Skip to content

Commit 4954346

Browse files
kndkAl Viro
authored andcommitted
fs: allow clone_private_mount() for a path on real rootfs
Mounting overlayfs with a directory on real rootfs (initramfs) as upperdir has failed with following message since commit db04662 ("fs: allow detached mounts in clone_private_mount()"). [ 4.080134] overlayfs: failed to clone upperpath Overlayfs mount uses clone_private_mount() to create internal mount for the underlying layers. The commit made clone_private_mount() reject real rootfs because it does not have a parent mount and is in the initial mount namespace, that is not an anonymous mount namespace. This issue can be fixed by modifying the permission check of clone_private_mount() following [1]. Reviewed-by: Christian Brauner <brauner@kernel.org> Fixes: db04662 ("fs: allow detached mounts in clone_private_mount()") Link: https://lore.kernel.org/all/20250514190252.GQ2023217@ZenIV/ [1] Link: https://lore.kernel.org/all/20250506194849.GT2023217@ZenIV/ Suggested-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Kazuma Kondo <kazuma-kondo@nec.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent d8cc036 commit 4954346

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

fs/namespace.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,18 +2493,19 @@ struct vfsmount *clone_private_mount(const struct path *path)
24932493
if (IS_MNT_UNBINDABLE(old_mnt))
24942494
return ERR_PTR(-EINVAL);
24952495

2496-
if (mnt_has_parent(old_mnt)) {
2497-
if (!check_mnt(old_mnt))
2498-
return ERR_PTR(-EINVAL);
2499-
} else {
2500-
if (!is_mounted(&old_mnt->mnt))
2501-
return ERR_PTR(-EINVAL);
2502-
2503-
/* Make sure this isn't something purely kernel internal. */
2504-
if (!is_anon_ns(old_mnt->mnt_ns))
2496+
/*
2497+
* Make sure the source mount is acceptable.
2498+
* Anything mounted in our mount namespace is allowed.
2499+
* Otherwise, it must be the root of an anonymous mount
2500+
* namespace, and we need to make sure no namespace
2501+
* loops get created.
2502+
*/
2503+
if (!check_mnt(old_mnt)) {
2504+
if (!is_mounted(&old_mnt->mnt) ||
2505+
!is_anon_ns(old_mnt->mnt_ns) ||
2506+
mnt_has_parent(old_mnt))
25052507
return ERR_PTR(-EINVAL);
25062508

2507-
/* Make sure we don't create mount namespace loops. */
25082509
if (!check_for_nsfs_mounts(old_mnt))
25092510
return ERR_PTR(-EINVAL);
25102511
}

0 commit comments

Comments
 (0)