From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512335; b=j14kqnSZNnZEyJqUaLYvszClHiCesyDjUp5lCsi3T0gyrtDW+wVBk3C7OaZ8SxExsE0A yihaZSZzDdkbdYKTrKfTU2wJcARPpAOzSdvIwpIB3CDJuOI7RurPFCFYBE2fFnWIdSF/A pdzyQJmkEAs9VSJRe+Q0b+2c2NT0Vu+UJ7UtgH+AX+AVYIyllZycZ06GECDaKRS5XP25j JX59th55xQGMWE59+y7bNjzNe9/AU/Rn1bcnl2AiTLk2xMtYF73kfQSL52AULIg9syQPE 7kFpBfQBiBioRhJdlODOTPfbQhVqu6nW2oPXFyAJeYaYAPhXFdh+66eBv6nV5SBjriQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512335; 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=0E5p9P+vNm+sQ7f41ndI45oVQ5EqldmaMZTEK2gJ18I=; b=La/mIrMzmthQ7UGhCHaJ3uDLnkhVJCvgnLINmuErquIjVGPzwtjl8X+w8xVu+DKHnUKP bo8ky6jrn/0QGFYUqsOumTA+qLDBalPbRwJoiEWmCwYBpIO0F6IRsyGq2U2OPrOuRCknu 3qfdXpoBchMipYjFdfSJKZ60ft6kZ4COJZFeDFSJg2UvtdaclIBOE+oewWdYslNRIkLCP 7cMAM8HxbsfPB3q6N0IaXZZnIVudCffS4ehmx0dTz7I4vf1wDopU4zCdzt4+Lw03AWm66 Hb55Cx87rK8V3qjhffsvzjsOrYbHV7ozeQB76pli9XDD9umF0YrgX42KiK1rAcvx7uw== 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=qxCgV+Gp; arc=none smtp.remote-ip=209.85.167.172 Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) (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 A063E606A31F for ; Sat, 5 Dec 2026 23:12:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A063E606A31F 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=qxCgV+Gp Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-4d198f1a591so2428329b6e.2 for ; Sat, 05 Dec 2026 15:12:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512334; x=1797117134; 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=0E5p9P+vNm+sQ7f41ndI45oVQ5EqldmaMZTEK2gJ18I=; b=qxCgV+Gpo3JG8+Iev34L2lqDGujy5Hwaw4NMKh6lIckQo+KMLrjFYv1Vpki1BzDHpz GuxcZvJiaXTqvNcFOVm+Pcy7yaFjyAGoeAktl8ipEjr3ctcSlQqu+M7X1Man+AuvUNqc LvyBCwfDokcqweiSM6/C4Z499Wj07G905N4p9GBmU5upoqoMpFHje/qLpslZoqmeA43E pbXW5q30+lfyDFs4SuhhqpmX/Jj6HrmYIhYSqRdaaEMmYydb0Sa6vFHcvJo/AVsBJUQw wfa+pHKRZ5GCuTKa3etTiChCcPWDNf0SCPzBB+4dylznZIxIxii/xPGFUEaNY2HCjSB+ n6Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512334; x=1797117134; 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=0E5p9P+vNm+sQ7f41ndI45oVQ5EqldmaMZTEK2gJ18I=; b=WNS9vjxMSz/6m1hgLl/0Ujd5EeUTvLKrnDArGjtIJ5Wu0wrdSg8Kdl/XEwfIshz0PA MAkvxwHahVlTn2RSyQHUkT7Olfxt1wwzVl9pvAnW6MvKkkJ+Jigttk4oPUf16WT+dMqN trNcOZw4SeUh05MMZUbdob/gGgcuKQJVRTc6s2/Dpn/5gZz34aFRPma7otcWItBSwDvZ 9Wl2Rbuqfe2QJ0PYmXCebLHyMK7OmpMNnkATLOOredwgp6JSqAVe0Rt2yNpz65iIrFPS seV1shQOuzZ69QE+SXOFHTi8txQM08MSb+PvlonADOh+g76Cb2QUXAm8+NB/v+0HBw1z Rbug== X-Gm-Message-State: APuU4Z8S6o0zRn+yBaDt7TYiNLByFQZ8Ei1SHc3MMObG0DD7v0BN3v6p NoK19CEeWM50gD0uwQyj4YFxC4OvnC64+wl+KYrFj0fIFCmFhsRC3VD6t8GMktFeCSFDo/1MnLF 6Y0Mol2Q= X-Gm-Gg: AZFdTZcQpgQW3quLUWPR6fcKKMywnPBKo3N2fP/yzUL3yXSxRKn+F4NiuowA6N377Wh EMgmYCWnA28hM2j5aeo2BaBo8s2ekO8AwwBGXACpt6xPpxbu84vhxgraA0u8zK+xV1eD8h3JasI 1SdAqnONDrGedET1cPlmM7TpQX0MD3TbffuXB3kt9LAlbfDfpfanjCa9c5uGbUfFldfNNMtAMRe J2j1mWtVK4sJdcHd6xbad87QUOzPFCTL40i/8DS3WNQR7YWSL7Py3EzVXwK6FManj6xMNeA20F+ YO1AWY64X9oe86HAnb7vCwiYp0uBHxUWRdWmGMKSqSywYfxOlvRjy9eya487FCXoLS13At+1FTT cU+hgJ+clo3HDxEDNWF6OX5qiViAt7V9Pzp9kdMfGZ/oI1lcJHgbTcFDIx4qKlahVWo4svOZp8j 2B/qxnhO1bl+Q9YkRYI5eNY43Ibc6Xo7ztcggPD3X/lW/3evvlut/fw8xiqkWqL6QLNpFaGJpIA hZyjNYKY00ejoWZ/16l4W+sKClv4xsLRUUGyIsE5LUD3rCEXyX2tb5in5WUoWfktuCwYNRmtcq0 TAjqOxXFcAN+FB5DfLcoUU2T2PEjyAIqPxoYXzTs16PouAh6p24T88HweByCOvOgIxnTya0THn2 dsIo+J299/tzFkHgxEYz/+yIiE/QyDJd5Ky4u X-Received: by 2002:a05:6808:4f28:b0:572:3644:95cf with SMTP id 5614622812f47-57f207bbfd4mr6299098b6e.26.1796512333709; Sat, 05 Dec 2026 15:12:13 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57f1f6fe2ecsm4086916b6e.14.2026.12.05.15.12.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:12:12 -0800 (PST) From: Jens Axboe 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 Message-ID: <20261205231147.4095031-13-axboe@kernel.dk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261205231147.4095031-1-axboe@kernel.dk> References: <20261205231147.4095031-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 --- 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