Skip to content

Commit 4bed843

Browse files
committed
fs: reject invalid last mount id early
Unique mount ids start past the last valid old mount id value to not confuse the two. If a last mount id has been specified, reject any invalid values early. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 80744d0 commit 4bed843

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

fs/namespace.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5375,6 +5375,7 @@ SYSCALL_DEFINE4(listmount, const struct mnt_id_req __user *, req,
53755375
const size_t maxcount = 1000000;
53765376
struct mnt_namespace *ns __free(mnt_ns_release) = NULL;
53775377
struct mnt_id_req kreq;
5378+
u64 last_mnt_id;
53785379
ssize_t ret;
53795380

53805381
if (flags & ~LISTMOUNT_REVERSE)
@@ -5395,6 +5396,11 @@ SYSCALL_DEFINE4(listmount, const struct mnt_id_req __user *, req,
53955396
if (ret)
53965397
return ret;
53975398

5399+
last_mnt_id = kreq.param;
5400+
/* The first valid unique mount id is MNT_UNIQUE_ID_OFFSET + 1. */
5401+
if (last_mnt_id != 0 && last_mnt_id <= MNT_UNIQUE_ID_OFFSET)
5402+
return -EINVAL;
5403+
53985404
kmnt_ids = kvmalloc_array(nr_mnt_ids, sizeof(*kmnt_ids),
53995405
GFP_KERNEL_ACCOUNT);
54005406
if (!kmnt_ids)
@@ -5409,7 +5415,7 @@ SYSCALL_DEFINE4(listmount, const struct mnt_id_req __user *, req,
54095415
return -ENOENT;
54105416

54115417
scoped_guard(rwsem_read, &namespace_sem)
5412-
ret = do_listmount(ns, kreq.mnt_id, kreq.param, kmnt_ids,
5418+
ret = do_listmount(ns, kreq.mnt_id, last_mnt_id, kmnt_ids,
54135419
nr_mnt_ids, (flags & LISTMOUNT_REVERSE));
54145420
if (ret <= 0)
54155421
return ret;

0 commit comments

Comments
 (0)