Skip to content

Commit fa1974f

Browse files
braunergregkh
authored andcommitted
statmount: don't call path_put() under namespace semaphore
[ Upstream commit e8c84e2 ] 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: [email protected] # v6.8+ Signed-off-by: Christian Brauner <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 32c258a commit fa1974f

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

fs/namespace.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5200,7 +5200,6 @@ static int grab_requested_root(struct mnt_namespace *ns, struct path *root)
52005200
static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,
52015201
struct mnt_namespace *ns)
52025202
{
5203-
struct path root __free(path_put) = {};
52045203
struct mount *m;
52055204
int err;
52065205

@@ -5212,7 +5211,7 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,
52125211
if (!s->mnt)
52135212
return -ENOENT;
52145213

5215-
err = grab_requested_root(ns, &root);
5214+
err = grab_requested_root(ns, &s->root);
52165215
if (err)
52175216
return err;
52185217

@@ -5221,15 +5220,13 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,
52215220
* mounts to show users.
52225221
*/
52235222
m = real_mount(s->mnt);
5224-
if (!is_path_reachable(m, m->mnt.mnt_root, &root) &&
5223+
if (!is_path_reachable(m, m->mnt.mnt_root, &s->root) &&
52255224
!ns_capable_noaudit(ns->user_ns, CAP_SYS_ADMIN))
52265225
return -EPERM;
52275226

52285227
err = security_sb_statfs(s->mnt->mnt_root);
52295228
if (err)
52305229
return err;
5231-
5232-
s->root = root;
52335230
if (s->mask & STATMOUNT_SB_BASIC)
52345231
statmount_sb_basic(s);
52355232

@@ -5406,6 +5403,7 @@ SYSCALL_DEFINE4(statmount, const struct mnt_id_req __user *, req,
54065403
if (!ret)
54075404
ret = copy_statmount_to_user(ks);
54085405
kvfree(ks->seq.buf);
5406+
path_put(&ks->root);
54095407
if (retry_statmount(ret, &seq_size))
54105408
goto retry;
54115409
return ret;

0 commit comments

Comments
 (0)