Skip to content

Commit

Permalink
nvme-core: check for too small lba shift
Browse files Browse the repository at this point in the history
[ Upstream commit 74fbc88 ]

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 <[email protected]>
Signed-off-by: Keith Busch <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
keithbusch authored and gregkh committed Jan 20, 2024
1 parent 511f602 commit a4848c4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/nvme/host/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit a4848c4

Please sign in to comment.