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=1796385231; b=RCxGybbkT0S0uFy9xQkV3KgHXtDsKYP36Gsy4q/9ykORZVHDlqTz3T98eYLbhf8vTB76 S4S5SSkcwKvycHuYoZWqvYOnT3g7vAZKs3mgnD140+nJrQ278oHaVOszZc1e5xVPwzYQA Bcm+dTQHoEvY0o5fqtjgOJz7fbycsmV+3zUnsvHHFLytt/+VeVhdY9IVgmechfzVfLneN iWBFH9Ygnn+Rj2VGIhrR1ERvkhlBwu1/lMDhmlDUjUlgBAQAF2Prdizm0i0fSB29d3UiG UPd5ssm6vL3XkNZIo555DDmVK403ZIiSIJTReZhAIO2aZx/gRLxiMCvM1j3aERA+T1A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385231; 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-Transfer-Encoding; bh=asrFGsc0m4fjlNw3/IAjSt9Sw7SEf6mdisH+c9jEssw=; b=Kj43sgNnS3K6U8RmMF4S1UdzjjCMoMUDw4meHyKRuZAkj4OORSJnLRRIhd4G32b848O3 Ontlk/AANw4jRZoAN0N4UfmequvFkLgBbcZDS8hYcqC4v4AN4+Ry30xf2ZeuvonhEkZIz srdkeylb0HuLt856Hv6gYCu81ByE8r8frm6TWaXTbKdBrDY5CKmpFh2sSfOAwAVJh636o jYpb4ty6ql96b+4JLUTedK1TLgZDUidS9P0VLNz0q1OWgQTNpT6Bze1UmT2njrJFrQ6AS IpPhiq+Y7Fc1fa1Fkf5chiHrwfyLm5aqIH5XoKheS56nicY0qMAT1PCV4xsrZsPOlaw== 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=qCVtuHmA; 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 585B9606A32D; Fri, 4 Dec 2026 11:53:51 +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=qCVtuHmA Received: by smtp.kernel.org (Postfix) with ESMTPSA id 077F51F00897; Fri, 4 Dec 2026 11:53:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385230; bh=asrFGsc0m4fjlNw3/IAjSt9Sw7SEf6mdisH+c9jEssw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qCVtuHmAZfK2XJlWYpj9ba64yecAsMARmNjR4LMwGumKjgZMvVTj/HZBciXgby+cX HS34hmnQHZ/AEyu+AKPbsiSYnIMQ9A5EPMqF8w4MdSHcOV3PcG2XDcd2vWLQ0FFc2z rFJdyRLm6NLSR3pq3BZ6WaVZ4mQy8qXF2EcTtlV0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Josef Bacik , Christoph Hellwig , Jens Axboe , Sasha Levin Subject: [PATCH 6.6 0473/1167] blk-mq: dont trust the cookie in blk_mq_poll() Date: Fri, 4 Dec 2026 18:58:20 +0900 Message-ID: <20261204100714.342914024@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-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik [ Upstream commit 24974185999fd80b676fbe2a6c7a97bbd38aaf3a ] blk_mq_poll() indexes queue_hw_ctx[] with bio->bi_cookie unchecked. Zone write plugging keeps the segment count of a plugged write in __bi_nr_segments, which shares a union with the cookie, and clears REQ_POLLED, but bio_poll() only looks at the cookie. A plugged polled write with more segments than there are hardware queues reads past the array. The bio is also SLAB_TYPESAFE_BY_RCU, so a cookie from a bio reused for another device can meet the wrong array as well. Ignore a cookie that is out of range or doesn't name a poll queue. Fixes: 3e08773c3841 ("block: switch polling to be bio based") Fixes: dd291d77cc90 ("block: Introduce zone write plugging") Signed-off-by: Josef Bacik Reviewed-by: Christoph Hellwig Link: https://patch.msgid.link/20261028164415.1262013-28-axboe@kernel.dk Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-mq.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 72fd729ee9cd4..565c2c6082bb2 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -5071,8 +5071,15 @@ static int blk_hctx_poll(struct request_queue *q, struct blk_mq_hw_ctx *hctx, int blk_mq_poll(struct request_queue *q, blk_qc_t cookie, struct io_comp_batch *iob, unsigned int flags) { - struct blk_mq_hw_ctx *hctx = xa_load(&q->hctx_table, cookie); + struct blk_mq_hw_ctx *hctx; + /* + * The cookie is no more than a hint. iocb_bio_iopoll() may have read it + * from a bio that was reused for another queue right afterwards. + */ + hctx = xa_load(&q->hctx_table, cookie); + if (!hctx || hctx->type != HCTX_TYPE_POLL) + return 0; return blk_hctx_poll(q, hctx, iob, flags); } -- 2.53.0