Commit dd9f3c62 authored by Keith Busch's avatar Keith Busch Committed by Baogen Shang
Browse files

nvme-core: check for too small lba shift

stable inclusion
from stable-v5.10.209
commit 06a33eec1dc28dfbcd62c1ff94a3229f3ee265bc
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I9J6AL
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-5.10.y&id=06a33eec1dc28dfbcd62c1ff94a3229f3ee265bc



-------------------------

[ 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: default avatarJens Axboe <axboe@kernel.dk>
Signed-off-by: default avatarKeith Busch <kbusch@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarBaogen Shang <baogen.shang@windriver.com>
parent 34c4be6c
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -2038,9 +2038,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);
	}