* [PATCH] io_uring: fix ctx cancellation for rings allocation failure
@ 2021-04-01 9:10 Hao Xu
2021-04-01 9:11 ` Pavel Begunkov
0 siblings, 1 reply; 2+ messages in thread
From: Hao Xu @ 2021-04-01 9:10 UTC (permalink / raw)
To: Jens Axboe; +Cc: io-uring, Pavel Begunkov, Joseph Qi
abaci reported the follow issue:
RDX: 0000000000000001 RSI: 0000000020000a80 RDI: 0000000000007a32
RBP: 0000000000000000 R08: 00007facc4ccb1bd R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000004007c0
R13: 00007ffdf5fa1380 R14: 0000000000000000 R15: 0000000000000000
BUG: kernel NULL pointer dereference, address: 00000000000000c0
PGD 8000000105fc7067 P4D 8000000105fc7067 PUD 10c6a5067 PMD 0
Oops: 0002 [#1] SMP PTI
Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011
RIP: 0010:io_commit_cqring+0xf6/0x190 fs/io_uring.c:1318
Code: 85 c0 0f 85 6d ff ff ff e8 67 2d d4 ff 44 89 a5 10 06 00 00 e8 5b 2d d4 ff 48 8b 85 40 04 00 00 8b 95 00 06 00 00 4c 8d 65 78 <89> 90 c0 00 00 00 48 8b 45 78 49 39 c4 75 6c 5b 5d 41 5c 41 5d e9
RSP: 0018:ffffc90001283db0 EFLAGS: 00010093
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
RDX: 0000000000000000 RSI: ffffffff814c2b45 RDI: ffff888105f0b000
RBP: ffff888105f0b000 R08: ffff88810c534c80 R09: 00000000fffffffe
R10: 0000000089b853a8 R11: 00000000fec8d1bc R12: ffff888105f0b078
R13: ffff888105f0b088 R14: 0000000000000000 R15: 0000000000100140
FS: 00007facc547d740(0000) GS:ffff88813bd00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00000000000000c0 CR3: 000000010c5a0006 CR4: 00000000003706e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
io_kill_timeouts+0x125/0x140 fs/io_uring.c:8606
io_ring_ctx_wait_and_kill+0x109/0x1d0 fs/io_uring.c:8629
io_uring_create+0x4c9/0xfb0 fs/io_uring.c:9574
io_uring_setup+0x8c/0xd0 fs/io_uring.c:9601
do_syscall_64+0x2d/0x40 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x7facc4d76239
Code: 01 00 48 81 c4 80 00 00 00 e9 f1 fe ff ff 0f 1f 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 27 ec 2c 00 f7 d8 64 89 01 48
RSP: 002b:00007ffdf5fa1298 EFLAGS: 00000246 ORIG_RAX: 00000000000001a9
RAX: ffffffffffffffda RBX: 0000000000400d38 RCX: 00007facc4d76239
RDX: 0000000000000001 RSI: 0000000020000a80 RDI: 0000000000007a32
RBP: 0000000000000000 R08: 00007facc4ccb1bd R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000004007c0
R13: 00007ffdf5fa1380 R14: 0000000000000000 R15: 0000000000000000
Modules linked in:
Dumping ftrace buffer:
(ftrace buffer empty)
CR2: 00000000000000c0
This is caused by access ctx->rings in io_ring_ctx_wait_and_kill()
while ctx->rings is NULL because of allocation failure.
Reported-by: Abaci <[email protected]>
Signed-off-by: Hao Xu <[email protected]>
---
fs/io_uring.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 1949b80677e7..03f593f5e740 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8616,12 +8616,16 @@ static void io_ring_ctx_wait_and_kill(struct io_ring_ctx *ctx)
unsigned long index;
struct creds *creds;
+ if (!ctx->rings) {
+ io_ring_ctx_free(ctx);
+ return;
+ }
+
mutex_lock(&ctx->uring_lock);
percpu_ref_kill(&ctx->refs);
/* if force is set, the ring is going away. always drop after that */
ctx->cq_overflow_flushed = 1;
- if (ctx->rings)
- __io_cqring_overflow_flush(ctx, true, NULL, NULL);
+ __io_cqring_overflow_flush(ctx, true, NULL, NULL);
xa_for_each(&ctx->personalities, index, creds)
io_unregister_personality(ctx, index);
mutex_unlock(&ctx->uring_lock);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] io_uring: fix ctx cancellation for rings allocation failure
2021-04-01 9:10 [PATCH] io_uring: fix ctx cancellation for rings allocation failure Hao Xu
@ 2021-04-01 9:11 ` Pavel Begunkov
0 siblings, 0 replies; 2+ messages in thread
From: Pavel Begunkov @ 2021-04-01 9:11 UTC (permalink / raw)
To: Hao Xu, Jens Axboe; +Cc: io-uring, Joseph Qi
> This is caused by access ctx->rings in io_ring_ctx_wait_and_kill()
> while ctx->rings is NULL because of allocation failure.
Yep, missed it out but already fixed
https://git.kernel.dk/cgit/linux-block/commit/?h=io_uring-5.12&id=51520426f4bc3e61cbbf7a39ccf4e411b665002d
> Reported-by: Abaci <[email protected]>
> Signed-off-by: Hao Xu <[email protected]>
> ---
> fs/io_uring.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 1949b80677e7..03f593f5e740 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -8616,12 +8616,16 @@ static void io_ring_ctx_wait_and_kill(struct io_ring_ctx *ctx)
> unsigned long index;
> struct creds *creds;
>
> + if (!ctx->rings) {
> + io_ring_ctx_free(ctx);
> + return;
> + }
> +
> mutex_lock(&ctx->uring_lock);
> percpu_ref_kill(&ctx->refs);
> /* if force is set, the ring is going away. always drop after that */
> ctx->cq_overflow_flushed = 1;
> - if (ctx->rings)
> - __io_cqring_overflow_flush(ctx, true, NULL, NULL);
> + __io_cqring_overflow_flush(ctx, true, NULL, NULL);
> xa_for_each(&ctx->personalities, index, creds)
> io_unregister_personality(ctx, index);
> mutex_unlock(&ctx->uring_lock);
>
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-01 9:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-01 9:10 [PATCH] io_uring: fix ctx cancellation for rings allocation failure Hao Xu
2021-04-01 9:11 ` Pavel Begunkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox