Skip to content

Commit 80744d0

Browse files
committed
fs: refuse mnt id requests with invalid ids early
Unique mount ids start past the last valid old mount id value to not confuse the two so reject invalid values early in copy_mnt_id_req(). Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 5e8a9ce commit 80744d0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

fs/namespace.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ static DEFINE_IDA(mnt_id_ida);
7070
static DEFINE_IDA(mnt_group_ida);
7171

7272
/* Don't allow confusion with old 32bit mount ID */
73-
static atomic64_t mnt_id_ctr = ATOMIC64_INIT(1ULL << 32);
73+
#define MNT_UNIQUE_ID_OFFSET (1ULL << 32)
74+
static atomic64_t mnt_id_ctr = ATOMIC64_INIT(MNT_UNIQUE_ID_OFFSET);
7475

7576
static struct hlist_head *mount_hashtable __ro_after_init;
7677
static struct hlist_head *mountpoint_hashtable __ro_after_init;
@@ -5241,6 +5242,9 @@ static int copy_mnt_id_req(const struct mnt_id_req __user *req,
52415242
return ret;
52425243
if (kreq->spare != 0)
52435244
return -EINVAL;
5245+
/* The first valid unique mount id is MNT_UNIQUE_ID_OFFSET + 1. */
5246+
if (kreq->mnt_id <= MNT_UNIQUE_ID_OFFSET)
5247+
return -EINVAL;
52445248
return 0;
52455249
}
52465250

0 commit comments

Comments
 (0)