From: Jens Axboe <[email protected]>
To: Mark Harmstone <[email protected]>,
[email protected], [email protected]
Subject: Re: [PATCH 4/4] btrfs: don't read from userspace twice in btrfs_uring_encoded_read()
Date: Wed, 20 Nov 2024 09:53:01 -0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
On 11/20/24 9:02 AM, 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]>
> ---
> fs/btrfs/ioctl.c | 74 ++++++++++++++++++++++++++++++++----------------
> 1 file changed, 49 insertions(+), 25 deletions(-)
>
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 488dcd022dea..97f7812cbf7c 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -4873,7 +4873,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;
> @@ -4888,6 +4888,9 @@ 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);
> + struct io_uring_cmd_data *data = req->async_data;
> + bool need_copy = false;
>
> if (!capable(CAP_SYS_ADMIN)) {
> ret = -EPERM;
> @@ -4899,34 +4902,55 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue
> io_tree = &inode->io_tree;
> sqe_addr = u64_to_user_ptr(READ_ONCE(cmd->sqe->addr));
>
> + if (!data->op_data) {
> + data->op_data = kzalloc(sizeof(*args), GFP_NOFS);
> + if (!data->op_data) {
> + ret = -ENOMEM;
> + goto out_acct;
> + }
> +
> + need_copy = true;
> + }
I'd probably get rid of this need_copy variable and just do the copy
here? Might look cleaner with an btrfs_alloc_copy_foo() helper, as you
could just do:
ret = btrfs_alloc_copy_foo(...);
if (unlikely(ret))
return ret;
and hide all that ugly compat business outside the meat of this
function.
More of a style thing, the change itself looks fine.
--
Jens Axboe
prev parent reply other threads:[~2024-11-20 16:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-20 16:02 [PATCH 1/4] io_uring/cmd: rename struct uring_cache to io_uring_cmd_data Mark Harmstone
2024-11-20 16:02 ` [PATCH 2/4] io_uring: use sizeof for io_issue_defs[IORING_OP_URING_CMD].async_size Mark Harmstone
2024-11-20 16:49 ` Jens Axboe
2024-11-20 16:02 ` [PATCH 3/4] io_uring/cmd: add per-op data to struct io_uring_cmd_data Mark Harmstone
2024-11-20 16:02 ` [PATCH 4/4] btrfs: don't read from userspace twice in btrfs_uring_encoded_read() Mark Harmstone
2024-11-20 16:07 ` Mark Harmstone
2024-11-20 16:53 ` Jens Axboe [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