Skip to content

Commit 9141144

Browse files
keithbuschgregkh
authored andcommitted
nvme-pci: fix mempool alloc size
[ Upstream commit c89a529 ] Convert the max size to bytes to match the units of the divisor that calculates the worst-case number of PRP entries. The result is used to determine how many PRP Lists are required. The code was previously rounding this to 1 list, but we can require 2 in the worst case. In that scenario, the driver would corrupt memory beyond the size provided by the mempool. While unlikely to occur (you'd need a 4MB in exactly 127 phys segments on a queue that doesn't support SGLs), this memory corruption has been observed by kfence. Cc: Jens Axboe <[email protected]> Fixes: 943e942 ("nvme-pci: limit max IO size and segments to avoid high order allocations") Signed-off-by: Keith Busch <[email protected]> Reviewed-by: Jens Axboe <[email protected]> Reviewed-by: Kanchan Joshi <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent f17cf8f commit 9141144

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/nvme/host/pci.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ static bool nvme_dbbuf_update_and_check_event(u16 value, __le32 *dbbuf_db,
370370
*/
371371
static int nvme_pci_npages_prp(void)
372372
{
373-
unsigned nprps = DIV_ROUND_UP(NVME_MAX_KB_SZ + NVME_CTRL_PAGE_SIZE,
374-
NVME_CTRL_PAGE_SIZE);
373+
unsigned max_bytes = (NVME_MAX_KB_SZ * 1024) + NVME_CTRL_PAGE_SIZE;
374+
unsigned nprps = DIV_ROUND_UP(max_bytes, NVME_CTRL_PAGE_SIZE);
375375
return DIV_ROUND_UP(8 * nprps, PAGE_SIZE - 8);
376376
}
377377

0 commit comments

Comments
 (0)