nvme-pci: fix mempool alloc size
authorKeith Busch <kbusch@kernel.org>
Mon, 19 Dec 2022 18:59:06 +0000 (10:59 -0800)
committerChristoph Hellwig <hch@lst.de>
Wed, 21 Dec 2022 08:17:25 +0000 (09:17 +0100)
commitc89a529e823d51dd23c7ec0c047c7a454a428541
treefa60419843f42cb3f3b7be7089a05c5c33240ad9
parentb5f96cb719d8ba220b565ddd3ba4ac0d8bcfb130
nvme-pci: fix mempool alloc size

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 <axboe@kernel.dk>
Fixes: 943e942e6266f ("nvme-pci: limit max IO size and segments to avoid high order allocations")
Signed-off-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Jens Axboe <axboe@kernel.dk>
Reviewed-by: Kanchan Joshi <joshi.k@samsung.com>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/host/pci.c