Check for nil task before attempting to return a mount namespace.

If we try to mount something with an empty set of tasks grabbing the
mount namespace panics.

PiperOrigin-RevId: 597045687
This commit is contained in:
Lucas Manning
2024-01-09 14:33:37 -08:00
committed by gVisor bot
parent 88efa359d5
commit 3749bdab65
+2 -2
View File
@@ -1631,13 +1631,13 @@ func (ctx *supervisorContext) Value(key any) any {
// The supervisor context is global root.
return auth.NewRootCredentials(ctx.Kernel.rootUserNamespace)
case vfs.CtxRoot:
if ctx.Kernel.globalInit == nil {
if ctx.Kernel.globalInit == nil || ctx.Kernel.globalInit.Leader() == nil {
return vfs.VirtualDentry{}
}
root := ctx.Kernel.GlobalInit().Leader().MountNamespace().Root(ctx)
return root
case vfs.CtxMountNamespace:
if ctx.Kernel.globalInit == nil {
if ctx.Kernel.globalInit == nil || ctx.Kernel.globalInit.Leader() == nil {
return nil
}
mntns := ctx.Kernel.GlobalInit().Leader().MountNamespace()