public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] io_uring: Fix NULL dereference in error in io_sqe_files_register()
@ 2021-02-01 12:23 Dan Carpenter
  2021-02-01 18:34 ` Pavel Begunkov
  2021-02-01 18:57 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2021-02-01 12:23 UTC (permalink / raw)
  To: Jens Axboe, Bijan Mottahedeh; +Cc: Pavel Begunkov, io-uring, kernel-janitors

If we hit a "goto out_free;" before the "ctx->file_data" pointer has
been assigned then it leads to a NULL derefence when we call:

	free_fixed_rsrc_data(ctx->file_data);

We can fix this by moving the assignment earlier.

Fixes: 3cfb739c561e ("io_uring: create common fixed_rsrc_data allocation routines")
Signed-off-by: Dan Carpenter <[email protected]>
---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 03748faa5295..8e8b74dd7d9b 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7869,6 +7869,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
 	file_data = alloc_fixed_rsrc_data(ctx);
 	if (!file_data)
 		return -ENOMEM;
+	ctx->file_data = file_data;
 
 	nr_tables = DIV_ROUND_UP(nr_args, IORING_MAX_FILES_TABLE);
 	file_data->table = kcalloc(nr_tables, sizeof(*file_data->table),
@@ -7878,7 +7879,6 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
 
 	if (io_sqe_alloc_file_tables(file_data, nr_tables, nr_args))
 		goto out_free;
-	ctx->file_data = file_data;
 
 	for (i = 0; i < nr_args; i++, ctx->nr_user_files++) {
 		struct fixed_rsrc_table *table;
-- 
2.29.2


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

* Re: [PATCH] io_uring: Fix NULL dereference in error in io_sqe_files_register()
  2021-02-01 12:23 [PATCH] io_uring: Fix NULL dereference in error in io_sqe_files_register() Dan Carpenter
@ 2021-02-01 18:34 ` Pavel Begunkov
  2021-02-01 18:57 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Pavel Begunkov @ 2021-02-01 18:34 UTC (permalink / raw)
  To: Dan Carpenter, Jens Axboe, Bijan Mottahedeh; +Cc: io-uring, kernel-janitors

On 01/02/2021 12:23, Dan Carpenter wrote:
> If we hit a "goto out_free;" before the "ctx->file_data" pointer has
> been assigned then it leads to a NULL derefence when we call:
> 
> 	free_fixed_rsrc_data(ctx->file_data);
> 
> We can fix this by moving the assignment earlier.

looks good, thanks

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

> 
> Fixes: 3cfb739c561e ("io_uring: create common fixed_rsrc_data allocation routines")
> Signed-off-by: Dan Carpenter <[email protected]>
> ---
>  fs/io_uring.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 03748faa5295..8e8b74dd7d9b 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -7869,6 +7869,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
>  	file_data = alloc_fixed_rsrc_data(ctx);
>  	if (!file_data)
>  		return -ENOMEM;
> +	ctx->file_data = file_data;
>  
>  	nr_tables = DIV_ROUND_UP(nr_args, IORING_MAX_FILES_TABLE);
>  	file_data->table = kcalloc(nr_tables, sizeof(*file_data->table),
> @@ -7878,7 +7879,6 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
>  
>  	if (io_sqe_alloc_file_tables(file_data, nr_tables, nr_args))
>  		goto out_free;
> -	ctx->file_data = file_data;
>  
>  	for (i = 0; i < nr_args; i++, ctx->nr_user_files++) {
>  		struct fixed_rsrc_table *table;
> 

-- 
Pavel Begunkov

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

* Re: [PATCH] io_uring: Fix NULL dereference in error in io_sqe_files_register()
  2021-02-01 12:23 [PATCH] io_uring: Fix NULL dereference in error in io_sqe_files_register() Dan Carpenter
  2021-02-01 18:34 ` Pavel Begunkov
@ 2021-02-01 18:57 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2021-02-01 18:57 UTC (permalink / raw)
  To: Dan Carpenter, Bijan Mottahedeh; +Cc: Pavel Begunkov, io-uring, kernel-janitors

On 2/1/21 5:23 AM, Dan Carpenter wrote:
> If we hit a "goto out_free;" before the "ctx->file_data" pointer has
> been assigned then it leads to a NULL derefence when we call:
> 
> 	free_fixed_rsrc_data(ctx->file_data);
> 
> We can fix this by moving the assignment earlier.

Applied, thanks Dan.

-- 
Jens Axboe


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

end of thread, other threads:[~2021-02-01 18:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-01 12:23 [PATCH] io_uring: Fix NULL dereference in error in io_sqe_files_register() Dan Carpenter
2021-02-01 18:34 ` Pavel Begunkov
2021-02-01 18:57 ` Jens Axboe

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