Skip to content

Commit e8c84e2

Browse files
committed
statmount: don't call path_put() under namespace semaphore
Massage statmount() and make sure we don't call path_put() under the namespace semaphore. If we put the last reference we're fscked. Fixes: 46eae99 ("add statmount(2) syscall") Cc: stable@vger.kernel.org # v6.8+ Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent b9cb7e5 commit e8c84e2

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

fs/namespace.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5708,7 +5708,6 @@ static int grab_requested_root(struct mnt_namespace *ns, struct path *root)
57085708
static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,
57095709
struct mnt_namespace *ns)
57105710
{
5711-
struct path root __free(path_put) = {};
57125711
struct mount *m;
57135712
int err;
57145713

@@ -5720,7 +5719,7 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,
57205719
if (!s->mnt)
57215720
return -ENOENT;
57225721

5723-
err = grab_requested_root(ns, &root);
5722+
err = grab_requested_root(ns, &s->root);
57245723
if (err)
57255724
return err;
57265725

@@ -5729,16 +5728,14 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,
57295728
* mounts to show users.
57305729
*/
57315730
m = real_mount(s->mnt);
5732-
if (!is_path_reachable(m, m->mnt.mnt_root, &root) &&
5731+
if (!is_path_reachable(m, m->mnt.mnt_root, &s->root) &&
57335732
!ns_capable_noaudit(ns->user_ns, CAP_SYS_ADMIN))
57345733
return -EPERM;
57355734

57365735
err = security_sb_statfs(s->mnt->mnt_root);
57375736
if (err)
57385737
return err;
57395738

5740-
s->root = root;
5741-
57425739
/*
57435740
* Note that mount properties in mnt->mnt_flags, mnt->mnt_idmap
57445741
* can change concurrently as we only hold the read-side of the
@@ -5960,6 +5957,7 @@ SYSCALL_DEFINE4(statmount, const struct mnt_id_req __user *, req,
59605957
if (!ret)
59615958
ret = copy_statmount_to_user(ks);
59625959
kvfree(ks->seq.buf);
5960+
path_put(&ks->root);
59635961
if (retry_statmount(ret, &seq_size))
59645962
goto retry;
59655963
return ret;

0 commit comments

Comments
 (0)