Skip to content

Commit 123d8b7

Browse files
committed
statmount: allow for root to be NULL
1 parent 0df4ee1 commit 123d8b7

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

fs/namespace.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5365,6 +5365,12 @@ static int statmount_mnt_root(struct kstatmount *s, struct seq_file *seq)
53655365
return 0;
53665366
}
53675367

5368+
static int statmount_mnt_point_detached(struct kstatmount *s, struct seq_file *seq)
5369+
{
5370+
seq_puts(seq, "[detached]");
5371+
return 0;
5372+
}
5373+
53685374
static int statmount_mnt_point(struct kstatmount *s, struct seq_file *seq)
53695375
{
53705376
struct vfsmount *mnt = s->mnt;
@@ -5585,7 +5591,11 @@ static int statmount_string(struct kstatmount *s, u64 flag)
55855591
break;
55865592
case STATMOUNT_MNT_ROOT:
55875593
offp = &sm->mnt_root;
5588-
ret = statmount_mnt_root(s, seq);
5594+
if (!s->root.mnt && !s->root.dentry)
5595+
/* detached mount case */
5596+
ret = statmount_mnt_point_detached(s, seq);
5597+
else
5598+
ret = statmount_mnt_point(s, seq);
55895599
break;
55905600
case STATMOUNT_MNT_POINT:
55915601
offp = &sm->mnt_point;
@@ -5736,23 +5746,25 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,
57365746
int err;
57375747

57385748
/* Has the namespace already been emptied? */
5739-
if (mnt_ns_id && mnt_ns_empty(ns))
5749+
if (!is_umount_ns(ns) && mnt_ns_id && mnt_ns_empty(ns))
57405750
return -ENOENT;
57415751

57425752
s->mnt = lookup_mnt_in_ns(mnt_id, ns);
57435753
if (!s->mnt)
57445754
return -ENOENT;
57455755

5746-
err = grab_requested_root(ns, &root);
5747-
if (err)
5748-
return err;
5756+
if (!is_umount_ns(ns)) {
5757+
err = grab_requested_root(ns, &root);
5758+
if (err)
5759+
return err;
5760+
}
57495761

57505762
/*
57515763
* Don't trigger audit denials. We just want to determine what
57525764
* mounts to show users.
57535765
*/
57545766
m = real_mount(s->mnt);
5755-
if (!is_path_reachable(m, m->mnt.mnt_root, &root) &&
5767+
if (!is_umount_ns(ns) && !is_path_reachable(m, m->mnt.mnt_root, &root) &&
57565768
!ns_capable_noaudit(ns->user_ns, CAP_SYS_ADMIN))
57575769
return -EPERM;
57585770

0 commit comments

Comments
 (0)