[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251002125422.203598-4-b.sachdev1904@gmail.com>
Date: Thu, 2 Oct 2025 18:18:39 +0530
From: Bhavik Sachdev <b.sachdev1904@...il.com>
To: Alexander Viro <viro@...iv.linux.org.uk>,
Christian Brauner <brauner@...nel.org>
Cc: linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org,
Aleksa Sarai <cyphar@...har.com>,
Bhavik Sachdev <b.sachdev1904@...il.com>,
Pavel Tikhomirov <ptikhomirov@...tuozzo.com>,
Jan Kara <jack@...e.cz>,
John Garry <john.g.garry@...cle.com>,
Arnaldo Carvalho de Melo <acme@...hat.com>,
"Darrick J . Wong" <djwong@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Ingo Molnar <mingo@...nel.org>,
Andrei Vagin <avagin@...il.com>,
Alexander Mikhalitsyn <alexander@...alicyn.com>
Subject: [PATCH 3/4] statmount: allow for "unmounted" mounts
With "unmounted" mounts getting added to a separate umount_mnt_ns, we
need special handling in statmount in order for it to work on
"unmounted" mounts.
unmount_mnt_ns has no root mount (it doesn't really make sense for it to
have one) and "unmounted" mounts have no mountpoint. We handle both
these things in statmount and output the mountpoint as "[detached]" in
case of an "unmounted" mount.
Signed-off-by: Bhavik Sachdev <b.sachdev1904@...il.com>
---
fs/namespace.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index 0b4be12c02de..29d0e692b365 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -5365,6 +5365,12 @@ static int statmount_mnt_root(struct kstatmount *s, struct seq_file *seq)
return 0;
}
+static int statmount_mnt_point_detached(struct kstatmount *s, struct seq_file *seq)
+{
+ seq_puts(seq, "[detached]");
+ return 0;
+}
+
static int statmount_mnt_point(struct kstatmount *s, struct seq_file *seq)
{
struct vfsmount *mnt = s->mnt;
@@ -5589,7 +5595,11 @@ static int statmount_string(struct kstatmount *s, u64 flag)
break;
case STATMOUNT_MNT_POINT:
offp = &sm->mnt_point;
- ret = statmount_mnt_point(s, seq);
+ if (!s->root.mnt && !s->root.dentry)
+ /* detached mount case */
+ ret = statmount_mnt_point_detached(s, seq);
+ else
+ ret = statmount_mnt_point(s, seq);
break;
case STATMOUNT_MNT_OPTS:
offp = &sm->mnt_opts;
@@ -5743,17 +5753,20 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,
if (!s->mnt)
return -ENOENT;
- err = grab_requested_root(ns, &root);
- if (err)
- return err;
+ if (!is_umount_ns(ns)) {
+ err = grab_requested_root(ns, &root);
+ if (err)
+ return err;
+ }
/*
* Don't trigger audit denials. We just want to determine what
* mounts to show users.
*/
m = real_mount(s->mnt);
- if (!is_path_reachable(m, m->mnt.mnt_root, &root) &&
- !ns_capable_noaudit(ns->user_ns, CAP_SYS_ADMIN))
+
+ if (!is_umount_ns(ns) && !is_path_reachable(m, m->mnt.mnt_root, &root) &&
+ !ns_capable_noaudit(ns->user_ns, CAP_SYS_ADMIN))
return -EPERM;
err = security_sb_statfs(s->mnt->mnt_root);
--
2.51.0
Powered by blists - more mailing lists