From: Gabriel Krisman Bertazi <krisman@suse.de>
To: axboe@kernel.dk
Cc: io-uring@vger.kernel.org, Gabriel Krisman Bertazi <krisman@suse.de>
Subject: [PATCH 2/3] io_uring: Allocate only necessary memory in io_probe
Date: Tue, 18 Jun 2024 22:06:19 -0400 [thread overview]
Message-ID: <20240619020620.5301-3-krisman@suse.de> (raw)
In-Reply-To: <20240619020620.5301-1-krisman@suse.de>
We write at most IORING_OP_LAST entries in the probe buffer, so we don't
need to allocate temporary space for more than that. As a side effect,
we no longer can overflow "size".
Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de>
---
io_uring/register.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/io_uring/register.c b/io_uring/register.c
index 75f8e85cf0b0..8409fc80c1cb 100644
--- a/io_uring/register.c
+++ b/io_uring/register.c
@@ -39,9 +39,10 @@ static __cold int io_probe(struct io_ring_ctx *ctx, void __user *arg,
size_t size;
int i, ret;
+ if (nr_args > IORING_OP_LAST)
+ nr_args = IORING_OP_LAST;
+
size = struct_size(p, ops, nr_args);
- if (size == SIZE_MAX)
- return -EOVERFLOW;
p = kzalloc(size, GFP_KERNEL);
if (!p)
return -ENOMEM;
@@ -54,8 +55,6 @@ static __cold int io_probe(struct io_ring_ctx *ctx, void __user *arg,
goto out;
p->last_op = IORING_OP_LAST - 1;
- if (nr_args > IORING_OP_LAST)
- nr_args = IORING_OP_LAST;
for (i = 0; i < nr_args; i++) {
p->ops[i].op = i;
--
2.45.2
next prev parent reply other threads:[~2024-06-19 2:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-19 2:06 [PATCH 0/3] io_uring op probing fixes Gabriel Krisman Bertazi
2024-06-19 2:06 ` [PATCH 1/3] io_uring: Fix probe of disabled operations Gabriel Krisman Bertazi
2024-06-19 2:06 ` Gabriel Krisman Bertazi [this message]
2024-06-19 2:06 ` [PATCH 3/3] io_uring: Don't read userspace data in io_probe Gabriel Krisman Bertazi
2024-06-19 13:44 ` Jens Axboe
2024-06-19 14:55 ` Gabriel Krisman Bertazi
2024-06-19 14:57 ` Jens Axboe
2024-06-19 13:42 ` [PATCH 0/3] io_uring op probing fixes Jens Axboe
2024-06-19 14:58 ` (subset) " 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=20240619020620.5301-3-krisman@suse.de \
--to=krisman@suse.de \
--cc=axboe@kernel.dk \
--cc=io-uring@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.