Skip to content

Commit

Permalink
fs: keep struct mnt_id_req extensible
Browse files Browse the repository at this point in the history
Make it extensible so that we have the liberty to reuse it in future
mount-id based apis. Treat zero size as the first published struct.

Signed-off-by: Christian Brauner <brauner@kernel.org>
  • Loading branch information
Christian Brauner committed Dec 14, 2023
1 parent d8b0f54 commit 35e27a5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
34 changes: 30 additions & 4 deletions fs/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -4956,6 +4956,30 @@ static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq,
return 0;
}

static int copy_mnt_id_req(const struct mnt_id_req __user *req,
struct mnt_id_req *kreq)
{
int ret;
size_t usize;

BUILD_BUG_ON(sizeof(struct mnt_id_req) != MNT_ID_REQ_SIZE_VER0);

ret = get_user(usize, &req->size);
if (ret)
return -EFAULT;
if (unlikely(usize > PAGE_SIZE))
return -E2BIG;
if (unlikely(usize < MNT_ID_REQ_SIZE_VER0))
return -EINVAL;
memset(kreq, 0, sizeof(*kreq));
ret = copy_struct_from_user(kreq, sizeof(*kreq), req, usize);
if (ret)
return ret;
if (kreq->spare != 0)
return -EINVAL;
return 0;
}

SYSCALL_DEFINE4(statmount, const struct mnt_id_req __user *, req,
struct statmount __user *, buf, size_t, bufsize,
unsigned int, flags)
Expand All @@ -4970,8 +4994,9 @@ SYSCALL_DEFINE4(statmount, const struct mnt_id_req __user *, req,
if (flags)
return -EINVAL;

if (copy_from_user(&kreq, req, sizeof(kreq)))
return -EFAULT;
ret = copy_mnt_id_req(req, &kreq);
if (ret)
return ret;

retry:
ret = prepare_kstatmount(&ks, &kreq, buf, bufsize, seq_size);
Expand Down Expand Up @@ -5052,8 +5077,9 @@ SYSCALL_DEFINE4(listmount, const struct mnt_id_req __user *, req,
if (flags)
return -EINVAL;

if (copy_from_user(&kreq, req, sizeof(kreq)))
return -EFAULT;
ret = copy_mnt_id_req(req, &kreq);
if (ret)
return ret;
mnt_id = kreq.mnt_id;
last_mnt_id = kreq.param;

Expand Down
5 changes: 5 additions & 0 deletions include/uapi/linux/mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,15 @@ struct statmount {
* For listmount(2) @param represents the last listed mount id (or zero).
*/
struct mnt_id_req {
__u32 size;
__u32 spare;
__u64 mnt_id;
__u64 param;
};

/* List of all mnt_id_req versions. */
#define MNT_ID_REQ_SIZE_VER0 24 /* sizeof first published struct */

/*
* @mask bits for statmount(2)
*/
Expand Down

0 comments on commit 35e27a5

Please sign in to comment.