From nobody Thu Sep 24 18:39:53 2026 Received: from mail-pz2-f12.google.com (mail-pz2-f12.google.com [74.125.228.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2C7039182E for ; Mon, 21 Sep 2026 20:07:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790021256; cv=none; b=AUJ2Eccnc5ezLhQmYFUdXTDWf30BL6ETfFfD4CShLBVCHE0Fv1EMtshaUYlCVQb4PRBL/x/zctQGs4BCjuzRbZW4AMOppzJWQw4ShQndcEEMbm2KxldMhzDgqXuIGVzIVG7QJTaGHS4dHl/YpYlpfA/hgUESvPuuB2MsIqnOQAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790021256; c=relaxed/simple; bh=h8e53L5zdYtFd0pFE4MxiUgVtoMWZ7wr783X/OjPx4A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=koWsLW459wA5V6mGbgtgWQMfVhu/kdSVuykQh/u4vbjcvLpp/x2Luu8egIeYRMAGg4LX39Ksu8RdYBZGi2v3ThKt5W4Tr2CmzH5sYxmnEeprjdG5mjLvOTb2X0o4slsh1RM+PQzf/EeYMUMA7XPtApBoqUL5Yt9Sn/GT1AFc09Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com; spf=pass smtp.mailfrom=trailofbits.com; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b=f9L2KWat; arc=none smtp.client-ip=74.125.228.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b="f9L2KWat" Received: by mail-pz2-f12.google.com with SMTP id 41be03b00d2f7-cc4d2fe2056so2086189a12.2 for ; Mon, 21 Sep 2026 13:07:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trailofbits.com; s=google; t=1790021254; x=1790626054; 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=XupBU+OHDiEaB57xV6YrpzDidx9L2S107dqdUErPaGE=; b=f9L2KWatq4SfI0CM3hxcDFSyDkJJkdm09W7aviGTkaUrWVHiEST6tsWau5MpNQAHkG 4iTk7sBbzSYHVT8AVhjCuwif81ftW5/oXgcARMv5FIX4Idbus9m/7XVYX1mkwIPWdTJ5 ByNB/6fbzeCTPD2BwL1GSkxCdwnPc1DPcO6pawhqnb42gxWczDcRh6tcMBKRILLL2kLQ /srYF43qPkjGB+Aj3LmdFLYkvZAN+SJnAC5vqzn6BBEHWpKg/Pw5L/UoA5BVr1Zn0MYZ 73J08gD3xeLpQlCiAVCiC+jAyKvSrOFL84lgllb8IlfQgk7Jnn/jEH+0/v/Wc/VPNWeD xkAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790021254; x=1790626054; 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=XupBU+OHDiEaB57xV6YrpzDidx9L2S107dqdUErPaGE=; b=Z+nRX6kvN+eDQ3/lXQSwsWthb7IsiD/4KiW4W9TyxAeR8UXylBTUXRqTe0D+GO2zKA ntvAEZLddQoQh3ofSK0x54bvTJP6mYLiHYUPeRLVwxFuMscnm5EOWfJ8J3L2t8XuGssJ k4cSdOcDzESoS5xeFGnqgWd/LxlXsv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ac33 with SMTP id d9443c01a7336-2ddb1bbdf3cmr169683055ad.28.1790021253750; Mon, 21 Sep 2026 13:07:33 -0700 (PDT) Received: from localhost.localdomain ([2603:8001:5f01:8bab:289a:f600:f11e:a45c]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-33e5ebcdbe8sm501164eec.15.2026.09.21.13.07.32 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 21 Sep 2026 13:07:33 -0700 (PDT) From: Artem Dinaburg To: stable@vger.kernel.org Cc: Artem Dinaburg , Greg Kroah-Hartman , Sasha Levin , Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Chengming Zhou , Ming Lei , Yi Zhang , Hannes Reinecke Subject: [PATCH 6.1.y 1/2] blk-mq: fix tags leak when shrink nr_hw_queues Date: Mon, 21 Sep 2026 16:07:25 -0400 Message-ID: <20260921200728.84114-2-artem@trailofbits.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260921200728.84114-1-artem@trailofbits.com> References: <20260921200728.84114-1-artem@trailofbits.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Chengming Zhou [ Upstream commit e1dd7bc93029024af5688253b0c05181d6e01f8e ] Although we don't need to realloc set->tags[] when shrink nr_hw_queues, we need to free them. Or these tags will be leaked. How to reproduce: 1. mount -t configfs configfs /mnt 2. modprobe null_blk nr_devices=3D0 submit_queues=3D8 3. mkdir /mnt/nullb/nullb0 4. echo 1 > /mnt/nullb/nullb0/power 5. echo 4 > /mnt/nullb/nullb0/submit_queues 6. rmdir /mnt/nullb/nullb0 In step 4, will alloc 9 tags (8 submit queues and 1 poll queue), then in step 5, new_nr_hw_queues =3D 5 (4 submit queues and 1 poll queue). At last in step 6, only these 5 tags are freed, the other 4 tags leaked. Signed-off-by: Chengming Zhou Reviewed-by: Ming Lei Link: https://lore.kernel.org/r/20230821095602.70742-1-chengming.zhou@linux= .dev Signed-off-by: Jens Axboe [ Backport to 6.1.y: use this tree's cur_nr_hw_queues snapshot when freeing excess tag sets. ] Assisted-by: LLM Signed-off-by: Artem Dinaburg --- Stable submission note: patch 1/2 in the CVE-2023-54227 series for Linux 6.1.y. CVE: CVE-2023-54227 Build: This patch was included in the x86_64 allmodconfig and CONFIG_WERROR=3Dy build. It produced no new warnings or errors. block/blk-mq.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 8a9d9e3db1668a..b6215bee3d3c45 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -4509,9 +4509,13 @@ static int blk_mq_realloc_tag_set_tags(struct blk_mq= _tag_set *set, int cur_nr_hw_queues, int new_nr_hw_queues) { struct blk_mq_tags **new_tags; + int i; =20 - if (cur_nr_hw_queues >=3D new_nr_hw_queues) + if (cur_nr_hw_queues >=3D new_nr_hw_queues) { + for (i =3D new_nr_hw_queues; i < cur_nr_hw_queues; i++) + __blk_mq_free_map_and_rqs(set, i); return 0; + } =20 new_tags =3D kcalloc_node(new_nr_hw_queues, sizeof(struct blk_mq_tags *), GFP_KERNEL, set->numa_node); --=20 2.39.5 From nobody Thu Sep 24 18:39:53 2026 Received: from mail-pj2-f43.google.com (mail-pj2-f43.google.com [74.125.227.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDC742E738A for ; Mon, 21 Sep 2026 20:07:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790021257; cv=none; b=TsB+4by4XQA/8Zfnl0ASdd/dxobCIQvJ/6UJ2970nkUr1jpeKVAA9keJ9wSTLWcymXyNq7TH+wzru007eIteS/vQVEi8Tuy/5JlQGQfCwwZJq+y9L5VFZr/Z5ju0XB62gJpWHkJ+Pr1UH0HHMvTJAkF/IcMtl7AkyEAKni8YoZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790021257; c=relaxed/simple; bh=3vXE7lcQFe0Ihorih0Ly7xdqxebP2q99jKEPnxKX+mU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VvO7K7XGBEM1ySDvvXkJLb9ro5DQlUUcFxsSowZgqkiYZgOgJkGOseOK6BTau3I7yxdDNMIzmtegaziRtLgSAvVnDCd2NptfG3ZxX9nChjBNbK7Cq1MiqxylzBciqpohBHxKPnKja0Jqaj/Jxb/yLDnZUOO5l4eckClFnaiySQM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com; spf=pass smtp.mailfrom=trailofbits.com; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b=IVJ242w4; arc=none smtp.client-ip=74.125.227.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b="IVJ242w4" Received: by mail-pj2-f43.google.com with SMTP id 98e67ed59e1d1-39dacf053eeso2492574a91.2 for ; Mon, 21 Sep 2026 13:07:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trailofbits.com; s=google; t=1790021255; x=1790626055; 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=A4qzWgzNNZY14DzhBVqEY1Mje98vG/0yM0yF+Z9V/Bg=; b=IVJ242w4vD43Q/eF3sfcPGvWTylhHY0x9f6jsXVW9+Bv2ln0VBpM9oL7VvybLjb0rE WwfPdXEH4RmbDFWPl7reW0dDZf36FG9plKPJqGHtE/B8rUrDYWpycrY2q1BgOyMczjQ6 kVcSGcDr1Ug1VwoJz+7y+NRwNft9ZLVSW6xaVGxQw3GBhZoKEs5YwXGXGnzNpiwRxA9y hPJTGkNSBiD6X4LVBOOX2rIL2r13BisHGfOfv8GL3xrZVKpuJ4up/mT30b8xRoegpfLK LexCMlIyN2uQhDmxJRT+EuUd4CbkJY1txMkMdAt6K6HvS9JXKwFP2Uf3cNjORIFdJAra XOSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790021255; x=1790626055; 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=A4qzWgzNNZY14DzhBVqEY1Mje98vG/0yM0yF+Z9V/Bg=; b=ZyPrSdeJcO7Nc1PKtb3KTLOSSEXnfBBf+3AttBLoPxD+Q2ItlhfIAytNUXw6uXg9Qx NpTaosvzHnWa+TXl/vTgmbwlQgJtHMGhG3Xh+GCDpOs7q8xUfWzMjfzSrUoMXzmi/ywS 3oWcj7uheDKoQZOSQw+dNH5xjz2y8imudzGA7FiFXIuzMXcd1FD3Gdqz5h9n6QYdZ8eh ElZ5X2aYuCRjc2JsWiq5SNVRSKLc87pg4SH7jsISsbv6OQ71YppO3sDJikcAR5yv7d8R 0kc6RS8vA1TlxVkJBXZxmtWCFx8XTW3AYsJKMwxX329f4L9J6cPZdfxE9FF63nY8foQu FdNA== X-Forwarded-Encrypted: i=1; AKwUvByi7WfNqXcSjFlGkiiFPc8dZdQK+5DIjz+1cDeNMiH7u3zo+h8UzNfYw7ZPHXPeaoofNEJj0bxpdSvRzdE=@vger.kernel.org X-Gm-Message-State: AFuF++n27+MPIdQSGSX7cpRguDFG+94FbokaNwqvFN1XzkTbMg5D4R4O UuZAdeDeBPuvz/Uqaulajp9JPI++mR+tFv1uPQup6s6D5jRy4aK9C2bij+UGHgiIxOo= X-Gm-Gg: AYBFou3yEuPLlSrg1/p0/NlY3hDF5XIip5Zz305xhKeTc8yB6nuFvnYWI+b/hZnQx06 4e67OSrDy+owrgrJzfTxa6NIGwxgNQygh4uUoi2AB7a4ymY5HfAFHrggOCqABHJzbAr8AuZuMwC nh2sTXV+MAsrgX8ODSGi3WWNippQ74RPN44wtw36l8NzmdkbfSW813qN25V7aT1OA3VqIpOE74j VnJd7nFSmOX5H/3rWMruVekpj1UeSV1c8hUTrfG/+PxWyhaWUuOVnhCN+s1CdZ0dlCzyCXq3lXg ECv0emTk3WJSjU3FUYfrTg2QyT0xZCHlzvfcx2tV3LpaLTTRmnzMlq83KqrX4h1YMRyfyFSTKCs KCelxW5pzhwFV7klqKnm006aj88nQnQtRJXF/vP3tdp4YSAGu3oaYVH+BzElrez/98I1+00iQwh t/TGtUpfAhuGIrfGTmRgH2XjJ9c48TMUn5ojf/PEmS0a2/zH2Zwno4xMaj6xT77lZhLOSdUv+VP G/HPfC+IAepK7e2Im3TW+f9WKhwv9/7ST2b2vFyVgn80ecw+WOpM/gSdG5gKdE7MKVgK9qIN+FV XQmJmw== X-Received: by 2002:a17:90b:2649:b0:39e:3713:c2e4 with SMTP id 98e67ed59e1d1-39e54dce754mr19264623a91.14.1790021255157; Mon, 21 Sep 2026 13:07:35 -0700 (PDT) Received: from localhost.localdomain ([2603:8001:5f01:8bab:289a:f600:f11e:a45c]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-33e5ebcdbe8sm501164eec.15.2026.09.21.13.07.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 21 Sep 2026 13:07:34 -0700 (PDT) From: Artem Dinaburg To: stable@vger.kernel.org Cc: Artem Dinaburg , Greg Kroah-Hartman , Sasha Levin , Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Chengming Zhou , Ming Lei , Yi Zhang , Hannes Reinecke Subject: [PATCH 6.1.y 2/2] blk-mq: fix tags UAF when shrinking q->nr_hw_queues Date: Mon, 21 Sep 2026 16:07:26 -0400 Message-ID: <20260921200728.84114-3-artem@trailofbits.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260921200728.84114-1-artem@trailofbits.com> References: <20260921200728.84114-1-artem@trailofbits.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Chengming Zhou [ Upstream commit 6be6d112419713334ddd9c01f219ca16adaa4c76 ] When nr_hw_queues shrink, we free the excess tags before realloc'ing hw_ctxs for each queue. During that resize, we may need to access those tags, like blk_mq_tag_idle(hctx) will access queue shared tags. This can cause a slab use-after-free, as reported by KASAN. Fix it by moving the releasing of excess tags to the end. Fixes: e1dd7bc93029 ("blk-mq: fix tags leak when shrink nr_hw_queues") Reported-by: Yi Zhang Closes: https://lore.kernel.org/all/CAHj4cs_CK63uoDpGBGZ6DN4OCTpzkR3UaVgK= =3DLX8Owr8ej2ieQ@mail.gmail.com/ Cc: Ming Lei Signed-off-by: Chengming Zhou Reviewed-by: Hannes Reinecke Link: https://lore.kernel.org/r/20230908005702.2183908-1-chengming.zhou@lin= ux.dev Signed-off-by: Jens Axboe [ Backport to 6.1.y follow-up to e1dd7bc93029: move those frees after hctx resizing using cur_nr_hw_queues, preventing its tag UAF. ] Assisted-by: LLM Signed-off-by: Artem Dinaburg --- Stable submission note: patch 2/2 in the CVE-2023-54227 series for Linux 6.1.y. CVE: CVE-2023-54227 Build: This patch was included in the x86_64 allmodconfig and CONFIG_WERROR=3Dy build. It produced no new warnings or errors. block/blk-mq.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index b6215bee3d3c45..bf69079f6bd517 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -4509,13 +4509,9 @@ static int blk_mq_realloc_tag_set_tags(struct blk_mq= _tag_set *set, int cur_nr_hw_queues, int new_nr_hw_queues) { struct blk_mq_tags **new_tags; - int i; =20 - if (cur_nr_hw_queues >=3D new_nr_hw_queues) { - for (i =3D new_nr_hw_queues; i < cur_nr_hw_queues; i++) - __blk_mq_free_map_and_rqs(set, i); + if (cur_nr_hw_queues >=3D new_nr_hw_queues) return 0; - } =20 new_tags =3D kcalloc_node(new_nr_hw_queues, sizeof(struct blk_mq_tags *), GFP_KERNEL, set->numa_node); @@ -4804,7 +4800,8 @@ static void __blk_mq_update_nr_hw_queues(struct blk_m= q_tag_set *set, { struct request_queue *q; LIST_HEAD(head); - int prev_nr_hw_queues; + int prev_nr_hw_queues =3D set->nr_hw_queues; + int i; =20 lockdep_assert_held(&set->tag_list_lock); =20 @@ -4831,7 +4828,6 @@ static void __blk_mq_update_nr_hw_queues(struct blk_m= q_tag_set *set, blk_mq_sysfs_unregister_hctxs(q); } =20 - prev_nr_hw_queues =3D set->nr_hw_queues; if (blk_mq_realloc_tag_set_tags(set, set->nr_hw_queues, nr_hw_queues) < 0) goto reregister; @@ -4869,6 +4865,10 @@ static void __blk_mq_update_nr_hw_queues(struct blk_= mq_tag_set *set, =20 list_for_each_entry(q, &set->tag_list, tag_set_list) blk_mq_unfreeze_queue(q); + + /* Free the excess tags when nr_hw_queues shrink. */ + for (i =3D set->nr_hw_queues; i < prev_nr_hw_queues; i++) + __blk_mq_free_map_and_rqs(set, i); } =20 void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int nr_hw_queu= es) --=20 2.39.5