All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <krisman@suse.de>
To: Laxman Acharya <acharyalaxman8848@gmail.com>,
	Jens Axboe <axboe@kernel.dk>
Cc: Pavel Begunkov <asml.silence@gmail.com>,
	io-uring@vger.kernel.org, linux-kernel@vger.kernel.org,
	Laxman Acharya Padhya <acharyalaxman8848@gmail.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH] io_uring/query: cap user size passed to copy_struct_to_user
Date: Mon, 24 Aug 2026 09:24:01 -0400	[thread overview]
Message-ID: <87wltfslce.fsf@mailhost.krisman.be> (raw)
In-Reply-To: <20260821103317.91437-1-acharyalaxman8848@gmail.com>

Laxman Acharya <acharyalaxman8848@gmail.com> writes:

> From: Laxman Acharya Padhya <acharyalaxman8848@gmail.com>
>
> io_handle_query_entry() clamps hdr.size for the inbound copy_from_user()
> but keeps the original user value as usize. copy_struct_to_user() uses
> that usize and, when it is larger than the kernel result, clear_user()s
> the trailing bytes.
>
> As hdr.size is a __u32, a query can request nearly 4 GiB of zeroing,
> including on the error path where res_size stays 0. The interface is
> reachable without a ring via IORING_REGISTER_QUERY.
>
> Reject sizes larger than PAGE_SIZE, as recommended for copy_struct_*
> interfaces.
>
> Fixes: c265ae75f900 ("io_uring: introduce io_uring querying")
> Cc: stable@vger.kernel.org # 6.18+
> Signed-off-by: Laxman Acharya Padhya <acharyalaxman8848@gmail.com>

Looks good. feel free to add:

Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de>

> ---
>  io_uring/query.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/io_uring/query.c b/io_uring/query.c
> index 88a325736992..f2b5e19e5af6 100644
> --- a/io_uring/query.c
> +++ b/io_uring/query.c
> @@ -76,6 +76,9 @@ static int io_handle_query_entry(union io_query_data *data, void __user *uhdr,
>  
>  	if (copy_from_user(&hdr, uhdr, sizeof(hdr)))
>  		return -EFAULT;
> +	/* copy_struct_to_user() zeros up to usize bytes */
> +	if (hdr.size > PAGE_SIZE)
> +		return -E2BIG;
>  	usize = hdr.size;
>  	hdr.size = min(hdr.size, IO_MAX_QUERY_SIZE);
>  	udata = u64_to_user_ptr(hdr.query_data);
> -- 
> 2.51.2

-- 
Gabriel Krisman Bertazi

  reply	other threads:[~2026-08-24 13:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21 10:33 [PATCH] io_uring/query: cap user size passed to copy_struct_to_user Laxman Acharya
2026-08-24 13:24 ` Gabriel Krisman Bertazi [this message]
2026-08-25 18:11 ` Jens Axboe

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 \
    --in-reply-to=87wltfslce.fsf@mailhost.krisman.be \
    --to=krisman@suse.de \
    --cc=acharyalaxman8848@gmail.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.