Skip to content

Commit 6bc9199

Browse files
krismanaxboe
authored andcommitted
io_uring: Allocate only necessary memory in io_probe
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> Link: https://lore.kernel.org/r/20240619020620.5301-3-krisman@suse.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 3e05b22 commit 6bc9199

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

io_uring/register.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ static __cold int io_probe(struct io_ring_ctx *ctx, void __user *arg,
3939
size_t size;
4040
int i, ret;
4141

42+
if (nr_args > IORING_OP_LAST)
43+
nr_args = IORING_OP_LAST;
44+
4245
size = struct_size(p, ops, nr_args);
43-
if (size == SIZE_MAX)
44-
return -EOVERFLOW;
4546
p = kzalloc(size, GFP_KERNEL);
4647
if (!p)
4748
return -ENOMEM;
@@ -54,8 +55,6 @@ static __cold int io_probe(struct io_ring_ctx *ctx, void __user *arg,
5455
goto out;
5556

5657
p->last_op = IORING_OP_LAST - 1;
57-
if (nr_args > IORING_OP_LAST)
58-
nr_args = IORING_OP_LAST;
5958

6059
for (i = 0; i < nr_args; i++) {
6160
p->ops[i].op = i;

0 commit comments

Comments
 (0)