IO-Uring Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH][next] io_uring: fix missing error return when percpu_ref_init fails
@ 2019-12-20 23:33 Colin King
  2019-12-20 23:48 ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: Colin King @ 2019-12-20 23:33 UTC (permalink / raw)
  To: Jens Axboe, Alexander Viro, io-uring, linux-fsdevel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently when the call to percpu_ref_init fails ctx->file_data is
set to null and because there is a missing return statement the
following statement dereferences this null pointer causing an oops.
Fix this by adding the missing -ENOMEM return to avoid the oops.

Addresses-Coverity: ("Explicit null dereference")
Fixes: cbb537634780 ("io_uring: avoid ring quiesce for fixed file set unregister and update")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 fs/io_uring.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index c756b8fc44c6..1d31294f5914 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -4937,6 +4937,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
 		kfree(ctx->file_data->table);
 		kfree(ctx->file_data);
 		ctx->file_data = NULL;
+		return -ENOMEM;
 	}
 	ctx->file_data->put_llist.first = NULL;
 	INIT_WORK(&ctx->file_data->ref_work, io_ring_file_ref_switch);
-- 
2.24.0


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

* Re: [PATCH][next] io_uring: fix missing error return when percpu_ref_init fails
  2019-12-20 23:33 [PATCH][next] io_uring: fix missing error return when percpu_ref_init fails Colin King
@ 2019-12-20 23:48 ` Jens Axboe
  2019-12-20 23:49   ` Colin Ian King
  0 siblings, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2019-12-20 23:48 UTC (permalink / raw)
  To: Colin King, Alexander Viro, io-uring, linux-fsdevel
  Cc: kernel-janitors, linux-kernel

On 12/20/19 4:33 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently when the call to percpu_ref_init fails ctx->file_data is
> set to null and because there is a missing return statement the
> following statement dereferences this null pointer causing an oops.
> Fix this by adding the missing -ENOMEM return to avoid the oops.

Nice, thanks! I'm guessing I didn't have the necessary magic debug
options to allow failure injection for failing.


-- 
Jens Axboe


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

* Re: [PATCH][next] io_uring: fix missing error return when percpu_ref_init fails
  2019-12-20 23:48 ` Jens Axboe
@ 2019-12-20 23:49   ` Colin Ian King
  2019-12-20 23:50     ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: Colin Ian King @ 2019-12-20 23:49 UTC (permalink / raw)
  To: Jens Axboe, Alexander Viro, io-uring, linux-fsdevel
  Cc: kernel-janitors, linux-kernel

On 20/12/2019 23:48, Jens Axboe wrote:
> On 12/20/19 4:33 PM, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> Currently when the call to percpu_ref_init fails ctx->file_data is
>> set to null and because there is a missing return statement the
>> following statement dereferences this null pointer causing an oops.
>> Fix this by adding the missing -ENOMEM return to avoid the oops.
> 
> Nice, thanks! I'm guessing I didn't have the necessary magic debug
> options to allow failure injection for failing.

Fortunately we have Coverity to the rescue :-)

Colin



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

* Re: [PATCH][next] io_uring: fix missing error return when percpu_ref_init fails
  2019-12-20 23:49   ` Colin Ian King
@ 2019-12-20 23:50     ` Jens Axboe
  0 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2019-12-20 23:50 UTC (permalink / raw)
  To: Colin Ian King, Alexander Viro, io-uring, linux-fsdevel
  Cc: kernel-janitors, linux-kernel

On 12/20/19 4:49 PM, Colin Ian King wrote:
> On 20/12/2019 23:48, Jens Axboe wrote:
>> On 12/20/19 4:33 PM, Colin King wrote:
>>> From: Colin Ian King <colin.king@canonical.com>
>>>
>>> Currently when the call to percpu_ref_init fails ctx->file_data is
>>> set to null and because there is a missing return statement the
>>> following statement dereferences this null pointer causing an oops.
>>> Fix this by adding the missing -ENOMEM return to avoid the oops.
>>
>> Nice, thanks! I'm guessing I didn't have the necessary magic debug
>> options to allow failure injection for failing.
> 
> Fortunately we have Coverity to the rescue :-)

Indeed!

-- 
Jens Axboe


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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-20 23:33 [PATCH][next] io_uring: fix missing error return when percpu_ref_init fails Colin King
2019-12-20 23:48 ` Jens Axboe
2019-12-20 23:49   ` Colin Ian King
2019-12-20 23:50     ` Jens Axboe

IO-Uring Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/io-uring/0 io-uring/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 io-uring io-uring/ https://lore.kernel.org/io-uring \
		io-uring@vger.kernel.org
	public-inbox-index io-uring

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.io-uring


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git