Skip to contentSkip to conversation

io_uring: disallow mixed provided buffer group registrations

PATCH New Jens Axboe 1 participant 1 message May 18, 2022

Subsystems (2)
lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH 1/1 io_uring: disallow mixed provided buffer group registrations

It's nonsensical to register a provided buffer ring, if a classic provided buffer group with the same ID exists. Depending on the order of which we decide what type to pick, the other type will never get used. Explicitly disallow it and return an error if this is attempted.

Fixes c7fb19428d67 ("io_uring: add support for ring mapped supplied buffers")

---

fs/io_uring.c +5 -3
index 24d56b2a0637..065ea45de29c 100644
@@ -12156,9 +12156,11 @@ static int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
 	}
 
 	bl = io_buffer_get_list(ctx, reg.bgid);
-	if (bl && bl->buf_nr_pages)
-		return -EEXIST;
-	if (!bl) {
+	if (bl) {
+		/* if mapped buffer ring OR classic exists, don't allow */
+		if (bl->buf_nr_pages || !list_empty(&bl->buf_list))
+			return -EEXIST;
+	} else {
 		bl = kzalloc(sizeof(*bl), GFP_KERNEL);
 		if (!bl)
 			return -ENOMEM;
Signature · 1 line
Jens Axboe