FAILED: patch "[PATCH] namespace: check the mounts before reading their parents in" failed to apply to 5.15-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 6b7c001eb5857fa09041f47673666060a2e5fc1c
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026101250-enforcer-oasis-a289@gregkh' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 6b7c001eb5857fa09041f47673666060a2e5fc1c Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Wed, 30 Sep 2026 15:32:02 +0200
Subject: [PATCH] namespace: check the mounts before reading their parents in
pivot_root()
path_pivot_root() reads the parents of new_root and of the caller's root and checks whether they are shared before it checks that either mount is in the caller's mount namespace. Only namespace_sem is held. That's fine for a mount that is in the caller's mount namespace.
But new_root can be a file descriptor to a mount that has been unmounted and that only the file descriptor keeps alive. If that mount stayed attached to its parent when it was unmounted nothing pins the parent for it. The final mntput() of the parent unhooks the children under mount_lock alone and frees the parent afterwards:
pivot_root() close(fd), last ref on the parent
------------ ---------------------------------
ex_parent = new_mnt->mnt_parent
mntput_no_expire_slowpath()
__umount_mnt(new_mnt)
cleanup_mnt()
call_rcu() IS_MNT_SHARED(ex_parent)
BUG: KASAN: slab-use-after-free in path_pivot_root+0xf1a/0x1840 Read of size 4 at addr ffff8881047382f8 by task pivot_widen/157 path_pivot_root+0xf1a/0x1840 __x64_sys_pivot_root+0x165/0x190
The same goes for the caller's root via chroot(). Both outcomes of the check end in EINVAL so nothing but the read itself goes wrong. It's the same thing commit bb4609405752 ("statmount: read the parent of an unmounted mount under mount_lock") fixed for statmount().
Check that both mounts are in the caller's namespace before their parents are read. Every path returns EINVAL either way.
fs/namespace.c +3 -2
@@ -4780,14 +4780,15 @@ int path_pivot_root(struct path *new, struct path *old) new_mnt =real_mount (new->mnt); root_mnt =real_mount (root.mnt); +/* only a mounted mount has a parent that namespace_sem pins */ +if (!check_mnt (root_mnt) || !check_mnt (new_mnt)) +return -EINVAL ; ex_parent = new_mnt->mnt_parent; root_parent = root_mnt->mnt_parent;if (IS_MNT_SHARED (old_mnt) ||IS_MNT_SHARED (ex_parent) ||IS_MNT_SHARED (root_parent))return -EINVAL ; -if (!check_mnt (root_mnt) || !check_mnt (new_mnt)) -return -EINVAL ;if (new_mnt->mnt.mnt_flags &MNT_LOCKED )return -EINVAL ;if (d_unlinked (new->dentry))
Sasha Levin
maintainerPATCH 1/1 namespace: check the mounts before reading their parents in pivot_root()
From: Christian Brauner <[email protected]>
[ Upstream commit 6b7c001eb5857fa09041f47673666060a2e5fc1c ]
path_pivot_root() reads the parents of new_root and of the caller's root and checks whether they are shared before it checks that either mount is in the caller's mount namespace. Only namespace_sem is held. That's fine for a mount that is in the caller's mount namespace.
But new_root can be a file descriptor to a mount that has been unmounted and that only the file descriptor keeps alive. If that mount stayed attached to its parent when it was unmounted nothing pins the parent for it. The final mntput() of the parent unhooks the children under mount_lock alone and frees the parent afterwards:
pivot_root() close(fd), last ref on the parent
------------ ---------------------------------
ex_parent = new_mnt->mnt_parent
mntput_no_expire_slowpath()
__umount_mnt(new_mnt)
cleanup_mnt()
call_rcu() IS_MNT_SHARED(ex_parent)
BUG: KASAN: slab-use-after-free in path_pivot_root+0xf1a/0x1840 Read of size 4 at addr ffff8881047382f8 by task pivot_widen/157 path_pivot_root+0xf1a/0x1840 __x64_sys_pivot_root+0x165/0x190
The same goes for the caller's root via chroot(). Both outcomes of the check end in EINVAL so nothing but the read itself goes wrong. It's the same thing commit bb4609405752 ("statmount: read the parent of an unmounted mount under mount_lock") fixed for statmount().
Check that both mounts are in the caller's namespace before their parents are read. Every path returns EINVAL either way.
--- fs/namespace.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/namespace.c +3 -2
@@ -3927,14 +3927,15 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root, new_mnt =real_mount (new.mnt); root_mnt =real_mount (root.mnt); old_mnt =real_mount (old.mnt); +/* only a mounted mount has a parent that namespace_sem pins */ +if (!check_mnt (root_mnt) || !check_mnt (new_mnt)) + goto out4; ex_parent = new_mnt->mnt_parent; root_parent = root_mnt->mnt_parent;if (IS_MNT_SHARED (old_mnt) ||IS_MNT_SHARED (ex_parent) ||IS_MNT_SHARED (root_parent)) goto out4; -if (!check_mnt (root_mnt) || !check_mnt (new_mnt)) - goto out4;if (new_mnt->mnt.mnt_flags &MNT_LOCKED ) goto out4; error = -ENOENT ;
Signature · 1 line
2.53.0