public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] io_uring: initialize io_buffer_list head when shared ring is unregistered
@ 2022-05-18 20:38 Jens Axboe
  2022-05-18 20:58 ` [PATCH v2] " Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Jens Axboe @ 2022-05-18 20:38 UTC (permalink / raw)
  To: io-uring

We use ->buf_pages != 0 to tell if this is a shared buffer ring or a
classic provided buffer group. If we unregister the shared ring and
then attempt to use it, buf_pages is zero yet the classic list head
isn't properly initialized. This causes io_buffer_select() to think
that we have classic buffers available, but then we crash when we try
and get one from the list.

Just initialize the list if we unregister a shared buffer ring, leaving
it in a sane state for either re-registration or for attempting to use
it.

Fixes: c7fb19428d67 ("io_uring: add support for ring mapped supplied buffers")
Signed-off-by: Jens Axboe <[email protected]>

---

diff --git a/fs/io_uring.c b/fs/io_uring.c
index a210a2c0429d..23d68f8dfc66 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -12200,6 +12200,9 @@ static int io_unregister_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
 	if (bl->bgid >= BGID_ARRAY) {
 		xa_erase(&ctx->io_bl_xa, bl->bgid);
 		kfree(bl);
+	} else {
+		/* make sure it's seen as empty */
+		INIT_LIST_HEAD(&bl->buf_list);
 	}
 	return 0;
 }

-- 
Jens Axboe


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

* [PATCH v2] io_uring: initialize io_buffer_list head when shared ring is unregistered
  2022-05-18 20:38 [PATCH] io_uring: initialize io_buffer_list head when shared ring is unregistered Jens Axboe
@ 2022-05-18 20:58 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2022-05-18 20:58 UTC (permalink / raw)
  To: io-uring

We use ->buf_pages != 0 to tell if this is a shared buffer ring or a
classic provided buffer group. If we unregister the shared ring and
then attempt to use it, buf_pages is zero yet the classic list head
isn't properly initialized. This causes io_buffer_select() to think
that we have classic buffers available, but then we crash when we try
and get one from the list.

Just initialize the list if we unregister a shared buffer ring, leaving
it in a sane state for either re-registration or for attempting to use
it.

Fixes: c7fb19428d67 ("io_uring: add support for ring mapped supplied buffers")
Signed-off-by: Jens Axboe <[email protected]>

---

v2: do it in the place where we clear buf_nr_pages, that's safer and
    cleaner.

diff --git a/fs/io_uring.c b/fs/io_uring.c
index a210a2c0429d..24d56b2a0637 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -4969,6 +4969,8 @@ static int __io_remove_buffers(struct io_ring_ctx *ctx,
 		kvfree(bl->buf_pages);
 		bl->buf_pages = NULL;
 		bl->buf_nr_pages = 0;
+		/* make sure it's seen as empty */
+		INIT_LIST_HEAD(&bl->buf_list);
 		return i;
 	}
 

-- 
Jens Axboe


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

end of thread, other threads:[~2022-05-18 20:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-18 20:38 [PATCH] io_uring: initialize io_buffer_list head when shared ring is unregistered Jens Axboe
2022-05-18 20:58 ` [PATCH v2] " Jens Axboe

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