@@ -10,6 +10,7 @@ import (
1010 "strings"
1111 "sync"
1212
13+ securejoin "github.com/cyphar/filepath-securejoin"
1314 "github.com/moby/sys/mountinfo"
1415 "golang.org/x/sys/unix"
1516
@@ -159,10 +160,25 @@ func NewManager(config *configs.Config, id string, path string) *Manager {
159160 if config .IntelRdt == nil {
160161 return nil
161162 }
162- if _ , err := Root (); err != nil {
163- // Intel RDT is not available.
163+
164+ rootPath , err := Root ()
165+ if err != nil {
164166 return nil
165167 }
168+ // NOTE: Should we check if the path provided as arg matches the path
169+ // constructed below? If not, we're screwed as we've effectively lost resctrl
170+ // control of the container (e.g. because the resctrl fs was unmounted or
171+ // remounted elsewhere). All operations are deemed to fail.
172+ if path == "" {
173+ clos := id
174+ if config .IntelRdt .ClosID != "" {
175+ clos = config .IntelRdt .ClosID
176+ }
177+ if path , err = securejoin .SecureJoin (rootPath , clos ); err != nil {
178+ return nil
179+ }
180+ }
181+
166182 return newManager (config , id , path )
167183}
168184
@@ -434,32 +450,14 @@ func IsMBAEnabled() bool {
434450 return mbaEnabled
435451}
436452
437- // Get the path of the clos group in "resource control" filesystem that the container belongs to
438- func (m * Manager ) getIntelRdtPath () (string , error ) {
439- rootPath , err := Root ()
440- if err != nil {
441- return "" , err
442- }
443-
444- clos := m .id
445- if m .config .IntelRdt != nil && m .config .IntelRdt .ClosID != "" {
446- clos = m .config .IntelRdt .ClosID
447- }
448-
449- return filepath .Join (rootPath , clos ), nil
450- }
451-
452453// Apply applies Intel RDT configuration to the process with the specified pid.
453454func (m * Manager ) Apply (pid int ) (err error ) {
454455 // If intelRdt is not specified in config, we do nothing
455456 if m .config .IntelRdt == nil {
456457 return nil
457458 }
458459
459- path , err := m .getIntelRdtPath ()
460- if err != nil {
461- return err
462- }
460+ path := m .GetPath ()
463461
464462 m .mu .Lock ()
465463 defer m .mu .Unlock ()
@@ -503,9 +501,6 @@ func (m *Manager) Destroy() error {
503501// GetPath returns Intel RDT path to save in a state file and to be able to
504502// restore the object later.
505503func (m * Manager ) GetPath () string {
506- if m .path == "" {
507- m .path , _ = m .getIntelRdtPath ()
508- }
509504 return m .path
510505}
511506
0 commit comments