From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512379; b=xmW0Pvk2vZgsqCCAxkvgQnESk1SoSx13sBtBsrpIl763Hdf3dCHWwjL5yYPeDWuw5mcp 2yywtBW2PYNdU8ptasXMcHSBvaQwVLXX6ORj+TA+Dx+rk2Ln41Pubxq5RTDb0kGz0T2/f 3otAsF9HngDYaiscmOPHto+RBFQBA8kMEg1UjAGLFct2yxSqkrV9aq+m7FEqsgjFygzwg 1eC+TPC4dK51W0rvLaej0mHD3meilbCOWsc2I6HmRoNl/Vh8J7cZYYEjSPE94JBgxvsgX Yp+i8dcXspsskD+I42GnezVQ+9vNh/OW4Ww8kVTF+Hjsc6vehmC6Mw910o+yJX8cS9g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512379; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=LcSAyEWAUCbeNdf5p6MY1etju9UAfYfZXc+pObgiy8Q=; b=WUSNVlV7kOKxBN6G43EE08tLwRDFfsDTYwKV37Nvp48s5IJ7Ats9bf9WJiP3VAfNBs8h Ag4ZQTqBoXw85elTh6gog2a30CeUtr4bBERzQ8QKEl89UzdHGLTk9HWAYuqWRaZix/wVQ jBVpI4NObPV7w4scyBJxIgcIcTUTDPOUfa86ganSNQDZxjUXjPMVfj0k7FGLl23imdMM4 80FvTL0yG9On06PheW65aRMeYGq22wlJfKLTK+9agvCJDjJneVjY06UAX8wwqDRe/TIaS 7jjTnxH5X7B84AQRnb2K46fVRzo6SW3xMKCYcb1+igYxeWUuuLE/28A9B0ahU88i5fQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass header.d=kernel.dk header.i=@kernel.dk header.a=rsa-sha256 header.s=google header.b="gL/ktTfB"; arc=none smtp.remote-ip=209.85.210.48 Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF10A606A31F for ; Sat, 5 Dec 2026 23:12:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BF10A606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.dk header.i=@kernel.dk header.a=rsa-sha256 header.s=google header.b=gL/ktTfB Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-8253bc5a613so1481557a34.0 for ; Sat, 05 Dec 2026 15:12:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512378; x=1797117178; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=LcSAyEWAUCbeNdf5p6MY1etju9UAfYfZXc+pObgiy8Q=; b=gL/ktTfBjxPi0wyCv9tNP8nOX+EUvWR6AGif+0W0CK6gpgizIncMzGXrlsYFZbnqQw 2TTLGv+EejgKudKYN65es15rTE4GYs4e3YnCEPfZ/7Xo9EbnQtLzElELkoAhXkOO7dU2 4zSXbxSpsYNDJKnksviNYivWBUXlD1eJIVoDUJMUPlCwSsHD1Jr5NpA/yypuDF8sh8Fk 1hp/aPl5nW/+3b43WyUVe9T7+eNJcZQdFU0S1kwAUveVG225K4Fvrcvfwrh0VJQyTTKo MHo78hIUB53uFlHTBn8zdeylBcFYrrqjYr5rw7gyOtaCSjwMOzGxMhxbd4QxnHKE6ayM HgJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512378; x=1797117178; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=LcSAyEWAUCbeNdf5p6MY1etju9UAfYfZXc+pObgiy8Q=; b=rmWvNrbH8d07AaJiCxjoAy2ImUARvbkJC06OAeOktsFS4/eutcI/lUN9Hn32N7yzR3 C+9OGZZ28O14a6PpbFWMLkHcLThc24ORsowo6e9mQQi6p0iBr703lMnWpBKK5sum6Vwb ut3L2QqbAH3k5uUH4LqtQl/drfPbxZPr0UeE0iqKNdqCY5omBS5F5hDOUFpPgV+g3Ors MTcSCiNTbwSGKUrYCsL0dHwFwK2n+7nsj55i5ZYMKvCJ9dwAUq2wEzn9tiUPdacNHjrY FO3jFWifFy1WE6GhSKwcPvdeNBddlj9rrpVgPoZtXl1kLf6+iv7UBJYigdB9gSuuJVs2 11HQ== X-Gm-Message-State: APuU4Z8nyNTJBCu4/j5LpZ/oNCHtOLlwcofXXHZ9DaaRcbjJMb4EjXqA TDgJcT8KtARXxqaJyoJ1OC8cr6EYBz+/IuuVvbDbtDMVS86qFO3vSodpzLO4SzSivuD9f8BMJlJ ERcpjjj8= X-Gm-Gg: AZFdTZfCb00kSzEYCkSf3wWKPnFgOOoQSpdIzPThga86FFP4jxohokd38PaAOLBDvJU VMIT8AHL5BLqhGojtPUO1g/fNpBGEmLJ6nJycgLGUzv2wWDCfKCrwBaH5szwxQAx11MF9VSDDWQ 8h+oRgy3wwBTA8roynTtZ6u4wsPfFJgxKbMMPjxth4A0mybIAsRVnbkWDg1JL95rCuHu38UzeQd Z9x/yCGcb+nul9mvVD/rLQ2BxbnlpqHganBTzcr+F37UkR2k6DxZlvbh6hoh/Px80qfTS7mTjJS QSRI9Hb9yo1h6IyFQzNEnqSVaOIT+oPyEpYU3s+1c+rNA9j2kgEYjvX8NkbSVG6lavli3ooG0Cj KOEJDQO+ZYjAne7NGQixm5ZoSX1mI27/nvY8SFTVL7FdVK9g2dR/ecKYqOsCQCuTN733RS/+ESu qIqks7UiGzxsUSFUML3RL74pDzb445vqad1zVk86AQt0YK84bXVy5Y23332dd+lcmf0eWLrj9Qr zaDtYLVBUh23v0HuhiF/L+mn9pYK5Cvr0otcploYrnKSGkC8j36bxy9wJLG6XlzoE83HMl6eeRM uQ0RliuPbvqZXtLba0d5mbzmtMkociD4W71dCufYrOre+8aDVDDFxFwShCtXkMGshuvGkLrsvbH hznBbYoZGPkZU/Wh0nL6XimG8BnspQrqNCKw/ X-Received: by 2002:a05:6830:7195:b0:863:ad49:1f74 with SMTP id 46e09a7af769-863f898cd6amr5791806a34.9.1796512377796; Sat, 05 Dec 2026 15:12:57 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863f7dd42a8sm6279788a34.0.2026.12.05.15.12.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:12:56 -0800 (PST) From: Jens Axboe 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 Message-ID: <20261205231233.4140988-14-axboe@kernel.dk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261205231233.4140988-1-axboe@kernel.dk> References: <20261205231233.4140988-1-axboe@kernel.dk> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Andrea Parri 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 Link: https://patch.msgid.link/20261204184949.185716-1-parri.andrea@gmail.com Signed-off-by: Jens Axboe [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