runtime: Fix Incorrect conversion between integer types

Fix the high severity codeql issue by checking the
value is in bounds before converting

Signed-off-by: stevenhorsman <steven@uk.ibm.com>
This commit is contained in:
stevenhorsman 2025-05-01 12:48:43 +01:00
parent 4de79b9821
commit 5472662b33

View File

@ -11,6 +11,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math"
"os"
"path"
"path/filepath"
@ -1776,9 +1777,18 @@ func (k *kataAgent) handleDeviceBlockVolume(c *Container, m Mount, device api.De
if len(vol.Options) == 0 {
vol.Options = m.Options
}
if m.FSGroup != nil {
var safeFsgroup uint32
// Check conversions from int to uint32 is safe
if *m.FSGroup > 0 && *m.FSGroup <= math.MaxUint32 {
safeFsgroup = uint32(*m.FSGroup)
} else {
return nil, fmt.Errorf("m.FSGroup value was out of range: %d", m.FSGroup)
}
vol.FsGroup = &grpc.FSGroup{
GroupId: uint32(*m.FSGroup),
GroupId: safeFsgroup,
GroupChangePolicy: getFSGroupChangePolicy(m.FSGroupChangePolicy),
}
}