Skip to contentSkip to conversation

io_uring/rsrc: fix null ptr dereference in io_sqe_buffer_register

PATCH In review Daniel Yang 2 participants 2 messages Nov 4, 2024 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io_uring/rsrc: fix null ptr dereference in io_sqe_buffer_register

The call stack io_sqe_buffer_register -> io_buffer_account_pin -> headpage_already_acct results in a null ptr dereference in the for loop. There is no guarantee that ctx->buf_table.nodes[i] is an allocated node so add a check if null before dereferencing.

Reported-by [email protected]
Fixes 661768085e99 ("io_uring/rsrc: get rid of the empty node and dummy_ubuf")
---
 io_uring/rsrc.c | 2 ++
 1 file changed, 2 insertions(+)
io_uring/rsrc.c +2 -0
index af60d9f59..e2edb752a 100644
@@ -581,6 +581,8 @@ static bool headpage_already_acct(struct io_ring_ctx *ctx, struct page **pages,
 	/* check previously registered pages */
 	for (i = 0; i < ctx->buf_table.nr; i++) {
 		struct io_rsrc_node *node = ctx->buf_table.nodes[i];
+		if (!node)
+			continue;
 		struct io_mapped_ubuf *imu = node->buf;
 
 		for (j = 0; j < imu->nr_bvecs; j++) {
Signature · 1 line
2.39.2
maintainer
#1 lore raw
Quoted 4 lines · Daniel Yang

The call stack io_sqe_buffer_register -> io_buffer_account_pin -> headpage_already_acct results in a null ptr dereference in the for loop. There is no guarantee that ctx->buf_table.nodes[i] is an allocated node so add a check if null before dereferencing.

Assuming this is an older tree, it's fixed in the current tree.

Signature · 1 line
Jens Axboe