Skip to content

Commit 48aa269

Browse files
Al Viroharshimogalapalli
authored andcommitted
fs/fhandle.c: fix a race in call of has_locked_children()
commit 1f282cd upstream. 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> [ Harshit: Resolved conflicts due to missing commit: db04662 ("fs: allow detached mounts in clone_private_mount()") in linux-6.12.y ] Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit 6482c3dccbfb8d20e2856ce67c75856859930b3f) Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
1 parent b720df1 commit 48aa269

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
@@ -2227,7 +2227,7 @@ void drop_collected_mounts(struct vfsmount *mnt)
22272227
namespace_unlock();
22282228
}
22292229

2230-
bool has_locked_children(struct mount *mnt, struct dentry *dentry)
2230+
static bool __has_locked_children(struct mount *mnt, struct dentry *dentry)
22312231
{
22322232
struct mount *child;
22332233

@@ -2241,6 +2241,16 @@ bool has_locked_children(struct mount *mnt, struct dentry *dentry)
22412241
return false;
22422242
}
22432243

2244+
bool has_locked_children(struct mount *mnt, struct dentry *dentry)
2245+
{
2246+
bool res;
2247+
2248+
read_seqlock_excl(&mount_lock);
2249+
res = __has_locked_children(mnt, dentry);
2250+
read_sequnlock_excl(&mount_lock);
2251+
return res;
2252+
}
2253+
22442254
/**
22452255
* clone_private_mount - create a private clone of a path
22462256
* @path: path to clone
@@ -2268,7 +2278,7 @@ struct vfsmount *clone_private_mount(const struct path *path)
22682278
return ERR_PTR(-EPERM);
22692279
}
22702280

2271-
if (has_locked_children(old_mnt, path->dentry))
2281+
if (__has_locked_children(old_mnt, path->dentry))
22722282
goto invalid;
22732283

22742284
new_mnt = clone_mnt(old_mnt, path->dentry, CL_PRIVATE);
@@ -2762,7 +2772,7 @@ static struct mount *__do_loopback(struct path *old_path, int recurse)
27622772
if (!check_mnt(old) && old_path->dentry->d_op != &ns_dentry_operations)
27632773
return mnt;
27642774

2765-
if (!recurse && has_locked_children(old, old_path->dentry))
2775+
if (!recurse && __has_locked_children(old, old_path->dentry))
27662776
return mnt;
27672777

27682778
if (recurse)
@@ -3152,7 +3162,7 @@ static int do_set_group(struct path *from_path, struct path *to_path)
31523162
goto out;
31533163

31543164
/* From mount should not have locked children in place of To's root */
3155-
if (has_locked_children(from, to->mnt.mnt_root))
3165+
if (__has_locked_children(from, to->mnt.mnt_root))
31563166
goto out;
31573167

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

0 commit comments

Comments
 (0)