nvme: bound ns descriptor header and body to identify buffer
PATCH 2/2 nvme: clamp FDP nruhsd to allocated RUH status descriptor count
In reply to Greg Kroah-HartmanFrom: Hari Mishal <[email protected]>
nvme_query_fdp_info() allocates the RUH status buffer for at most S8_MAX
- 1 descriptors, and then copies ruhs->ruhsd[] into head->plids[] using the controller reported ruhs->nruhsd directly as the loop bound. However, that count wasn't taken into account for the actual buffer's size, so there was a chance for a controller reporting a larger nruhsd to cause the copy to overflow the buffer. Clamp nr_plids to the same bound used for the allocation.
--- drivers/nvme/host/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/core.c +1 -1
@@ -2361,7 +2361,7 @@ static int nvme_query_fdp_info(struct nvme_ns *ns, struct nvme_ns_info *info) goto free; } - head->nr_plids =le16_to_cpu (ruhs->nruhsd); + head->nr_plids =min (le16_to_cpu (ruhs->nruhsd),S8_MAX -1 );if (!head->nr_plids) goto free;
Signature · 1 line
2.55.0
PATCH 1/2 nvme: bound ns descriptor header and body to identify buffer
From: Hari Mishal <[email protected]>
nvme_identify_ns_descs() allocates a buffer and gives it to the controller, which populates it and then iterates the buffer with variable byte increments that vary by type and body size. But, there is no bounds check inside the iteration itself except the loop bound itself. Fix this by checking and stopping iteration if the next header or its declared body would go past the buffer itself.
--- drivers/nvme/host/core.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/nvme/host/core.c +4 -0
@@ -1583,8 +1583,12 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl,for (pos =0 ; pos <NVME_IDENTIFY_DATA_SIZE ; pos += len) {struct nvme_ns_id_desc *cur = data + pos; +if (pos +sizeof (*cur) >NVME_IDENTIFY_DATA_SIZE ) +break ;if (cur->nidl ==0 )break ; +if (pos +sizeof (*cur) + cur->nidl >NVME_IDENTIFY_DATA_SIZE ) +break ; len =nvme_process_ns_desc (ctrl, &info->ids, cur, &csi_seen);if (len <0 )
Signature · 1 line
2.55.0
Quoted 8 lines · Greg Kroah-Hartman
From: Hari Mishal <[email protected]>
nvme_identify_ns_descs()allocates a buffer and gives it to the controller, which populates it and then iterates the buffer with variable byte increments that vary by type and body size. But, there is no bounds check inside the iteration itself except the loop bound itself. Fix this by checking and stopping iteration if the next header or its declared body would go past the buffer itself.
Looks good:
Re: [PATCH 2/2] nvme: clamp FDP nruhsd to allocated RUH status descriptor count
In reply to Greg Kroah-HartmanLooks good:
Keith Busch
maintainerThanks, series applied to nvme-7.3.