From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512300; b=ZfeaiKaQwKme5Xy0URs46FWdUIdp6ALw6pcVWagmZ7Wur+AlNKr3KN6sj4Eb2RckKxud y2sqlPMHTqBjOBQyNRhW5WaDmqxArOigtJO84PkTaMDNApd9H4f3qbINJkbwp91Wdo/2R jiDLH+CXn7wxSRgsJ2W2oXd9ZvNAzoEDhWci/lERH1/YRSaWeqFhVaKoKmKhchy1osBmC UJY4Dhugcv6anK2Dt5XYS1u4T30ecxcoCP8a7vP/HSk/nJigk+bNLt0WDfIyVf//ioJGn NLtbqzRBFwSkxRzTel0ogSyT8rfbBKiDbnvnPVWyPAReh2zaWp1es3+E4awSRzcQfCQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512300; 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=2+W38BlhZOrUbCQLQpMRKzvTBfGJvnH2hvc4OSuWhL3cJezlYqUUoLcYa7GKY5KnBOZM vZoE2oYarFwYmDmRaotTeH3MeRA4smzUGuiraEzUjLFOPRf5cZZaBq6xpsVTniUoJI+nj 5uQLA2K92ce4XB1/azFIarCjGDMqqqBqoNYOhnAUVBmd9YjLZo2nQbk+J9o+AVeIYRi/t 604xihaScpOYC02Y7IxTMcMCI4TR/ubybN3RYT4vdTF4ddwWd6w8pw21hYBe8DQWix2+H L5ewpCpJ1tLF7pN6tXNhsbrRpxpvG3OGKNKFVzlJQCZqgvb7ChrOALpUsprJF/FEP6w== 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.51 Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) (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 12FC5606A32F for ; Sat, 5 Dec 2026 23:11:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 12FC5606A32F 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-f51.google.com with SMTP id 46e09a7af769-843cf077f10so3234791a34.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=VONDB+/7vTdubh1NXRPvIRDPm5p2orr+X9sRWBWYrwRjcKUWVUSMRIYxDPv79IGUz/ 92SXbfwPpdFhdU6drbu9BMfzopAL57joZxfS69xV5E+GWlc+WXJ+Gz9klOOzkwR/9QPy l7L+WfzpyPtPvjTeZCs1HendsmxOOArlA5/xdSwnvm0Tu20aytExLJtxF2/7nKhcNrO8 b/b/N4tNfgjGdLpCtziZ5p1AZ9qS5HCB0aeWIx1FjaDMJ5rG3SirPiWPXwYoYmwBTg3N 1/PBP74zhzJl74AjGRw9iYVIy55Kd9sQrizDneukUMDa9+ak5Y0rG9zEiSF6GqXsNS6a 14OQ== X-Gm-Message-State: APuU4Z/7hAkL75UCMaA2GoO5lS/RaiXAdjy0tGDUvdpsHQp58L39mXMa VcYPK0JiYh1W3YM+mbQ1iLvMrnkGOV8WGl9cweFBhA1Fcun9vELKCPTnHDjKMjfs6Isfgg3mniD h0Jwn1u0= X-Gm-Gg: AZFdTZdOHuZcp9rUB2y3v80JUAqnAqewvNcMA1TiBagTDcqtFtCQIJx70BCosvosDaW d1jZkuBWdEU1U6iogdrsT8Z1ttno+UnKide0bwBF6GGBMjmnIayXtWhMQp/h/DgsN2dh1F6RllP V9JFQUOF6peAcFq2yMh/qp4Sa99DjwkXnBSdeWfkuXptZz/lC0JkGJIOCamaimpp+U1Eq52LlgY YIzYWbqOJO6c83bxHBCUugf4NVn3RndTgQGTWni8FNgMz527gadXVuTWStnZgB6uc1eYkFY9/no fEIMykPRVIrZ/dQ5kzhyN/UXLYOq4Lt3/iQewXVFJuzR2If6/5Cp8nt4Q6FMsFSLRyyWFAYWXco gHb3Oo+RT2rQcE1+KasWAlSpGof4Z7Htayc6lnsZ4PPPSUInxlakIrgS2uxv47eq11foaEz1tMb cQqloI4nIhb995LBsfhR/d8T9QkiQUxEqE/ZNR5p/OioMwuAFebiiZMZjIphID1pBqHx+luwvlG Cc5S4OHRWLHpB461JYMggSeiJJ9IT9IlYFsYicaQpNPczdKFs4Rz+sH/FWpKaImcXBvHPSfbG2b oxg3k8XEycHiBE/GW32fZlZJAdp0anKmXaIWz1d8Xn5YCXfV5OWKYr+gcsvYkPQiIK6JvzJ6mC3 ju+AumQ9TL3xfVxWOnfjhG6ue9lQLvgDZdDL+ 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: io-uring@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