public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] io_uring/msg_ring: Fix NULL pointer dereference in io_msg_send_fd()
@ 2022-10-19 17:12 Harshit Mogalapalli
  2022-10-19 19:33 ` Jens Axboe
  2022-10-19 19:49 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Harshit Mogalapalli @ 2022-10-19 17:12 UTC (permalink / raw)
  Cc: vegard.nossum, harshit.m.mogalapalli, harshit.m.mogalapalli,
	syzkaller, Jens Axboe, Pavel Begunkov, io-uring, linux-kernel

Syzkaller produced the below call trace:

 BUG: KASAN: null-ptr-deref in io_msg_ring+0x3cb/0x9f0
 Write of size 8 at addr 0000000000000070 by task repro/16399

 CPU: 0 PID: 16399 Comm: repro Not tainted 6.1.0-rc1 #28
 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.0-2.el7
 Call Trace:
  <TASK>
  dump_stack_lvl+0xcd/0x134
  ? io_msg_ring+0x3cb/0x9f0
  kasan_report+0xbc/0xf0
  ? io_msg_ring+0x3cb/0x9f0
  kasan_check_range+0x140/0x190
  io_msg_ring+0x3cb/0x9f0
  ? io_msg_ring_prep+0x300/0x300
  io_issue_sqe+0x698/0xca0
  io_submit_sqes+0x92f/0x1c30
  __do_sys_io_uring_enter+0xae4/0x24b0
....
 RIP: 0033:0x7f2eaf8f8289
 RSP: 002b:00007fff40939718 EFLAGS: 00000246 ORIG_RAX: 00000000000001aa
 RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f2eaf8f8289
 RDX: 0000000000000000 RSI: 0000000000006f71 RDI: 0000000000000004
 RBP: 00007fff409397a0 R08: 0000000000000000 R09: 0000000000000039
 R10: 0000000000000000 R11: 0000000000000246 R12: 00000000004006d0
 R13: 00007fff40939880 R14: 0000000000000000 R15: 0000000000000000
  </TASK>
 Kernel panic - not syncing: panic_on_warn set ...

We don't have a NULL check on file_ptr in io_msg_send_fd() function,
so when file_ptr is NUL src_file is also NULL and get_file()
dereferences a NULL pointer and leads to above crash.

Add a NULL check to fix this issue.

Fixes: e6130eba8a84 ("io_uring: add support for passing fixed file descriptors")
Reported-by: syzkaller <[email protected]>
Signed-off-by: Harshit Mogalapalli <[email protected]>
---
I am not completely sure whether to place the NULL check on file_ptr
which i did in this case as file_ptr is NULL, or the masked src_file.

Similar checks are present in other files, io_uring/filetable.c has NULL
check before masking and io_uring/cancel.c has NULL check after masking
with FFS_MASK.
---
 io_uring/msg_ring.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c
index 4a7e5d030c78..90d2fc6fd80e 100644
--- a/io_uring/msg_ring.c
+++ b/io_uring/msg_ring.c
@@ -95,6 +95,9 @@ static int io_msg_send_fd(struct io_kiocb *req, unsigned int issue_flags)
 
 	msg->src_fd = array_index_nospec(msg->src_fd, ctx->nr_user_files);
 	file_ptr = io_fixed_file_slot(&ctx->file_table, msg->src_fd)->file_ptr;
+	if (!file_ptr)
+		goto out_unlock;
+
 	src_file = (struct file *) (file_ptr & FFS_MASK);
 	get_file(src_file);
 
-- 
2.37.1


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

* Re: [PATCH] io_uring/msg_ring: Fix NULL pointer dereference in io_msg_send_fd()
  2022-10-19 17:12 [PATCH] io_uring/msg_ring: Fix NULL pointer dereference in io_msg_send_fd() Harshit Mogalapalli
@ 2022-10-19 19:33 ` Jens Axboe
  2022-10-19 19:49 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2022-10-19 19:33 UTC (permalink / raw)
  To: Harshit Mogalapalli
  Cc: vegard.nossum, harshit.m.mogalapalli, syzkaller, Pavel Begunkov,
	io-uring, linux-kernel

