Skip to content

Commit f8b6cd6

Browse files
committed
fs: allow creating detached mounts from fsmount() file descriptors
The previous patch series only enabled the creation of detached mounts from detached mounts that were created via open_tree(). In such cases we know that the origin sequence number for the newly created anonymous mount namespace will be set to the sequence number of the mount namespace the source mount belonged to. But fsmount() creates an anonymous mount namespace that does not have an origin mount namespace as the anonymous mount namespace was derived from a filesystem context created via fsopen(). Account for this case and allow the creation of detached mounts from mounts created via fsmount(). Consequently, any such detached mount created from an fsmount() mount will also have a zero origin sequence number. This allows to mount subdirectories without ever having to expose the filesystem to a a non-anonymous mount namespace: fd_context = sys_fsopen("tmpfs", 0); sys_fsconfig(fd_context, FSCONFIG_CMD_CREATE, NULL, NULL, 0); fd_tmpfs = sys_fsmount(fd_context, 0, 0); mkdirat(fd_tmpfs, "subdir", 0755); fd_tree = sys_open_tree(fd_tmpfs, "subdir", OPEN_TREE_CLONE); sys_move_mount(fd_tree, "", -EBADF, "/mnt", MOVE_MOUNT_F_EMPTY_PATH); Signed-off-by: Christian Brauner <[email protected]>
1 parent 53dde6b commit f8b6cd6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

fs/namespace.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,8 +1000,13 @@ static inline int check_mnt(struct mount *mnt)
10001000

10011001
static inline bool check_anonymous_mnt(struct mount *mnt)
10021002
{
1003-
return is_anon_ns(mnt->mnt_ns) &&
1004-
mnt->mnt_ns->seq_origin == current->nsproxy->mnt_ns->seq;
1003+
u64 seq;
1004+
1005+
if (!is_anon_ns(mnt->mnt_ns))
1006+
return false;
1007+
1008+
seq = mnt->mnt_ns->seq_origin;
1009+
return !seq || (seq == current->nsproxy->mnt_ns->seq);
10051010
}
10061011

10071012
/*

0 commit comments

Comments
 (0)