Skip to content

Commit 1f282cd

Browse files
author
Al Viro
committed
fs/fhandle.c: fix a race in call of has_locked_children()
may_decode_fh() is calling has_locked_children() while holding no locks. That's an oopsable race... The rest of the callers are safe since they are holding namespace_sem and are guaranteed a positive refcount on the mount in question. Rename the current has_locked_children() to __has_locked_children(), make it static and switch the fs/namespace.c users to it. Make has_locked_children() a wrapper for __has_locked_children(), calling the latter under read_seqlock_excl(&mount_lock). Reviewed-by: Christian Brauner <brauner@kernel.org> Reviewed-by: Jeff Layton <jlayton@kernel.org> Fixes: 620c266 ("fhandle: relax open_by_handle_at() permission checks") Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent a82ba83 commit 1f282cd

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

fs/namespace.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,7 +2425,7 @@ void drop_collected_mounts(struct vfsmount *mnt)
24252425
namespace_unlock();
24262426
}
24272427

2428-
bool has_locked_children(struct mount *mnt, struct dentry *dentry)
2428+
static bool __has_locked_children(struct mount *mnt, struct dentry *dentry)
24292429
{
24302430
struct mount *child;
24312431

@@ -2439,6 +2439,16 @@ bool has_locked_children(struct mount *mnt, struct dentry *dentry)
24392439
return false;
24402440
}
24412441

2442+
bool has_locked_children(struct mount *mnt, struct dentry *dentry)
2443+
{
2444+
bool res;
2445+
2446+
read_seqlock_excl(&mount_lock);
2447+
res = __has_locked_children(mnt, dentry);
2448+
read_sequnlock_excl(&mount_lock);
2449+
return res;
2450+
}
2451+
24422452
/*
24432453
* Check that there aren't references to earlier/same mount namespaces in the
24442454
* specified subtree. Such references can act as pins for mount namespaces
@@ -2499,7 +2509,7 @@ struct vfsmount *clone_private_mount(const struct path *path)
24992509
return ERR_PTR(-EINVAL);
25002510
}
25012511

2502-
if (has_locked_children(old_mnt, path->dentry))
2512+
if (__has_locked_children(old_mnt, path->dentry))
25032513
return ERR_PTR(-EINVAL);
25042514

25052515
new_mnt = clone_mnt(old_mnt, path->dentry, CL_PRIVATE);
@@ -3036,7 +3046,7 @@ static struct mount *__do_loopback(struct path *old_path, int recurse)
30363046
if (!may_copy_tree(old_path))
30373047
return mnt;
30383048

3039-
if (!recurse && has_locked_children(old, old_path->dentry))
3049+
if (!recurse && __has_locked_children(old, old_path->dentry))
30403050
return mnt;
30413051

30423052
if (recurse)
@@ -3429,7 +3439,7 @@ static int do_set_group(struct path *from_path, struct path *to_path)
34293439
goto out;
34303440

34313441
/* From mount should not have locked children in place of To's root */
3432-
if (has_locked_children(from, to->mnt.mnt_root))
3442+
if (__has_locked_children(from, to->mnt.mnt_root))
34333443
goto out;
34343444

34353445
/* Setting sharing groups is only allowed on private mounts */

0 commit comments

Comments
 (0)