public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH 5.12] io_uring: handle setup-failed ctx in kill_timeouts
@ 2021-03-29 10:39 Pavel Begunkov
  2021-03-29 12:49 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Pavel Begunkov @ 2021-03-29 10:39 UTC (permalink / raw)
  To: Jens Axboe, io-uring; +Cc: syzbot+0e905eb8228070c457a0

general protection fault, probably for non-canonical address
	0xdffffc0000000018: 0000 [#1] KASAN: null-ptr-deref
	in range [0x00000000000000c0-0x00000000000000c7]
RIP: 0010:io_commit_cqring+0x37f/0xc10 fs/io_uring.c:1318
Call Trace:
 io_kill_timeouts+0x2b5/0x320 fs/io_uring.c:8606
 io_ring_ctx_wait_and_kill+0x1da/0x400 fs/io_uring.c:8629
 io_uring_create fs/io_uring.c:9572 [inline]
 io_uring_setup+0x10da/0x2ae0 fs/io_uring.c:9599
 do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xae

It can get into wait_and_kill() before setting up ctx->rings, and hence
io_commit_cqring() fails. Mimic poll cancel and do it only when we
completed events, there can't be any requests if it failed before
initialising rings.

Fixes: 80c4cbdb5ee60 ("io_uring: do post-completion chore on t-out cancel")
Reported-by: [email protected]
Signed-off-by: Pavel Begunkov <[email protected]>
---
 fs/io_uring.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index a4a944da95a0..088a9d3c420a 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8603,9 +8603,9 @@ static bool io_kill_timeouts(struct io_ring_ctx *ctx, struct task_struct *tsk,
 			canceled++;
 		}
 	}
-	io_commit_cqring(ctx);
+	if (canceled != 0)
+		io_commit_cqring(ctx);
 	spin_unlock_irq(&ctx->completion_lock);
-
 	if (canceled != 0)
 		io_cqring_ev_posted(ctx);
 	return canceled != 0;
-- 
2.24.0


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

* Re: [PATCH 5.12] io_uring: handle setup-failed ctx in kill_timeouts
  2021-03-29 10:39 [PATCH 5.12] io_uring: handle setup-failed ctx in kill_timeouts Pavel Begunkov
@ 2021-03-29 12:49 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2021-03-29 12:49 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring; +Cc: syzbot+0e905eb8228070c457a0

On 3/29/21 4:39 AM, Pavel Begunkov wrote:
> general protection fault, probably for non-canonical address
> 	0xdffffc0000000018: 0000 [#1] KASAN: null-ptr-deref
> 	in range [0x00000000000000c0-0x00000000000000c7]
> RIP: 0010:io_commit_cqring+0x37f/0xc10 fs/io_uring.c:1318
> Call Trace:
>  io_kill_timeouts+0x2b5/0x320 fs/io_uring.c:8606
>  io_ring_ctx_wait_and_kill+0x1da/0x400 fs/io_uring.c:8629
>  io_uring_create fs/io_uring.c:9572 [inline]
>  io_uring_setup+0x10da/0x2ae0 fs/io_uring.c:9599
>  do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
>  entry_SYSCALL_64_after_hwframe+0x44/0xae
> 
> It can get into wait_and_kill() before setting up ctx->rings, and hence
> io_commit_cqring() fails. Mimic poll cancel and do it only when we
> completed events, there can't be any requests if it failed before
> initialising rings.

Thanks, applied.

-- 
Jens Axboe


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

end of thread, other threads:[~2021-03-29 12:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-29 10:39 [PATCH 5.12] io_uring: handle setup-failed ctx in kill_timeouts Pavel Begunkov
2021-03-29 12: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