From mboxrd@z Thu Jan 1 00:00:00 1970 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: 8bit 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=LX8Owr8ej2ieQ@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@linux.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=y 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; - if (cur_nr_hw_queues >= new_nr_hw_queues) { - for (i = new_nr_hw_queues; i < cur_nr_hw_queues; i++) - __blk_mq_free_map_and_rqs(set, i); + if (cur_nr_hw_queues >= new_nr_hw_queues) return 0; - } new_tags = 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_mq_tag_set *set, { struct request_queue *q; LIST_HEAD(head); - int prev_nr_hw_queues; + int prev_nr_hw_queues = set->nr_hw_queues; + int i; lockdep_assert_held(&set->tag_list_lock); @@ -4831,7 +4828,6 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, blk_mq_sysfs_unregister_hctxs(q); } - prev_nr_hw_queues = 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, 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 = set->nr_hw_queues; i < prev_nr_hw_queues; i++) + __blk_mq_free_map_and_rqs(set, i); } void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int nr_hw_queues) -- 2.39.5