From: Pavel Begunkov <[email protected]>
To: Mark Harmstone <[email protected]>,
[email protected], [email protected]
Subject: Re: [PATCH v2 3/3] btrfs: don't read from userspace twice in btrfs_uring_encoded_read()
Date: Fri, 13 Dec 2024 21:18:31 +0000 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
On 12/13/24 18:44, Mark Harmstone wrote:
> If we return -EAGAIN the first time because we need to block,
> btrfs_uring_encoded_read() will get called twice. Take a copy of args
> the first time, to prevent userspace from messing around with it.
>
> Signed-off-by: Mark Harmstone <[email protected]>
> ---
> Refactored slightly from the first version, in order to eliminate the
> need_copy variable.
>
> fs/btrfs/ioctl.c | 75 +++++++++++++++++++++++++++++++-----------------
> 1 file changed, 49 insertions(+), 26 deletions(-)
>
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index dc5faa89cdba..684c1541105e 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -4882,7 +4882,7 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue
> {
> size_t copy_end_kernel = offsetofend(struct btrfs_ioctl_encoded_io_args, flags);
> size_t copy_end;
> - struct btrfs_ioctl_encoded_io_args args = { 0 };
> + struct btrfs_ioctl_encoded_io_args *args;
> int ret;
> u64 disk_bytenr, disk_io_size;
> struct file *file;
> @@ -4897,6 +4897,8 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue
> struct extent_state *cached_state = NULL;
> u64 start, lockend;
> void __user *sqe_addr;
> + struct io_kiocb *req = cmd_to_io_kiocb(cmd);
Oh no, please don't. In general cmd implementations should never
use helpers that are not explicitly given to them in
include/linux/io_uring/*
> + struct io_uring_cmd_data *data = req->async_data;
Just add a helper to io_uring/cmd.h,
>
> if (!capable(CAP_SYS_ADMIN)) {
> ret = -EPERM;
...
--
Pavel Begunkov
prev parent reply other threads:[~2024-12-13 21:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-13 18:44 [PATCH v2 1/3] io_uring/cmd: rename struct uring_cache to io_uring_cmd_data Mark Harmstone
2024-12-13 18:44 ` [PATCH v2 2/3] io_uring/cmd: add per-op data to struct io_uring_cmd_data Mark Harmstone
2024-12-13 18:44 ` [PATCH v2 3/3] btrfs: don't read from userspace twice in btrfs_uring_encoded_read() Mark Harmstone
2024-12-13 19:50 ` Jens Axboe
2024-12-13 21:18 ` Pavel Begunkov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox