Skip to content

Commit d3505b9

Browse files
committed
update.go: fix nil pointer risk in Intel RDT initialization
Static analysis revealed a possible nil dereference when applying Intel RDT configurations. The `NewManager()` function can return nil if Intel RDT is not supported by the kernel (e.g. no resctrl filesystem mounted), but the caller in `update.go` did not check for this condition. This patch adds an explicit nil check after NewManager() is called, with a descriptive log message to help users understand the failure. In addition, `NewManager()` itself now logs the underlying reason (using the error from `Root()`), improving observability. This issue was originally identified via static analysis: > update.go:367:9: undefined: log > and: Return value of function 'NewManager' will be overwritten Signed-off-by: AntonMoryakov <[email protected]>
1 parent cdf9530 commit d3505b9

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

libcontainer/intelrdt/intelrdt.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
"github.com/opencontainers/cgroups/fscommon"
1717
"github.com/opencontainers/runc/libcontainer/configs"
18+
"github.com/sirupsen/logrus"
1819
)
1920

2021
/*
@@ -161,6 +162,7 @@ func NewManager(config *configs.Config, id string, path string) *Manager {
161162
}
162163
if _, err := Root(); err != nil {
163164
// Intel RDT is not available.
165+
logrus.Errorf("Intel RDT is not available: %v", err)
164166
return nil
165167
}
166168
return newManager(config, id, path)

update.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ other options are ignored.
363363
}
364364
config.IntelRdt = &configs.IntelRdt{}
365365
intelRdtManager := intelrdt.NewManager(&config, container.ID(), state.IntelRdtPath)
366+
if intelRdtManager == nil {
367+
logrus.Errorf("Intel RDT manager creation failed: likely due to missing resctrl filesystem")
368+
return nil
369+
}
366370
if err := intelRdtManager.Apply(state.InitProcessPid); err != nil {
367371
return err
368372
}

0 commit comments

Comments
 (0)