@@ -5004,18 +5004,13 @@ static struct mount *listmnt_first(struct mount *root)
return list_first_entry_or_null(&root->mnt_mounts, struct mount, mnt_child);
}
-static struct mount *listmnt_next(struct mount *curr, struct mount *root, bool recurse)
+static struct mount *listmnt_next(struct mount *curr, struct mount *root)
{
- if (recurse)
- return next_mnt(curr, root);
- if (!list_is_head(curr->mnt_child.next, &root->mnt_mounts))
- return list_next_entry(curr, mnt_child);
- return NULL;
+ return next_mnt(curr, root);
}
static ssize_t do_listmount(struct vfsmount *mnt, u64 __user *buf,
- size_t bufsize, const struct path *root,
- unsigned int flags)
+ size_t bufsize, const struct path *root)
{
struct mount *r, *m = real_mount(mnt);
struct path rootmnt = {
@@ -5023,26 +5018,17 @@ static ssize_t do_listmount(struct vfsmount *mnt, u64 __user *buf,
.dentry = root->mnt->mnt_root
};
ssize_t ctr;
- bool reachable_only = true;
- bool recurse = flags & LISTMOUNT_RECURSIVE;
int err;
- if (flags & LISTMOUNT_UNREACHABLE) {
- if (!capable(CAP_SYS_ADMIN))
- return -EPERM;
- reachable_only = false;
- }
-
- if (reachable_only && !is_path_reachable(m, mnt->mnt_root, &rootmnt))
+ if (!is_path_reachable(m, mnt->mnt_root, &rootmnt))
return capable(CAP_SYS_ADMIN) ? 0 : -EPERM;
err = security_sb_statfs(mnt->mnt_root);
if (err)
return err;
- for (ctr = 0, r = listmnt_first(m); r; r = listmnt_next(r, m, recurse)) {
- if (reachable_only &&
- !is_path_reachable(r, r->mnt.mnt_root, root))
+ for (ctr = 0, r = listmnt_first(m); r; r = listmnt_next(r, m)) {
+ if (!is_path_reachable(r, r->mnt.mnt_root, root))
continue;
if (ctr >= bufsize)
@@ -5065,7 +5051,7 @@ SYSCALL_DEFINE4(listmount, const struct mnt_id_req __user *, req,
u64 mnt_id;
ssize_t ret;
- if (flags & ~(LISTMOUNT_UNREACHABLE | LISTMOUNT_RECURSIVE))
+ if (flags)
return -EINVAL;
if (copy_from_user(&kreq, req, sizeof(kreq)))
@@ -5075,20 +5061,17 @@ SYSCALL_DEFINE4(listmount, const struct mnt_id_req __user *, req,
mnt_id = kreq.mnt_id;
down_read(&namespace_sem);
- if (mnt_id == LSMT_ROOT)
- mnt = ¤t->nsproxy->mnt_ns->root->mnt;
- else
- mnt = lookup_mnt_in_ns(mnt_id, current->nsproxy->mnt_ns);
- if (!mnt) {
- up_read(&namespace_sem);
- return -ENOENT;
- }
-
get_fs_root(current->fs, &root);
- /* Skip unreachable for LSMT_ROOT */
- if (mnt_id == LSMT_ROOT && !(flags & LISTMOUNT_UNREACHABLE))
+ if (mnt_id == LSMT_ROOT) {
mnt = root.mnt;
- ret = do_listmount(mnt, buf, bufsize, &root, flags);
+ } else {
+ ret = -ENOENT;
+ mnt = lookup_mnt_in_ns(mnt_id, current->nsproxy->mnt_ns);
+ if (!mnt)
+ goto err;
+ }
+ ret = do_listmount(mnt, buf, bufsize, &root);
+err:
path_put(&root);
up_read(&namespace_sem);
return ret;
@@ -191,10 +191,6 @@ struct mnt_id_req {
#define STATMOUNT_MNT_POINT 0x00000010U /* Want/got mnt_point */
#define STATMOUNT_FS_TYPE 0x00000020U /* Want/got fs_type */
-/* listmount(2) flags */
-#define LISTMOUNT_UNREACHABLE 0x01U /* List unreachable mounts too */
-#define LISTMOUNT_RECURSIVE 0x02U /* List a mount tree */
-
/*
* Special @mnt_id values that can be passed to listmount
*/
LISTMOUNT_UNREACHABLE will be achieved differently in a following patch. LISTMOUNT_RECURSIVE becomes the default. If non-recursive listing turns out to be needed, it can be added later. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> --- fs/namespace.c | 49 +++++++++++++------------------------- include/uapi/linux/mount.h | 4 ---- 2 files changed, 16 insertions(+), 37 deletions(-)