]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nvme-core: check for too small lba shift
authorKeith Busch <kbusch@kernel.org>
Tue, 28 Nov 2023 17:36:04 +0000 (09:36 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 20 Jan 2024 10:50:04 +0000 (11:50 +0100)
[ 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 <axboe@kernel.dk>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/nvme/host/core.c

index 67c893934c806067cdaa2116c7b9cc7af06be0e2..0c088db944706663c43f69db92cc8776cb14ec6d 100644 (file)
@@ -1925,9 +1925,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);
        }