From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512400; b=zOYQV65QfHLXYWqYScIQwW/OmYQa5kfWmQ8wzvK4VwalDVrXzDDYUwbXgq2Qq9K9b4iC g9vH3x14hhzq2xe1IVLNrzRzrVYjyjVkU8GS6knvsB6c7KS2nTq49RaJPx0gxwyf8lxUU Nubg8pQRpmtYC7DlkUPGr0MKOJCyK2d+GQMLduzqkGNch0nl2EtvhpVHdWE48kjy71Apl X5iOSbGRXDa8Xb9Fbv65YWgg6OJrT7K+avOz0sdmElqYTIZ7OdRklnmwAScWMyrmVId2s zvszaMJsloFj+cj2ADAEaIMV9HsSHO3uqhxs9earvZ83aYsJybw1CeRnclatZrorZBA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512400; 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=sd/SZO9yIEIVsS3m1iVhEZ198IKSIDBwGTscvuFtJTI=; b=Q21WLpYaz84Ghbs9HtQXI0yf6tlHfnCoxfH9rxjVJQJuGN8a2l58ENtmBLZeLTiylFLa 5QyIgE+wYKkKD/mwbguVfvAVe3ZgCqvaVxXImlW1GrGy5sw1bPCnKbHWFUzU1Cbd65tfK z3wV2LuocVQ8HhkB3h3RvV94iPo1Lgur7IBnyPsCe2qzojh7U/iWhbfYK2gbfBIZlm5Uh pBHQrNRDF30NStxnLlCjVz5L1vb+/7h2mEttQjYjDA3PyXsXL3sy1Cgp8MBgIAFiTYytE 9fex+Ms7AupysCZOkjSbIUe4imdYITzyckrBSQlSsw8W3N698c1/JpQNFfT3SvepR7Q== 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=h2FZVzaf; arc=none smtp.remote-ip=209.85.210.45 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (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 2CA08606A32F for ; Sat, 5 Dec 2026 23:13:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2CA08606A32F 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=h2FZVzaf Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-862a19300b7so748421a34.2 for ; Sat, 05 Dec 2026 15:13:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512399; x=1797117199; 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=sd/SZO9yIEIVsS3m1iVhEZ198IKSIDBwGTscvuFtJTI=; b=h2FZVzaf8bQCO0ySS3eEUTtv3HnznD5LFWZRSXoOE/AKs169Z9D1KOrSTnFKDJwqaQ hXkp5n/H+2NRoR9zkZYHFMAD4WfDUzF/WQEhVv6zW/YCapzXHKud1EJqbK8AXcI0lOBc 78PLCpgzaAYZ5k+2OGZheK0JUe0VnFpmaeJz83MwD/1A2pDRSTFrNlp0TURJbIqGYlbW 6fA8BQr3IF5rGk6hh5ipM0S43ErCyIPZSAaLrHYWreiZ4Hf4xPRkb6k0ibFZLR9kvLM3 2nFrzwNmKqmvxhaXU8gjKd11nSI+1vnw4tLoySrul2tDuuYy+8HDwKqqrvw5CVbCkhEg LHQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512399; x=1797117199; 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=sd/SZO9yIEIVsS3m1iVhEZ198IKSIDBwGTscvuFtJTI=; b=bXiU0/jzVabkygwjdl+YileJYmbLMU4PnF4Q3s8mMVXuaE4rHbBF8Mx8zuRBB916cM NuDGlilXJcdDztJJV0HlfZnmB31NxGJh654d5ACW0k+XsPEVLsitxIRa7fBv9usGmRie h5SnSgU/tRwSm7atA5vYzpspzYtJhssQGPII4TMqtv/DJJzheKRXVnrWs14xw5iTxu0/ D32ZXl+yR1LRYKAdmLF4eZXXa0lXaESNbwhD/N2OiYlBvhXm2rVH2F9XDFHStEduMD0S L0GJrUkf3Q5kd7lf3jQHNBUwavdeCE8+NI0eIQZ58Xvt2D524S7TDUctA/foLCJ5b2ms F3MQ== X-Gm-Message-State: APuU4Z8y7IQxrHPec2HawDNJeHc1MW5nv8LTHh4FZDre2ePgZVho1DIx LqQ0TJDVPhjCjnSBUtzePAZCwVu5uBC4ExdgmDvNffaOwdKE3IWEh7fc0TvGWMKzXmM= X-Gm-Gg: AZFdTZfprps8H7jihJXsaaum6JzadOq3rDvmzRI2gfXZTowa2yqHl053qYhOtjdlAnY MwA85+Wla4RHgvJUVD3BtUpnOWi6OeRDwolfBN/5qYIVN2y97firAZ6K3adu3ccwdwYiVmcChRt f1qHZxzrKXkHqv6OdNt/fuzOpd5Sd3G2cZO+XskevX/Y/sSKvTwblFhkrhzS0enpHnJlh3itWxB 1lnVr7ZQQgSAr3WAk55qYvsVylevAP4eT0IThEnQo1bpAoDXSQBCpq40/dAHStbvozHDxsbfv56 KRSnLtXTrBSlOBNxegeiAh37QZhoxY7CAluI7mi7rWErarf/dGoq9szcPXMDk46wL68ONnXpLNl 0OUeNlxyCiQ9TMOoprBK2DK5NWb+r/avFv33k5azX8bV2PmpeNGdtsFNWqZO4SUtPFAyysqWRus px+dqtyyeHzDDlpIgukhcUPgEnJE0LWSVugYtwNV4l4wHe03w9ILUP0tHswrK9kiZtxKwtkzNM1 1II+z6T4e0jB9FIy/B22tFFzKVwk3du7DCe6NCEeuyjcGEP6vvNQfabmyq0FiNWsgBfku7ottxB LYMPm3ttCS3GHVZeF7udT8ajE70vqWCAkAWgr+mknJfOGOBJSRuPtK5FXiutZOmuApDj7NCNJ63 mBfihhQH+FE5GuBgxD7hcTam7kzSMSBgZrX+P X-Received: by 2002:a05:6830:4125:b0:862:b109:249d with SMTP id 46e09a7af769-863f8a2f7ffmr6426496a34.31.1796512399217; Sat, 05 Dec 2026 15:13:19 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863f8331ff6sm6269737a34.22.2026.12.05.15.13.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:13:18 -0800 (PST) From: Jens Axboe To: stable@vger.kernel.org Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 7.3.y 06/15] io_uring/timeout: hold timeout_lock for the link splice Date: Sat, 5 Dec 2026 23:12:56 +0000 Message-ID: <20261205231305.4158103-7-axboe@kernel.dk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261205231305.4158103-1-axboe@kernel.dk> References: <20261205231305.4158103-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: Chris Mason Commit 40162f8314a98948e0791b580024bbc899d2ee81 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 that has fired. io-wq calls its match function under raw spinlocks, so there io_match_task_safe() walks the link chain without ->uring_lock. It holds ->timeout_lock, which is enough only if a linked timeout leaves the chain under that lock. But io_req_task_link_timeout() does the splice under ->uring_lock alone. Once the ring is closed, the closing task runs that task_work, and with a drain active the flush frees the request: io_match_task_safe() io_cancel_local_task_work() ==================== =========================== lock ->timeout_lock io_match_linked() req = head->link lock ->uring_lock io_req_task_link_timeout() prev->link = req->link io_req_task_complete() io_submit_flush_completions() io_free_batch_list() io_queue_deferred() __io_req_caches_free() req = req->link The fix used here is to hold ->timeout_lock as well for the splice, which stays in task_work and under ->uring_lock. Fixes: 49ae66eb8c27 ("io_uring: defer linked-timeout chain splice out of hrtimer context") Signed-off-by: Chris Mason Signed-off-by: Jens Axboe --- io_uring/timeout.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/io_uring/timeout.c b/io_uring/timeout.c index b46a50b39517..cdc41634c324 100644 --- a/io_uring/timeout.c +++ b/io_uring/timeout.c @@ -392,11 +392,14 @@ static void io_req_task_link_timeout(struct io_tw_req tw_req, io_tw_token_t tw) if (prev) { /* * splice the linked timeout out of prev's chain if the regular - * completion path didn't already do it. + * completion path didn't already do it. io-wq cancellation + * walks the chain with only ->timeout_lock held. */ + raw_spin_lock_irq(&req->ctx->timeout_lock); if (prev->link == req) prev->link = req->link; req->link = NULL; + raw_spin_unlock_irq(&req->ctx->timeout_lock); if (!tw.cancel) { struct io_cancel_data cd = { -- 2.55.0