Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] nvme: fix FDP configuration log parsing
@ 2026-05-26  7:52 liuxixin
  2026-05-26 14:41 ` Keith Busch
  0 siblings, 1 reply; 19+ messages in thread
From: liuxixin @ 2026-05-26  7:52 UTC (permalink / raw)
  To: linux-nvme; +Cc: kbusch, axboe, hch, sagi, linux-kernel

NUMFDPC in the FDP Configurations log (NVMe Base Specification, Figure 279)
is a 0-based count of configuration descriptors. Valid fdpcidx values are 0
through the NUMFDPC field value inclusive.

Fix the off-by-one check which incorrectly accepts fdpcidx == NUMFDPC+1.
Also validate descriptor sizes while walking the list so dsze == 0 or a
descriptor past the log end cannot cause unbounded iteration or reads past
the buffer.

Fixes: 30b5f20bb2ddab013035399e5c7e6577da49320a ("nvme: register fdp parameters with the block layer")

Signed-off-by: liuxixin <gliuxen@gmail.com>
---
 drivers/nvme/host/core.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index c3032d6ad..c5e77f5bc 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2231,7 +2231,8 @@ static int nvme_query_fdp_granularity(struct nvme_ctrl *ctrl,
 	struct nvme_fdp_config_desc *desc;
 	size_t size = sizeof(hdr);
 	void *log, *end;
-	int i, n, ret;
+	int i, ret;
+	u16 numfdpc;
 
 	ret = nvme_get_log_lsi(ctrl, 0, NVME_LOG_FDP_CONFIGS, 0,
 			       NVME_CSI_NVM, &hdr, size, 0, info->endgid);
@@ -2262,10 +2263,10 @@ static int nvme_query_fdp_granularity(struct nvme_ctrl *ctrl,
 		goto out;
 	}
 
-	n = le16_to_cpu(h->numfdpc) + 1;
-	if (fdp_idx > n) {
+	numfdpc = le16_to_cpu(h->numfdpc);
+	if (fdp_idx > numfdpc) {
 		dev_warn(ctrl->device, "FDP index:%d out of range:%d\n",
-			 fdp_idx, n);
+			 fdp_idx, numfdpc);
 		/* Proceed without registering FDP streams */
 		ret = 0;
 		goto out;
@@ -2275,7 +2276,15 @@ static int nvme_query_fdp_granularity(struct nvme_ctrl *ctrl,
 	desc = log;
 	end = log + size - sizeof(*h);
 	for (i = 0; i < fdp_idx; i++) {
-		log += le16_to_cpu(desc->dsze);
+		u16 dsze = le16_to_cpu(desc->dsze);
+
+		if (!dsze || log + dsze > end) {
+			dev_warn(ctrl->device,
+				 "FDP invalid config descriptor at index %d\n", i);
+			ret = 0;
+			goto out;
+		}
+		log += dsze;
 		desc = log;
 		if (log >= end) {
 			dev_warn(ctrl->device,
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2026-06-03  9:42 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-26  7:52 [PATCH v1 1/1] nvme: fix FDP configuration log parsing liuxixin
2026-05-26 14:41 ` Keith Busch
2026-05-27  2:22   ` [PATCH v2 0/1] " liuxixin
2026-05-27  2:29     ` [PATCH v2 1/1] " liuxixin
2026-05-27  8:53       ` Nitesh Shetty
2026-05-27 13:32       ` Christoph Hellwig
2026-05-28  1:01         ` [PATCH v3 0/2] " liuxixin
2026-05-28  1:43           ` [PATCH v3 1/2] nvme: fix FDP fdpcidx bounds check liuxixin
2026-05-28  8:30             ` Christoph Hellwig
2026-05-28  1:43           ` [PATCH v3 2/2] nvme: validate FDP configuration descriptor sizes liuxixin
2026-05-28  8:30             ` Christoph Hellwig
2026-05-28 10:00           ` [PATCH v4 0/2] nvme: fix FDP configuration log parsing liuxixin
2026-05-28 10:00             ` [PATCH v4 1/2] nvme: fix FDP fdpcidx bounds check liuxixin
2026-06-02 12:27               ` Keith Busch
2026-05-28 10:00             ` [PATCH v4 2/2] nvme: validate FDP configuration descriptor sizes liuxixin
2026-06-02 12:19               ` Keith Busch
2026-06-02 14:00                 ` [PATCH v5 0/1] " liuxixin
2026-06-02 14:00                   ` [PATCH v5 1/1] " liuxixin
2026-06-03  9:42                     ` Keith Busch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox