Skip to content

Commit 74fbc88

Browse files
committed
nvme-core: check for too small lba shift
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 <axboe@kernel.dk> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent d8b90d6 commit 74fbc88

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/nvme/host/core.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,9 +1901,10 @@ static void nvme_update_disk_info(struct gendisk *disk,
19011901

19021902
/*
19031903
* The block layer can't support LBA sizes larger than the page size
1904-
* yet, so catch this early and don't allow block I/O.
1904+
* or smaller than a sector size yet, so catch this early and don't
1905+
* allow block I/O.
19051906
*/
1906-
if (ns->lba_shift > PAGE_SHIFT) {
1907+
if (ns->lba_shift > PAGE_SHIFT || ns->lba_shift < SECTOR_SHIFT) {
19071908
capacity = 0;
19081909
bs = (1 << 9);
19091910
}

0 commit comments

Comments
 (0)