Skip to content

Commit c976ee8

Browse files
ayushr2gvisor-bot
authored andcommitted
Add loader state checks for start commands.
In a normal startup sequence, StartRoot() is called on a "created" Loader. Then StartSubcontainer() is called on a "started" Loader for all sub-containers in the Pod. We do not want to allow either start methods to be called on a restoring container, otherwise, it can put the sandbox is a weird state. PiperOrigin-RevId: 831584019
1 parent 8213f69 commit c976ee8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

runsc/boot/controller.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ type containerManager struct {
270270
// StartRoot will start the root container process.
271271
func (cm *containerManager) StartRoot(cid *string, _ *struct{}) error {
272272
log.Debugf("containerManager.StartRoot, cid: %s", *cid)
273+
cm.l.mu.Lock()
274+
state := cm.l.state
275+
cm.l.mu.Unlock()
276+
if state != created {
277+
return fmt.Errorf("sandbox is not in created state, cannot start root container: state=%s", state)
278+
}
273279
// Tell the root container to start and wait for the result.
274280
return cm.onStart()
275281
}
@@ -366,6 +372,12 @@ func (cm *containerManager) StartSubcontainer(args *StartArgs, _ *struct{}) erro
366372
if args.CID == "" {
367373
return errors.New("start argument missing container ID")
368374
}
375+
cm.l.mu.Lock()
376+
state := cm.l.state
377+
cm.l.mu.Unlock()
378+
if state != started {
379+
return fmt.Errorf("sandbox is not in started state, cannot start subcontainer: state=%s", state)
380+
}
369381
expectedFDs := 1 // At least one FD for the root filesystem.
370382
expectedFDs += args.NumGoferFilestoreFDs
371383
if args.IsDevIoFilePresent {

0 commit comments

Comments
 (0)