From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 73B81C55182 for ; Tue, 4 Aug 2026 02:19:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=xgBFJ13+HvDOtpSLu7rBgHIyQWNnRy/oUaMbPGIpA4w=; b=himp0EhHZm0TNycKvlStQF13ev alvjqAacaoZCKzZuq9NzYcmDN6Adou12LKcnpbun/4dQ2PBZKek4krqlLN87fr1JF7lLZYx5Y1qVw yw23zjkebux/pNGHW39W+XB36uS4YkoPLVG4ODVk0zIbCd4XjAkJ6hkyd0fR0vgB2U14Inb35vUZ3 aP5XPpchVkiyfcfLYioFWLfJn24MPnkaYzJ5CZjP7ToTsNgcQ/cagYUozhmUko73kx7Ak5kZjeBHR a/URSA0qz74Eba9I0PvByZuhEpq6fW0hMiwOUKRfzpL1N9fMfsWZ06A1LHcAZEetrAQSkaFgERTWa atutrXCQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wr4kT-00000000pOh-46Ku; Tue, 04 Aug 2026 02:19:21 +0000 Received: from out30-97.freemail.mail.aliyun.com ([115.124.30.97]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wr4kM-00000000pJH-4B1n for linux-nvme@lists.infradead.org; Tue, 04 Aug 2026 02:19:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1785809950; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=xgBFJ13+HvDOtpSLu7rBgHIyQWNnRy/oUaMbPGIpA4w=; b=SrPnBm7hXIwlKe2MluqLzN0fhebREO4499pcaSIRp/+DOO3sKan0QZy5UiE8JdW9iek5hcwRHtOMvZ+t6kBO4zGdvL9R2Zz2wi3SqWtmTrp/Z95MNIP99qvU35lJXDcgjW3bIQb0wy7+DyeRxls5+HpFTNMnk5WPPE1wpROdSII= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R411e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045133197;MF=kanie@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0X8MFvs1_1785809949; Received: from localhost(mailfrom:kanie@linux.alibaba.com fp:SMTPD_---0X8MFvs1_1785809949 cluster:ay36) by smtp.aliyun-inc.com; Tue, 04 Aug 2026 10:19:10 +0800 From: Guixin Liu To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke , nilay@linux.ibm.com, Chaitanya Kulkarni , Kanchan Joshi Cc: linux-nvme@lists.infradead.org Subject: [PATCH v3 4/5] nvme: clamp FDP placement handle count to the buffer size Date: Tue, 4 Aug 2026 10:19:00 +0800 Message-ID: <20260804021901.3777326-5-kanie@linux.alibaba.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260804021901.3777326-1-kanie@linux.alibaba.com> References: <20260804021901.3777326-1-kanie@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260803_191915_205065_D3EC7FA8 X-CRM114-Status: GOOD ( 11.07 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org nvme_query_fdp_info() allocates the RUH status buffer for at most S8_MAX - 1 descriptors and caps the io-mgmt-receive transfer to that size. head->nr_plids, however, is taken verbatim from the device-supplied nruhsd field, which can be up to 65535. If a non-conformant or malicious device reports more descriptors than the buffer holds, the copy loop reads past the end of the ruhs buffer (heap out-of-bounds read). Clamp nr_plids to the number of descriptors the buffer can actually hold. Fixes: 30b5f20bb2dd ("nvme: register fdp parameters with the block layer") Signed-off-by: Guixin Liu Reviewed-by: Hannes Reinecke Reviewed-by: Kanchan Joshi Reviewed-by: Christoph Hellwig Reviewed-by: Nilay Shroff --- drivers/nvme/host/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 453c1f0b2dd0..b1f444cd3daf 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2358,6 +2358,7 @@ static int nvme_query_fdp_info(struct nvme_ns *ns, struct nvme_ns_info *info) } head->nr_plids = le16_to_cpu(ruhs->nruhsd); + head->nr_plids = min_t(u16, head->nr_plids, S8_MAX - 1); if (!head->nr_plids) goto free; -- 2.43.7