From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512299; b=LafxIsJulU5XAVY6cgX1IEdIHpPOdjxFtKiVNfQZwLblZ7iBUlPESVEbrU7rg9Nae/6U OJAmRlGs0GICwHP+FQF5CMQmMPfAFN6g61v6R6Nn5fMs26EHhfWbZfONvdbgvA9dGi/F3 kxzKHbrLb7kKOZ21ti4VubTUF6dzDVqKnoLfRAiRYDiWzbMxOS/pEboDDcEluGWgJLiO3 H5DaeQo47Y3i24QoFlcrJoejqbn+EjEy9oaXTu18e3q2i4zxs9IRY/abHFOcnmwHWgfTP IiPAS1C0PWQc22Cst1EHo1n9YDB5oIQ+7eZhaPRGYBpH4TGouJIezpp66AEZB0ho4uQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512299; 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=pk2glOTjUvgyxbOrDo4Gg1kxPVJLKw8rPX6mQu76ukU=; b=uypfdiBOiOp+PotVZBShcxP3822lzYHRFqbcuZfmUthee3WvLbFuseAjte7vZvQDSLka hBRChEdEqgu1BRB+A6Rn9UVu8xbJblqB7wi00mcnK6mnHr5thXrB6eVdV+3eCF7t0eF7P SoE0jJo7CkhdMzSkvnM2GUvlfd0lH+LZXLSyWFN3Z+pDe1Y4P2FFiibxSzjxyBvoqkUr2 X5MVg0ghrgy7aM8QDMS/mFcG7aGkzm7b3D0clKfiED1bo40XmiR4h3gaMANTY98dUSf+X W7V13Zz1OgwtRtdC2Sy/+lsQz8wNXm70rEJhbzJ+k8a0Lj3p5yvoydSeQQ13m2bAKeQ== 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=txWPKInV; arc=none smtp.remote-ip=209.85.210.52 Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (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 132A7606A333 for ; Sat, 5 Dec 2026 23:11:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 132A7606A333 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=txWPKInV Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-843cf077f10so3234792a34.1 for ; Sat, 05 Dec 2026 15:11:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512298; x=1797117098; 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=pk2glOTjUvgyxbOrDo4Gg1kxPVJLKw8rPX6mQu76ukU=; b=txWPKInV5iIDfmKELzHdeCENLGLR/dYfNwBHxQ1bsXsuUq2PLCjCDxMzmGy7CZVfIw Hekq4QYi9S0ObWuo4CsxOAsoCVRq4rnRBPb8YgSbKmQw3cX7qCsEDwHf8wrKUdpx6Nm6 qfNJkuKshCIfyJsYolI4yrMArBCn84p5IvJK6AK0rTYiXCrby5mtlRMplNph1HQ6Wlby T421U5QYIAhN+B0R95fwNcEj0A7c/qGN7dNLE/gezTu647fvG9TIOoa00TqQB3ge0O8L sDHHj5SaSjPH03yrcm1JqFQADqLyixT6r8i7+RenLNu0kZklDN5eMxKZegsgU+h1zP7h f5rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512298; x=1797117098; 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=pk2glOTjUvgyxbOrDo4Gg1kxPVJLKw8rPX6mQu76ukU=; b=0YzuwcuJJS+2nXRuQHFt/iqw3ss4reayS6QTjUGVrSCQGIEoXxtw/b9ZjCJUA9/9T1 e+O6jk7Ludies9TfZ+/ZnH7UIHW2QgRGWUm5Hug5j/XX7WMkmBJoXIzhjAZJlUvse7PQ O/qYQ03aHIxJl91fm2+5l+VOgxYCoH+vpmel/Y+kLkmygBmtrlRlY1IeLVeo9TayBrc0 EMQAOzFOI9uN1pVpGojx7ihYo924bU5HtuPy+o+LKU4t7rMLg7K8mFaAWN5a9Et8+Std wtIHp/8abmVNiNq6T+de7+EO4T0US/b6enrwDwSZE5WZEbzQ7RBYs21k6CDR0v8J7M0/ fLnA== X-Gm-Message-State: APuU4Z98uiAuN757yaXZlQnwWLtI7G/2jd2EbT4qvxODSfNaxW1pFWkV FYPlqA1U3x5x7bs11Cl1D/TEDqG+1LpZ53QU74ehwKMJsiiuTYv3LunB2uhqxZEW7P/k++ZZFqX kTz4DOxU= X-Gm-Gg: AZFdTZdP7wCjYDzFP/7zeW200AjA6xEFpDX+xgs5+QJUXedsYPk5PAp507fFg0/ekJm 3SMsGxXqbGkgxTze98QvUNirODItc4LncNQKwuahfdvR20DqDN9aEK1OMigxq8pm0j+QLTPcvce rNXqcg973i6/DKj+fELhizBhtrh1CjcXWlQGbhPP1vdzF2MsiAZpR/OCFeF7fC/7uN0AMCQgjyv CsCjkAZ6LAFqLkr6fWGoXTJeWRvwmIfX/wNA8jc11+EBxY1iNXS0anjb9kYnhhMEOfezA+QlHBB lmU1PYYpVr6Aoidpd1uITADBfTc0C6aceaJK12l9J01qswXZKGkfYs4m8Ototn2AewQvFgVgNy/ YfiVyd7kpsFf9u8do1XC/O17ek2BJxyp8vhU0Gti6XbVh1dXh/8ivgit11A3PjcDSNOsLoukGPo 4dlur9Hvu8wW0lh0j+jXtC2E2JY3z9bwuislSzvcniNAwH8ipLAp43kSR+6hFTPLLFqvJ5sLsQn zNz+j7PUbr626dPpGX+q9wPDnIC2FYL8Hfry5ZJ6Ge325MzdTVtMDD3EedXcbAdXT1WqXfOOSmu 1AMSDkEmY/eoCaWbgfd+JK8hnbeVBjH7ZmJ0O3etLwdnx4nGbc3pzbg1VCM63myampmXOLvVqA1 CtINRmBr8tDnt39+sTqR2BdyUHRSEl3iaoaMr X-Received: by 2002:a05:6808:4fd2:b0:4b3:7b31:8df7 with SMTP id 5614622812f47-57f2073ce0fmr5884018b6e.14.1796512298139; Sat, 05 Dec 2026 15:11:38 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57f1f65febbsm4163964b6e.6.2026.12.05.15.11.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:11:37 -0800 (PST) From: Jens Axboe To: stable@vger.kernel.org Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 6.12.y 15/15] io_uring/cancel: arm local work wakeups only for submitter Date: Sat, 5 Dec 2026 23:11:07 +0000 Message-ID: <20261205231107.4023506-16-axboe@kernel.dk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261205231107.4023506-1-axboe@kernel.dk> References: <20261205231107.4023506-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.12 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 1f67e0596faf..c27b0b3c4e7c 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -3189,7 +3189,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