From: Keith Busch Date: Tue, 28 Nov 2023 17:36:04 +0000 (-0800) Subject: nvme-core: check for too small lba shift X-Git-Tag: v6.6.14~708 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a4848c45a3f01d6af48ce0101b103fcb3f251ba1;p=platform%2Fkernel%2Flinux-starfive.git nvme-core: check for too small lba shift [ Upstream commit 74fbc88e161424b3b96a22b23a8e3e1edab9d05c ] The block layer doesn't support logical block sizes smaller than 512 bytes. The nvme spec doesn't support that small either, but the driver isn't checking to make sure the device responded with usable data. Failing to catch this will result in a kernel bug, either from a division by zero when stacking, or a zero length bio. Reviewed-by: Jens Axboe Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 2129913..ae234f3 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1893,9 +1893,10 @@ static void nvme_update_disk_info(struct gendisk *disk, /* * The block layer can't support LBA sizes larger than the page size - * yet, so catch this early and don't allow block I/O. + * or smaller than a sector size yet, so catch this early and don't + * allow block I/O. */ - if (ns->lba_shift > PAGE_SHIFT) { + if (ns->lba_shift > PAGE_SHIFT || ns->lba_shift < SECTOR_SHIFT) { capacity = 0; bs = (1 << 9); }