On 10/19/22 10:12 AM, Harshit Mogalapalli wrote:
> Syzkaller produced the below call trace:
> 
>  BUG: KASAN: null-ptr-deref in io_msg_ring+0x3cb/0x9f0
>  Write of size 8 at addr 0000000000000070 by task repro/16399
> 
>  CPU: 0 PID: 16399 Comm: repro Not tainted 6.1.0-rc1 #28
>  Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.0-2.el7
>  Call Trace:
>   <TASK>
>   dump_stack_lvl+0xcd/0x134
>   ? io_msg_ring+0x3cb/0x9f0
>   kasan_report+0xbc/0xf0
>   ? io_msg_ring+0x3cb/0x9f0
>   kasan_check_range+0x140/0x190
>   io_msg_ring+0x3cb/0x9f0
>   ? io_msg_ring_prep+0x300/0x300
>   io_issue_sqe+0x698/0xca0
>   io_submit_sqes+0x92f/0x1c30
>   __do_sys_io_uring_enter+0xae4/0x24b0
> ....
>  RIP: 0033:0x7f2eaf8f8289
>  RSP: 002b:00007fff40939718 EFLAGS: 00000246 ORIG_RAX: 00000000000001aa
>  RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f2eaf8f8289
>  RDX: 0000000000000000 RSI: 0000000000006f71 RDI: 0000000000000004
>  RBP: 00007fff409397a0 R08: 0000000000000000 R09: 0000000000000039
>  R10: 0000000000000000 R11: 0000000000000246 R12: 00000000004006d0
>  R13: 00007fff40939880 R14: 0000000000000000 R15: 0000000000000000
>   </TASK>
>  Kernel panic - not syncing: panic_on_warn set ...
> 
> We don't have a NULL check on file_ptr in io_msg_send_fd() function,
> so when file_ptr is NUL src_file is also NULL and get_file()
> dereferences a NULL pointer and leads to above crash.
> 
> Add a NULL check to fix this issue.
> 
> Fixes: e6130eba8a84 ("io_uring: add support for passing fixed file descriptors")
> Reported-by: syzkaller <[email protected]>
> Signed-off-by: Harshit Mogalapalli <[email protected]>
> ---
> I am not completely sure whether to place the NULL check on file_ptr
> which i did in this case as file_ptr is NULL, or the masked src_file.
> 
> Similar checks are present in other files, io_uring/filetable.c has NULL
> check before masking and io_uring/cancel.c has NULL check after masking
> with FFS_MASK.

Doesn't really matter when it's done, but we should arguably have a
helper for this to avoid having differences in this pattern.

-- 
Jens Axboe

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

* Re: [PATCH] io_uring/msg_ring: Fix NULL pointer dereference in io_msg_send_fd()
  2022-10-19 17:12 [PATCH] io_uring/msg_ring: Fix NULL pointer dereference in io_msg_send_fd() Harshit Mogalapalli
  2022-10-19 19:33 ` Jens Axboe
@ 2022-10-19 19:49 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2022-10-19 19:49 UTC (permalink / raw)
  To: Harshit Mogalapalli
  Cc: Pavel Begunkov, linux-kernel, vegard.nossum, io-uring,
	harshit.m.mogalapalli, syzkaller

On Wed, 19 Oct 2022 10:12:18 -0700, Harshit Mogalapalli wrote:
> Syzkaller produced the below call trace:
> 
>  BUG: KASAN: null-ptr-deref in io_msg_ring+0x3cb/0x9f0
>  Write of size 8 at addr 0000000000000070 by task repro/16399
> 
>  CPU: 0 PID: 16399 Comm: repro Not tainted 6.1.0-rc1 #28
>  Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.0-2.el7
>  Call Trace:
>   <TASK>
>   dump_stack_lvl+0xcd/0x134
>   ? io_msg_ring+0x3cb/0x9f0
>   kasan_report+0xbc/0xf0
>   ? io_msg_ring+0x3cb/0x9f0
>   kasan_check_range+0x140/0x190
>   io_msg_ring+0x3cb/0x9f0
>   ? io_msg_ring_prep+0x300/0x300
>   io_issue_sqe+0x698/0xca0
>   io_submit_sqes+0x92f/0x1c30
>   __do_sys_io_uring_enter+0xae4/0x24b0
> ....
>  RIP: 0033:0x7f2eaf8f8289
>  RSP: 002b:00007fff40939718 EFLAGS: 00000246 ORIG_RAX: 00000000000001aa
>  RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f2eaf8f8289
>  RDX: 0000000000000000 RSI: 0000000000006f71 RDI: 0000000000000004
>  RBP: 00007fff409397a0 R08: 0000000000000000 R09: 0000000000000039
>  R10: 0000000000000000 R11: 0000000000000246 R12: 00000000004006d0
>  R13: 00007fff40939880 R14: 0000000000000000 R15: 0000000000000000
>   </TASK>
>  Kernel panic - not syncing: panic_on_warn set ...
> 
> [...]

Applied, thanks!

[1/1] io_uring/msg_ring: Fix NULL pointer dereference in io_msg_send_fd()
      (no commit info)

Best regards,
-- 
Jens Axboe



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

end of thread, other threads:[~2022-10-19 19:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-19 17:12 [PATCH] io_uring/msg_ring: Fix NULL pointer dereference in io_msg_send_fd() Harshit Mogalapalli
2022-10-19 19:33 ` Jens Axboe
2022-10-19 19:49 ` Jens Axboe

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