[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250905012535.2806919-1-csander@purestorage.com>
Date: Thu, 4 Sep 2025 19:25:34 -0600
From: Caleb Sander Mateos <csander@...estorage.com>
To: Jens Axboe <axboe@...nel.dk>
Cc: Caleb Sander Mateos <csander@...estorage.com>,
io-uring@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH] io_uring/rsrc: initialize io_rsrc_data nodes array
io_rsrc_data_alloc() allocates an array of io_rsrc_node pointers and
assigns it to io_rsrc_data's nodes field along with the size in the nr
field. However, it doesn't initialize the io_rsrc_node pointers in the
array. If an error in io_sqe_buffers_register(), io_alloc_file_tables(),
io_sqe_files_register(), or io_clone_buffers() causes them to exit
before all the io_rsrc_node pointers in the array have been assigned,
io_rsrc_data_free() will read the uninitialized elements, triggering
undefined behavior.
Additionally, if dst_off exceeds the current size of the destination
buffer table in io_clone_buffers(), the io_rsrc_node pointers in between
won't be initialized. Any access to those registered buffer indices will
result in undefined behavior.
Allocate the array with kvcalloc() instead of kvmalloc_array() to ensure
the io_rsrc_node pointers are initialized to NULL (indicating no
registered buffer/file node).
Signed-off-by: Caleb Sander Mateos <csander@...estorage.com>
Fixes: 7029acd8a950 ("io_uring/rsrc: get rid of per-ring io_rsrc_node list")
---
io_uring/rsrc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index f75f5e43fa4a..3f3f355f6613 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -209,12 +209,12 @@ __cold void io_rsrc_data_free(struct io_ring_ctx *ctx,
data->nr = 0;
}
__cold int io_rsrc_data_alloc(struct io_rsrc_data *data, unsigned nr)
{
- data->nodes = kvmalloc_array(nr, sizeof(struct io_rsrc_node *),
- GFP_KERNEL_ACCOUNT | __GFP_ZERO);
+ data->nodes = kvcalloc(nr, sizeof(struct io_rsrc_node *),
+ GFP_KERNEL_ACCOUNT | __GFP_ZERO);
if (data->nodes) {
data->nr = nr;
return 0;
}
return -ENOMEM;
--
2.45.2
Powered by blists - more mailing lists