Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb-storage: reject too small values in max_sectors_store()
@ 2026-11-16 10:16 YuanZhe Liu
  2026-11-16 10:29 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: YuanZhe Liu @ 2026-11-16 10:16 UTC (permalink / raw)
  To: Alan Stern
  Cc: Greg Kroah-Hartman, linux-usb, usb-storage, linux-kernel, stable,
	Bin Yu, Cheng Wen

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@vger.kernel.org
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-16 10:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 10:16 [PATCH] usb-storage: reject too small values in max_sectors_store() YuanZhe Liu
2026-11-16 10:29 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox