From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512372; b=JfpFVVbU2xAR1T07Ry4B7pLD+RylM7YOhVe/wPMTU1vACDFJppPPXD5E/iLG+aD1t/zp DmGIlOd7nn8Wxe1JL3liXDQNZDLQv0J4TgBqY952TbUEOC4Zz395CyK/UpgaFh3sLrgt/ CrDBwQU5zfAKczIRz0HqDVO42uLCo1d2CrKV8zyq5TlDPmMEFr3Q/OrxZhwDrZloDRrWr lbsOUI3o+22k5gbXq+bHwa12zQfYEo/6y2tE/guJI4TDSnzplQEGNr+baw2WUATGLZWj6 OdR4JOwODqZbUvql28XMOF/10deUmV5NpJOFuKpRjDPQWGFxOQayp08Pm3QgveK9aRg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512372; 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=Nl3fZCFz0oCIt8rLI1FSNywy+o0SgM1mRxrOXi63L68=; b=qUUDi4neZ+5W7RFZnNmH+sFQEhR3WehV+85WVsHf9otq+myBPHFplgIYyR5z2U081Qyc tRY0fVRVeSNdEoMmOmZkg8g2b8SSYVJaFHEr9cyiQr3OxapM6UrcX7ZQNeWbVj8RMN6/a 1dmS1cgEgm+cDnA9uf1GxJ0fTYJpcvTEYTXRjjorC97776hQe//3s3Bq5YvkQAqMMwnGk zBVOy38CqvbsuymLOWz8NkCTdhZyjppXrN+t/r4Dz2i0b0+XIUSbz0ZGebefHuxfLuQkp 1ATprEz1KQJLCZejrLxePZvBbJZNEfkfVH5eqAbvHE8Pv8lJDg3NkTXB9ykirs0eOHw== 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=nx0C+c1K; arc=none smtp.remote-ip=209.85.210.46 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) (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 1837E606A335 for ; Sat, 5 Dec 2026 23:12:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1837E606A335 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=nx0C+c1K Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-84a248254f4so1377181a34.0 for ; Sat, 05 Dec 2026 15:12:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512371; x=1797117171; 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=Nl3fZCFz0oCIt8rLI1FSNywy+o0SgM1mRxrOXi63L68=; b=nx0C+c1KUWG4BVqWYxg/WubTj2lg/Qk1vGAUGw0B+aVdcWIz03Xp5pUh0yxlnYxYhs Hlnvx/U9XO28ot47cf/Km7w5/lWNvi3XI+kA7brojEBMwzTWlDInmV+/jBrgirP70HHP H2P1kHDdIkuw3wmoDGQHWoDOtzt+SC7j6C/+05C/j5t8Btop/wXE3qs+UWyOn7b/49BZ 36bf5jwSSxGqPh5h7Wr4mv9q5cTA2FDrwR07Ot33WlNZfX3qIWizKcA0FC2y5LZVWJla ROcHrzr14i6qR6gU0gMD/C5T6jLTe330N0SGLAUjr1eY05Vh56Mwzetiw7WarOOPDY/O T0FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512371; x=1797117171; 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=Nl3fZCFz0oCIt8rLI1FSNywy+o0SgM1mRxrOXi63L68=; b=Eyo/e0w7BXYXgc0n0S7am4VUJlqxROl+Jq8jQgKD+fcbcOKrXq7giUSLwQmUoRjq+Q mAKDRMrBCHv2qXAf4X8f1VK/fcWG0qFC/0/bBUXBhKDGh0Ni7igvUjvUGB7NIFA5k4EZ Cleaaw+jI4YjxzuQv9q4Ya9jJQThvV1nTVasRmaYqWIQke/gEFYN84FrEGmaVNHqrW15 Xty34NvgtrDndJqE+p+/x0g9AKWjqMhH9NmBhxFcfmyHyXE8+8/j3W2qt0xVfaNJRg4K TDPeZt7/Q7eymr+PLz0xVWAbI1HjMPeNSqs/HpePacIbiP3TrK/kBKsqm9Vlth4LJ+A6 NHrA== X-Gm-Message-State: APuU4Z/I8oADx4UlBFO58UA/kOlZco9Utawk0+rYDQu1peEhxaK8CMMF Eijnd0o1vffL6nN2UCaJgZ8yTQ8LrYQuTJm8kwqhega8OQip78Z6weDUuhNHZfba7v3U+hBcOcy oFHN36Ig= X-Gm-Gg: AZFdTZfsYZ15KXfI5gZkQYfs9bDGiYTGIwBdue7Rr63TfpgrSdn9lxvGe4Sx2dvFRme 6PzF1eqtd/UYv8MAwkCeEatpJ5uDxhk+0kS2T39YcufjyZREtOMgPT5UJ9NcQh4lk57x31jwxij dx3sg9Q7blE9mRa7rnE9xEUbYInX/EfUi8ATT1zLivR5dbmjiQreb6tdVp8lMZh0tWvzmRXQUld wlYu6L7bQQ4qYzm2bw+OcVxVb+PwKdTeUbgMNUV436/JpQCO8jwA6GxVeXgisM6WW/XOVI6k7SX FchZxonvPbHN3RuqE2T8X12EWvjnEtG4YRs8mHSg1muyQ5SJATL8XgnseN2XWIXcIDKSWc9kbeN 0CVQJ9HGf7MHfJFV+SVE/Op81lVzljMVx5K/QXWjUQCqpnsoRHj3skG/1X4+yt6bcvYNI2cYqpL jp0qzh9s1fmD2/+PgSoxFmsZTY8PPHBkrXeOedMoPiAW2YIZGcpX/myTD4dP424YwGHYpDN+jjv Pk/KJuRev9hKJSyaT0Yd3cuG9Sem0N58QAjfRWKJ9wBfyYHb3A2+yUGsiA19P3i4xDTXPTtid07 UoJqv3/L8qlwf0K+j0cA4c7LbXhg3fysTI1ndD/bbiYEbh340YfB2dAQPcql90IN4G9wnC35WTL J4skSBo8+cHW+lhfGqKLe80QC7sR4lu71XwDQ X-Received: by 2002:a05:6830:44a7:b0:81c:e293:7d66 with SMTP id 46e09a7af769-863f89ef71dmr6000131a34.21.1796512371097; Sat, 05 Dec 2026 15:12:51 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863f7dd42a8sm6279788a34.0.2026.12.05.15.12.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:12:50 -0800 (PST) From: Jens Axboe To: stable@vger.kernel.org Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 6.6.y 09/13] io_uring/cancel: always walk links under timeout_lock Date: Sat, 5 Dec 2026 23:12:29 +0000 Message-ID: <20261205231233.4140988-10-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: Chris Mason Commit a6b53de207d3472f209e71fd4990be3dd3133d1f upstream. The exit of a single thread that races with the close of its IORING_SETUP_DEFER_TASKRUN ring can cause a use-after-free of a linked timeout, if io-wq is the first to issue the request that the timeout is linked to. When io-wq calls io_match_task_safe(), ->timeout_lock alone protects the walk of the link chain against the removal of a linked timeout. The function takes the lock only if the head has REQ_F_LINK_TIMEOUT. But the first issue sets that flag. If that happens in an io-wq worker, cancellation can find the request as the current work of the worker before the flag is set: io_match_task_safe() io-wq worker, timer, task_work ==================== ============================== REQ_F_LINK_TIMEOUT is clear io_match_linked() req = head->link __io_issue_sqe() __io_prep_linked_timeout() io_queue_linked_timeout() io_link_timeout_fn() io_req_task_link_timeout() __io_req_caches_free() req = req->link The fix used here is to take ->timeout_lock for every walk, whatever the flags of the head say. Signed-off-by: Chris Mason Signed-off-by: Jens Axboe [axboe: 6.6 has io_match_task_safe() in io_uring.c] --- io_uring/io_uring.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 1dd7bfcfc80a..7a05875d2b7d 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -210,6 +210,7 @@ static bool io_match_linked(struct io_kiocb *head) bool io_match_task_safe(struct io_kiocb *head, struct task_struct *task, bool cancel_all) { + struct io_ring_ctx *ctx = head->ctx; bool matched; if (task && head->task != task) @@ -217,16 +218,13 @@ bool io_match_task_safe(struct io_kiocb *head, struct task_struct *task, if (cancel_all) return true; - if (head->flags & REQ_F_LINK_TIMEOUT) { - struct io_ring_ctx *ctx = head->ctx; - - /* protect against races with linked timeouts */ - raw_spin_lock_irq(&ctx->timeout_lock); - matched = io_match_linked(head); - raw_spin_unlock_irq(&ctx->timeout_lock); - } else { - matched = io_match_linked(head); - } + /* + * Protect against races with linked timeouts. REQ_F_LINK_TIMEOUT can't + * tell if there is one: an io-wq worker may set it during the walk. + */ + raw_spin_lock_irq(&ctx->timeout_lock); + matched = io_match_linked(head); + raw_spin_unlock_irq(&ctx->timeout_lock); return matched; } -- 2.55.0