Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE23636197E for ; Sat, 3 Oct 2026 22:52:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791067955; cv=none; b=P8Wje4sTOOZI1Jj69rDI4zKsS82DPjXZ3m9ET0cYKbSbr4pDfucPR1fBHnTzbWmS7tbaVoiUv0zsCUQ7WjYIY+zw5c2VXg6vx3BLR/jn0LgkyH+K8XPi30ay390TFTE8s1YqcmmSnonYTXUc6F+VNfptkWjT4hREchtPH0beeAw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791067955; c=relaxed/simple; bh=2gG+DZQCNU1FjMDfS7+wDOf7eckSHFE7rxiZxDYU5pM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ve7qmoraYz0iM9VHNbk87KdgTR1mNnk0paoC+829A/Pt2bbJvTthauwwqCn/0XUtUBe22i7Bb00ldmcPmLD0B3BVQjcMUXbHtvBG647zAMdNymUTCq5iDMTWq/dK97txdrzZ3f/8zbC1TAUvSeKpepO1x8CklHDuMCjJz7WgyyA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b6JA1xwt; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b6JA1xwt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E7791F0089B; Sat, 3 Oct 2026 22:52:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1791067953; bh=0H1PTt1sdnecPFmzpQQWUkROLi962NefHEvCnwh8fYQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=b6JA1xwtCPq8hBtTELDpRIOUp4LaavLquSbfZDKTpbKT89MinXQHtqFkkj3DPfhLF PoAsVNEwSqaI20lWi+8vzsQjFbmDTUcMjq9BHyLpMYxOQGTu3M/yUoztmALUpj/ubq FGHrQQwp61ygRxVLJ+vFU7k4ImwWnc/dSONhdJioxsJYn0/gdYpeHYK/e7icSPSg3j c8uVgUmFkZU52nWXh++Gbf7Mb4f222EtBTGFbW8rNjlh3hTci2mQTjczFXXfvFyu/r oG8GixiMDbQyAQm+E02pdIL7XF25VXWY8PHU+/JL92TXULgrPyDDtw0QfI6oBGen8l 3dUvHgIMbcmWw== From: Sasha Levin To: stable@vger.kernel.org Cc: Jens Axboe , =?UTF-8?q?J=C3=A9r=C3=A9my=20Jean?= , Sasha Levin Subject: [PATCH 6.18.y] io_uring: fix task_work add use-after-free with SQPOLL Date: Sat, 3 Oct 2026 18:52:14 -0400 Message-ID: <20261003225129.513032-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026100333-unpicked-popsicle-044c@gregkh> References: <2026100333-unpicked-popsicle-044c@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Jens Axboe [ Upstream commit a92193c91e8839fe5fc209616ea95465ae4b919d ] 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 [ sashal: Relocated the task-work hunk to the existing io_req_normal_work_add() implementation. ] 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 fd64ba7a0927a..524669ee19982 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -1341,6 +1341,9 @@ static void io_req_normal_work_add(struct io_kiocb *req) struct io_uring_task *tctx = req->tctx; 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; @@ -3146,8 +3149,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