All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: stable@vger.kernel.org
Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org
Subject: [PATCH 6.6.y 13/13] io_uring/cancel: arm local work wakeups only for submitter
Date: Sat,  5 Dec 2026 23:12:33 +0000	[thread overview]
Message-ID: <20261205231233.4140988-14-axboe@kernel.dk> (raw)
In-Reply-To: <20261205231233.4140988-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>
[axboe: 6.6 has io_uring_try_cancel_requests() in io_uring.c]
---
 io_uring/io_uring.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 0f5b7ce5f618..d5bca05c6b21 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -3501,7 +3501,8 @@ static __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


      parent reply	other threads:[~2026-12-05 23:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 23:12 [PATCH 6.6.y 00/13] io_uring fixes for 6.6-stable Jens Axboe
2026-12-05 23:12 ` [PATCH 6.6.y 01/13] io_uring/net: don't charge the folio offset to truesize for managed frags Jens Axboe
2026-12-05 23:12 ` [PATCH 6.6.y 02/13] io_uring/net: don't copy msg_name on a recvmsg retry Jens Axboe
2026-12-05 23:12 ` [PATCH 6.6.y 03/13] io_uring/tctx: add separate lock for list of tctx's in ctx Jens Axboe
2026-12-05 23:12 ` [PATCH 6.6.y 04/13] io_uring: free the task context after a grace period Jens Axboe
2026-12-05 23:12 ` [PATCH 6.6.y 05/13] io_uring: free the ring " Jens Axboe
2026-12-05 23:12 ` [PATCH 6.6.y 06/13] io_uring/filetable: don't install O_PATH files Jens Axboe
2026-12-05 23:12 ` [PATCH 6.6.y 07/13] io_uring: make ctx->timeout_lock a raw spinlock Jens Axboe
2026-12-05 23:12 ` [PATCH 6.6.y 08/13] io_uring/timeout: flush timeouts outside of the timeout lock Jens Axboe
2026-12-05 23:12 ` [PATCH 6.6.y 09/13] io_uring/cancel: always walk links under timeout_lock Jens Axboe
2026-12-05 23:12 ` [PATCH 6.6.y 10/13] io_uring/net: restore the cmsg buffer on recvmsg retry Jens Axboe
2026-12-05 23:12 ` [PATCH 6.6.y 11/13] io_uring_poll: kill the no longer necessary barrier after poll_wait() Jens Axboe
2026-12-05 23:12 ` [PATCH 6.6.y 12/13] io_uring: close poll activation race when enabling rings Jens Axboe
2026-12-05 23:12 ` Jens Axboe [this message]

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=20261205231233.4140988-14-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.