Skip to contentSkip to conversation

nvme-core: check for too small lba shift

PATCH In review Keith Busch 3 participants 3 messages Nov 28, 2023 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme-core: check for too small lba shift

From: Keith Busch <[email protected]>

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.

---
 drivers/nvme/host/core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +3 -2
index a55c2a774b9c4..1be1ce5228965 100644
@@ -1901,9 +1901,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);
 	}
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Keith Busch

From: Keith Busch <[email protected]>

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.

Signature · 1 line
Jens Axboe