public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] io_uring/rsrc: initialize io_rsrc_data nodes array
@ 2025-09-05  1:25 Caleb Sander Mateos
  2025-09-05 11:14 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Caleb Sander Mateos @ 2025-09-05  1:25 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Caleb Sander Mateos, io-uring, linux-kernel

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@purestorage.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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] io_uring/rsrc: initialize io_rsrc_data nodes array
  2025-09-05  1:25 [PATCH] io_uring/rsrc: initialize io_rsrc_data nodes array Caleb Sander Mateos
@ 2025-09-05 11:14 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2025-09-05 11:14 UTC (permalink / raw)
  To: Caleb Sander Mateos; +Cc: io-uring, linux-kernel


On Thu, 04 Sep 2025 19:25:34 -0600, Caleb Sander Mateos wrote:
> 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).
> 
> [...]

Applied, thanks!

[1/1] io_uring/rsrc: initialize io_rsrc_data nodes array
      commit: 0f51a5c0a89921deca72e42583683e44ff742d06

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-09-05 11:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-05  1:25 [PATCH] io_uring/rsrc: initialize io_rsrc_data nodes array Caleb Sander Mateos
2025-09-05 11:14 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox