Move rootfs check to inside mountMu.

Reported-by: syzbot+811d3f0d101cfe1b1737@syzkaller.appspotmail.com
PiperOrigin-RevId: 578631715
This commit is contained in:
Lucas Manning
2023-11-01 13:57:23 -07:00
committed by gVisor bot
parent 9c0d595c8f
commit 429f7c4396
+7 -4
View File
@@ -1040,10 +1040,7 @@ retry:
if oldRoot.mount.root != oldRoot.dentry {
return newRoot, oldRoot, linuxerr.EINVAL
}
// The current root and the new root cannot be on the rootfs mount.
if oldRoot.mount.parent() == nil || newRoot.mount.parent() == nil {
return newRoot, oldRoot, linuxerr.EINVAL
}
// The current root and the new root must be in the context's mount namespace.
ns := MountNamespaceFromContext(ctx)
defer ns.DecRef(ctx)
@@ -1053,6 +1050,12 @@ retry:
return newRoot, oldRoot, linuxerr.EINVAL
}
// The current root and the new root cannot be on the rootfs mount.
if oldRoot.mount.parent() == nil || newRoot.mount.parent() == nil {
vfs.unlockMounts(ctx)
return newRoot, oldRoot, linuxerr.EINVAL
}
// Either the mount point at new_root, or the parent mount of that mount
// point, has propagation type MS_SHARED.
if newRootParent := newRoot.mount.parent(); newRoot.mount.isShared || newRootParent.isShared {