From: Jens Axboe <axboe@kernel.dk>
To: stable@vger.kernel.org
Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org
Subject: [PATCH 6.18.y 12/14] io_uring/cancel: arm local work wakeups only for submitter
Date: Sat, 5 Dec 2026 23:11:45 +0000 [thread overview]
Message-ID: <20261205231147.4095031-13-axboe@kernel.dk> (raw)
In-Reply-To: <20261205231147.4095031-1-axboe@kernel.dk>
From: Andrea Parri <parri.andrea@gmail.com>
Commit 709d9af776febf3a0773727939742460a55e14e2 upstream.
io_uring_try_cancel_requests() arms cq_wait_nr on every DEFER_TASKRUN
ring it visits, so that io_req_local_work_add() wakes the caller. The
wakeup goes to submitter_task, which need not be the caller. A
cancelling task can visit a ring whose local work belongs to another
task, and ring release and io_ring_exit_work() call in as well.
A cancelling task can also visit a ring that is still disabled, where
submitter_task is NULL. A later ZCRX event then passes it to
wake_up_state():
BUG: kernel NULL pointer dereference, address: 00000000000008e4
RIP: 0010:_raw_spin_lock_irqsave+0x1b/0x50
Call Trace:
try_to_wake_up+0x51/0x790
io_req_local_work_add+0xbb/0x1b0
zcrx_send_notif+0xf9/0x120
On an enabled ring, the same arm can replace the submitter's cq_wait_nr
batch threshold and cause an early wakeup. If the submitter is not
waiting on the ring, a later local work add can still find the count
armed and wake the submitter from an unrelated interruptible sleep.
Arm cq_wait_nr only when the caller is allowed to run the ring's local
work. The submitter-only rearm before cancellation sleeps already uses
the same ownership check.
ZCRX could skip disabled rings, as msg_ring does, but that leaves the
wrong arm on enabled rings. Work that ZCRX queues on a disabled ring
waits there until the ring is enabled, or until io_ring_exit_work()
drains it.
ZCRX events are the only local work a disabled ring can receive, so the
NULL pointer dereference needs commit 0719e10d826a ("io_uring/zcrx:
notify user when out of buffers"). Older kernels only see the early
wakeups.
Tested in a 2-vCPU x86-64 KVM guest with a reproducer that execs with
an io_uring request pending while ZCRX copy events target a disabled
DEFER_TASKRUN ring. v7.4-rc5 hit the NULL pointer dereference above.
With this patch, 1000 runs completed.
The bug was found with the help of an LLM, which was also used to write
the fix, the changelog and the tests.
Fixes: 360cd42c4e95 ("io_uring: optimise io_req_local_work_add")
Cc: stable@vger.kernel.org
Signed-off-by: Andrea Parri <parri.andrea@gmail.com>
Link: https://patch.msgid.link/20261204184949.185716-1-parri.andrea@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/cancel.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/io_uring/cancel.c b/io_uring/cancel.c
index b4d31de286fe..4971dbaaf929 100644
--- a/io_uring/cancel.c
+++ b/io_uring/cancel.c
@@ -537,7 +537,8 @@ __cold bool io_uring_try_cancel_requests(struct io_ring_ctx *ctx,
bool ret = false;
/* set it so io_req_local_work_add() would wake us up */
- if (ctx->flags & IORING_SETUP_DEFER_TASKRUN) {
+ if ((ctx->flags & IORING_SETUP_DEFER_TASKRUN) &&
+ io_allowed_defer_tw_run(ctx)) {
atomic_set(&ctx->cq_wait_nr, 1);
smp_mb();
}
--
2.55.0
next prev parent reply other threads:[~2026-12-05 23:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 23:11 [PATCH 6.18.y 00/14] io_uring fixes for 6.18-stable Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 01/14] io_uring/net: don't charge the folio offset to truesize for managed frags Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 02/14] io_uring/net: don't copy msg_name on a recvmsg retry Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 03/14] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 04/14] io_uring/tctx: add separate lock for list of tctx's in ctx Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 05/14] io_uring: free the task context after a grace period Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 06/14] io_uring: free the ring " Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 07/14] io_uring/filetable: don't install O_PATH files Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 08/14] io_uring/cancel: always walk links under timeout_lock Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 09/14] io_uring/net: don't count the buffers of a send bundle Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 10/14] io_uring/net: restore the cmsg buffer on recvmsg retry Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 11/14] io_uring: close poll activation race when enabling rings Jens Axboe
2026-12-05 23:11 ` Jens Axboe [this message]
2026-12-05 23:11 ` [PATCH 6.18.y 13/14] io_uring/zcrx: cache fallback availability in zcrx ctx Jens Axboe
2026-12-05 23:11 ` [PATCH 6.18.y 14/14] io_uring/zcrx: don't sync dma-bufs Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205231147.4095031-13-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=gregkh@linuxfoundation.org \
--cc=io-uring@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox