linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Guixin Liu <kanie@linux.alibaba.com>
To: Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@kernel.dk>,
	Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
	Hannes Reinecke <hare@suse.de>,
	Nilay Shroff <nilay@linux.ibm.com>,
	Chaitanya Kulkarni <kch@nvidia.com>
Cc: linux-nvme@lists.infradead.org
Subject: [PATCH 4/4] nvme: clamp FDP placement handle count to the buffer size
Date: Thu, 30 Jul 2026 12:31:05 +0800	[thread overview]
Message-ID: <20260730043105.3071328-5-kanie@linux.alibaba.com> (raw)
In-Reply-To: <20260730043105.3071328-1-kanie@linux.alibaba.com>

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 <kanie@linux.alibaba.com>
---
 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



  parent reply	other threads:[~2026-07-30  4:31 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30  4:31 [PATCH 0/4] nvme: a few error-path and validation fixes Guixin Liu
2026-07-30  4:31 ` [PATCH 1/4] nvmet: fix NULL pointer dereference in nvmet_execute_identify_nslist() Guixin Liu
2026-07-30  8:22   ` Hannes Reinecke
2026-07-30 11:34   ` Christoph Hellwig
2026-07-31  1:57     ` Guixin Liu
2026-07-30 12:06   ` Nilay Shroff
2026-07-30  4:31 ` [PATCH 2/4] nvmet: propagate percpu_ref_init() failure in nvmet_ns_enable() Guixin Liu
2026-07-30  8:23   ` Hannes Reinecke
2026-07-30 11:38   ` Christoph Hellwig
2026-07-30 12:06   ` Nilay Shroff
2026-07-30  4:31 ` [PATCH 3/4] nvme-pci: release descriptor pools on probe failure Guixin Liu
2026-07-30  8:23   ` Hannes Reinecke
2026-07-30 11:34   ` Christoph Hellwig
2026-07-30 11:49   ` Kanchan Joshi
2026-07-30 12:07   ` Nilay Shroff
2026-07-30  4:31 ` Guixin Liu [this message]
2026-07-30  8:24   ` [PATCH 4/4] nvme: clamp FDP placement handle count to the buffer size Hannes Reinecke
2026-07-30  9:40   ` Kanchan Joshi
2026-07-30 11:37     ` Christoph Hellwig
2026-07-30 12:41       ` Keith Busch
2026-07-31  2:00         ` Guixin Liu
2026-07-30 11:36   ` Christoph Hellwig
2026-07-30 12:08   ` Nilay Shroff

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260730043105.3071328-5-kanie@linux.alibaba.com \
    --to=kanie@linux.alibaba.com \
    --cc=axboe@kernel.dk \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=kch@nvidia.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=nilay@linux.ibm.com \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).