Skip to contentSkip to conversation

io_uring: fix free of unallocated buffer list

PATCH Applied Dylan Yudaken 3 participants 3 messages Jul 21, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io_uring: fix free of unallocated buffer list

in the error path of io_register_pbuf_ring, only free bl if it was allocated.

Fixes c7fb19428d67 ("io_uring: add support for ring mapped supplied buffers")
---
 fs/io_uring.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/io_uring.c +3 -3
index a01ea49f3017..2b7bb62c7805 100644
@@ -12931,7 +12931,7 @@ static int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
 {
 	struct io_uring_buf_ring *br;
 	struct io_uring_buf_reg reg;
-	struct io_buffer_list *bl;
+	struct io_buffer_list *bl, *free_bl = NULL;
 	struct page **pages;
 	int nr_pages;
 
@@ -12963,7 +12963,7 @@ static int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
 		if (bl->buf_nr_pages || !list_empty(&bl->buf_list))
 			return -EEXIST;
 	} else {
-		bl = kzalloc(sizeof(*bl), GFP_KERNEL);
+		free_bl = bl = kzalloc(sizeof(*bl), GFP_KERNEL);
 		if (!bl)
 			return -ENOMEM;
 	}
@@ -12972,7 +12972,7 @@ static int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
 			     struct_size(br, bufs, reg.ring_entries),
 			     &nr_pages);
 	if (IS_ERR(pages)) {
-		kfree(bl);
+		kfree(free_bl);
 		return PTR_ERR(pages);
 	}
 

base-commit: ff6992735ade75aae3e35d16b17da1008d753d28

Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Dylan Yudaken

in the error path of io_register_pbuf_ring, only free bl if it was allocated.

Quoted 40 lines
Fixes c7fb19428d67 ("io_uring: add support for ring mapped supplied buffers")
---
  fs/io_uring.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
fs/io_uring.c +3 -3
index a01ea49f3017..2b7bb62c7805 100644
@@ -12931,7 +12931,7 @@ static int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
  {
  	struct io_uring_buf_ring *br;
  	struct io_uring_buf_reg reg;
-	struct io_buffer_list *bl;
+	struct io_buffer_list *bl, *free_bl = NULL;
  	struct page **pages;
  	int nr_pages;
 
@@ -12963,7 +12963,7 @@ static int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
  		if (bl->buf_nr_pages || !list_empty(&bl->buf_list))
  			return -EEXIST;
  	} else {
-		bl = kzalloc(sizeof(*bl), GFP_KERNEL);
+		free_bl = bl = kzalloc(sizeof(*bl), GFP_KERNEL);
  		if (!bl)
  			return -ENOMEM;
  	}
@@ -12972,7 +12972,7 @@ static int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
  			     struct_size(br, bufs, reg.ring_entries),
  			     &nr_pages);
  	if (IS_ERR(pages)) {
-		kfree(bl);
+		kfree(free_bl);
  		return PTR_ERR(pages);
  	}
 

base-commit: ff6992735ade75aae3e35d16b17da1008d753d28

Signature · 1 line
Pavel Begunkov
maintainer Applied
#2 lore raw
In reply to Dylan Yudaken
Quoted 4 lines · Dylan Yudaken

in the error path of io_register_pbuf_ring, only free bl if it was allocated.

Applied, thanks!

[1/1] io_uring: fix free of unallocated buffer list

      commit: ec8516f3b7c40ba7050e6b3a32467e9de451ecdf

Best regards,

Signature · 1 line
Jens Axboe