[PATCH] usb-storage: reject too small values in max_sectors_store()

From: YuanZhe Liu

Date: Mon Nov 16 2026 - 05:16:27 EST


Writing a value smaller than a page worth of sectors to
/sys/class/scsi_device/.../device/max_sectors passes an invalid
max_hw_sectors to queue_limits_commit_update_frozen(). The block layer
requires max_hw_sectors to cover at least one page and treats a smaller
value as a driver bug:

WARNING: block/blk-settings.c:389 at blk_validate_limits+0xeb9/0x14b0
Call Trace:
queue_limits_commit_update
queue_limits_commit_update_frozen
max_sectors_store
dev_attr_store
sysfs_kf_write

Before commit 70a7949335e5 ("scsi: usb-storage: Switch to using
->device_configure") the store called blk_queue_max_hw_sectors(), which
silently raised values below PAGE_SECTORS to that minimum. The
conversion to the queue_limits API lost the clamping, so a single sysfs
write from user space can now trigger the warning.

Reject values below PAGE_SECTORS with -EINVAL before taking the limits
lock. This keeps the return value for 1..7 unchanged, as the block
layer already returned -EINVAL for them, and also rejects zero, which
blk_validate_limits() would otherwise replace with BLK_SAFE_MAX_SECTORS
without the user asking for it.

Fixes: 70a7949335e5 ("scsi: usb-storage: Switch to using ->device_configure")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
---
drivers/usb/storage/scsiglue.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 97de28e85562..94131b726ade 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -591,6 +591,8 @@ static ssize_t max_sectors_store(struct device *dev, struct device_attribute *at

if (sscanf(buf, "%hu", &ms) <= 0)
return -EINVAL;
+ if (ms < PAGE_SECTORS)
+ return -EINVAL;

lim = queue_limits_start_update(sdev->request_queue);
lim.max_hw_sectors = ms;
--
2.34.1