public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Caleb Sander Mateos <csander@purestorage.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Caleb Sander Mateos <csander@purestorage.com>,
	io-uring@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] io_uring/rsrc: initialize io_rsrc_data nodes array
Date: Thu,  4 Sep 2025 19:25:34 -0600	[thread overview]
Message-ID: <20250905012535.2806919-1-csander@purestorage.com> (raw)

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


             reply	other threads:[~2025-09-05  1:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-05  1:25 Caleb Sander Mateos [this message]
2025-09-05 11:14 ` [PATCH] io_uring/rsrc: initialize io_rsrc_data nodes array 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=20250905012535.2806919-1-csander@purestorage.com \
    --to=csander@purestorage.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox