From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512335; b=XVmbTZMkiA5ae3hY8Fa8YuhcD9YHjwDtJP5k9UUnm6rGZqXnkO544zUYXf5Yhju0Sc1o LgwD0kHksqOWVW8sU9jjpvnsJlcL2qJ6WaTTHgCAjyJCmbU9KaQUkN1y/9zW3Q8nfYlHw iLx/YTKi+Uqy4krSNbeB9TbVwPBMkfbmXDxPIojvZdkt9zKWWajxbY4/a8BufEOiVDu1X LrTXHnH/1fpffGteO+M5vY42DbdJm7x///81t9kCvlQn3V9043306jEQMs+XzJweGgx+A d126KCNnTVPzADhU+nfUeUQ/DaMz30cFIX18DUBHYBm667Kplo1cLhKQEUSvjBQGCZA== 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=L0Wfr0jNwSN1dy2sgRDnNeJZz8Za/Oc6mU3D+CkbnikECrSVnVRY/AwLC6qHPzARMsjk jYl8V5adtmDha5OjICxBEQ0kK4S9C326vQF60FtAwzI5xfySqCYbyp5iyyuOsX3FgWHBd Am3dvJ+mJfydgpE7AOWoVAQMlYr+jeBD9UiJTt5c5JY1m93j03hdyztKAmo9A0R9KdA9P FkofrWLPmMRzJtby6YWBS+R8bq64pm/xmBumQWQFpE9Gw2tHUg5FWhFVOM5i/6xZHdDE8 +f5y34ryIvirWL7YeYD2GjIdGpBIQMb5m5oOvmw+BO1HkzS6XAAbuFvqSEDgaSSKiLg== 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.171 Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.171]) (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 A193D606A322 for ; Sat, 5 Dec 2026 23:12:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A193D606A322 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-f171.google.com with SMTP id 5614622812f47-4d198f1a591so2428328b6e.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=DA/+ofg4dTS+x6xNgMQUPOMsnExPcJ4t5oRXUGjPcyGz9IIvneMVTQCHWnn2rQd8U6 fo5752Y3TIwHgRqSudFrF54KQq8QxYabdZfdJLJypWbk+8seJ9JYZaSORU/pwUjKm51y MK6RdVlTzeihK05Tn7xMETajFvYsylgPlYMh/p6dHA5q6tTqlGfCPRdQb8o9AGVfr0Ee mAT924a4tolT3zOpu2tvTeP2l4FRP2Kc+pG1ez4NgjYAUEyHHKlSou9iYWilzUmsxxmx u07+oV/2BZ3kLdNgu87oxtSfEV4sVcFWquW5iQdYkV4105z7g2tLVYp1BYTQnEauhAjN ikiQ== X-Gm-Message-State: APuU4Z9iMHz50EyBoMnm93eBbHr0q/BMdoskUl8cuWEZNSj1sKGqnrYV zQHQsYVgfK5F5e74LZ8Yh2LSFvr9a1Rz9PYwftX2L+FWTsJP6NTuJpSudddccVfXzdsPwhnoG/9 C/HIaZdE= X-Gm-Gg: AZFdTZdKC6J60Y/DlD4vnLuGaYdVic7G3bj/Toj+IwsuY+ALd96kvmj8jEYUtsXCIeQ WADwuTvIRdmmLpaWr5JzofQCPUdjOLZZ78uF7q8IjfPU7T4obZE+86OK5IeqIfaxZlco8n3n2tl WaHO/cjhhC1yOjs579tJxpOV4PcLz24zrSWvQxD0um0YRHdCzJSxsec2Wgfk5+CBpVcJAziMC1k pXU03mcGyuwyJqWy4KTKA1kRW2I3oe0YA/Ejzc1vLOYe8n8WlpqyVkRUTcpf/zo8jv+xcdVuFHf 42P3wlKuL3Ve+vOuh9s5XroqG9bTUoZoNYEdgJpNIhGIkb0NJEWto7iGjn/ad/YCpIMscT7nJKh gKhuCAibHJ9bHKGLNIRKK/zzue2FKHWmuWATimGYP6FCnfct2Pya7HC1D8gM+K/8QnH+zBMgK4T LWQh55oBpkv9AH7QjFHtgOOYuqjLwaoMFhwSg07GSZwjF5C/TwMm/POew23zcnenwGDgaN6xjAi t3aiCZ61kFa0AX3p8eaQYF5bNVRAYRNvFk+sLzKsLP5I6y+bhlEhMFaynS6OS9dz5psP2i2jzMt 7ofs6fq6uSxT85UENX8N5iJMIhh8OMTvnzuuJAjwEJl3RZ/WKBP6zLlhtE2g2svsTA+04qthf8g oS49o3QpJuV0x96hAV1fbWgi/QPaVEOHNNpPD 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: 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 --- 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