From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379549; b=YgX2QGP7BFWfjF2ZvMGVO4MMnv58qykL2f2wyel186jxcpbrpSyrju+AB4D/eTK6QnAA 65lEozIBddO7qzzmBCq3TU+aVNDV7rlZMDTwT/WmZBcVo/lJAcVq5EllBjt/uG2aNvdCJ YGyQ4IDdr/j3yFxHi9GD+tE+yMkkFfHeUUykwZwkG7eGjdqozJC/cKh6X5Im4W67BCxig qtD0CrAayPwnx6vnaX+TDS43ead+iPZc04HuDWKmpH8O0GYYBFDG492yQRsATSQQBzjR1 L7S/IIJVVdj/qsa6af+4a9SYlj6o6bz24/knfGuEW9PedHVU8Xc+Bfkr8sXRnkIsRRg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379549; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=RlAvg+cW57Zw6Zo9V2H09aA8w4VNGLVgGyImIXCblLE=; b=3gDCuMSRSkqtHmCRXcKDZNvgx/zcD2F4pHp/pUi/BmHFDnlSzMmb+C/mqWRDSO6g6CdA oerUYiLQLeE7prKWS9ZMx4TArbgOFhBHCx8BOPaHriQEn+3fOuhuuKtvIa79yL/+c7beJ VI1JEpNsZp+J5asgYpRfzENh9uBzRQwH9wXFC1e6eP2NMETC1ITK9c2x4gP0gtJn5uJsi 6hLDvm29XepDp3gh6MN0eTowO/izPrz4Jb66C44UHIUG2WUPx+uNWGsrHR4g9vZsp7jaf ICnrWa+Lb1jGL22Af8isPnhA+Mo3H8yf8AICCtAeGBm7IPqGzgvprjfnve0me1YAvtw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=DUAUviqj; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACD16606A322; Fri, 4 Dec 2026 10:19:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=DUAUviqj Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28E311F000C2; Fri, 4 Dec 2026 10:19:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379549; bh=RlAvg+cW57Zw6Zo9V2H09aA8w4VNGLVgGyImIXCblLE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DUAUviqj0Ua58Eht01CS8A3ieSlJX8La1Pvd+yORSlxbS/Hw8UQZTrvXlvROJQ/nI 2m/hyASPgUN2oUeEUWMGAOwABEZL8b6Rew0OiRMFm30DGFa6Qq0gJnDvT63hDeTIDP lIl6FpAiKiT9oJk779wi1/xUYJJ1v7tcWb9EELL4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?J=C3=A9r=C3=A9my=20Jean?= , Jens Axboe , Sasha Levin Subject: [PATCH 6.6 0033/1167] io_uring: fix task_work add use-after-free with SQPOLL Date: Fri, 4 Dec 2026 18:51:00 +0900 Message-ID: <20261204100702.906051076@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jens Axboe Commit a92193c91e8839fe5fc209616ea95465ae4b919d upstream. For SQPOLL, the sqpoll thread runs task_work off its own list and doesn't need to be told about it, so it can pop and complete a request as soon as mpscq_push() has published it. If that was the last request holding the ring alive, io_ring_exit_work() then frees the ctx, stops the thread, and with it the tctx, while io_req_normal_work_add() is still looking at both after the push: BUG: KASAN: slab-use-after-free in io_req_normal_work_add+0x439/0x510 Read of size 4 at addr ff11000000ca0000 by task repro/55 (...) BUG: KASAN: slab-use-after-free in queue_work_on+0x25/0x70 Write of size 8 at addr ff11000000c3bd00 by task repro/55 Hold an RCU read lock across the add, like io_req_local_work_add() already does, and have io_ring_exit_work() wait for a grace period for SQPOLL rings as well before freeing the ctx. Reported-by: Jérémy Jean Link: https://lore.kernel.org/io-uring/20260924205056.3759980-2-Jeremy.Jean@oss.cyber.gouv.fr/ Fixes: af5d68f8892f ("io_uring/sqpoll: manage task_work privately") Cc: stable@vger.kernel.org Signed-off-by: Jens Axboe [axboe: 6.6 has io_req_normal_work_add() in io_uring.c and adds with llist_add(), not mpscq_push()] Signed-off-by: Sasha Levin --- io_uring/io_uring.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 3108af4514eb2..fda288405e44f 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -1401,6 +1401,9 @@ static void io_req_normal_work_add(struct io_kiocb *req) struct io_uring_task *tctx = req->task->io_uring; struct io_ring_ctx *ctx = req->ctx; + /* SQPOLL can retire the request on push, see io_ring_exit_work() */ + guard(rcu)(); + /* task_work already pending, we're done */ if (!llist_add(&req->io_task_work.node, &tctx->task_list)) return; @@ -3369,8 +3372,8 @@ static __cold void io_ring_exit_work(struct work_struct *work) spin_lock(&ctx->completion_lock); spin_unlock(&ctx->completion_lock); - /* pairs with RCU read section in io_req_local_work_add() */ - if (ctx->flags & IORING_SETUP_DEFER_TASKRUN) + /* pairs with the RCU read sections in the task_work add paths */ + if (ctx->flags & (IORING_SETUP_DEFER_TASKRUN | IORING_SETUP_SQPOLL)) synchronize_rcu(); io_ring_ctx_free(ctx); -- 2.53.0