public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] io_uring: fix free of unallocated buffer list
@ 2022-07-21 11:01 Dylan Yudaken
  2022-07-21 11:03 ` Pavel Begunkov
  2022-07-21 14:29 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Dylan Yudaken @ 2022-07-21 11:01 UTC (permalink / raw)
  To: Jens Axboe, Pavel Begunkov, io-uring
  Cc: Kernel-team, linux-kernel, Dylan Yudaken, Dipanjan Das

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

Reported-by: Dipanjan Das <[email protected]>
Fixes: c7fb19428d67 ("io_uring: add support for ring mapped supplied buffers")
Signed-off-by: Dylan Yudaken <[email protected]>
---
 fs/io_uring.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index a01ea49f3017..2b7bb62c7805 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -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
-- 
2.30.2


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

* Re: [PATCH] io_uring: fix free of unallocated buffer list
  2022-07-21 11:01 [PATCH] io_uring: fix free of unallocated buffer list Dylan Yudaken
@ 2022-07-21 11:03 ` Pavel Begunkov
  2022-07-21 14:29 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Pavel Begunkov @ 2022-07-21 11:03 UTC (permalink / raw)
  To: Dylan Yudaken, Jens Axboe, io-uring
  Cc: Kernel-team, linux-kernel, Dipanjan Das

On 7/21/22 12:01, Dylan Yudaken wrote:
> in the error path of io_register_pbuf_ring, only free bl if it was
> allocated.

Reviewed-by: Pavel Begunkov <[email protected]>


> Reported-by: Dipanjan Das <[email protected]>
> Fixes: c7fb19428d67 ("io_uring: add support for ring mapped supplied buffers")
> Signed-off-by: Dylan Yudaken <[email protected]>
> ---
>   fs/io_uring.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index a01ea49f3017..2b7bb62c7805 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -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

-- 
Pavel Begunkov

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

* Re: [PATCH] io_uring: fix free of unallocated buffer list
  2022-07-21 11:01 [PATCH] io_uring: fix free of unallocated buffer list Dylan Yudaken
  2022-07-21 11:03 ` Pavel Begunkov
@ 2022-07-21 14:29 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2022-07-21 14:29 UTC (permalink / raw)
  To: io-uring, dylany, asml.silence
  Cc: Kernel-team, linux-kernel, mail.dipanjan.das

On Thu, 21 Jul 2022 04:01:15 -0700, Dylan Yudaken wrote:
> 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,
-- 
Jens Axboe



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

end of thread, other threads:[~2022-07-21 14:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-21 11:01 [PATCH] io_uring: fix free of unallocated buffer list Dylan Yudaken
2022-07-21 11:03 ` Pavel Begunkov
2022-07-21 14:29 ` Jens Axboe

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