* [PATCH v2] usb-storage: reject too small values in max_sectors_store()
@ 2026-11-16 16:39 YuanZhe Liu
2026-11-16 16:44 ` sashiko-bot
2026-11-16 18:39 ` [usb-storage] " Alan Stern
0 siblings, 2 replies; 3+ messages in thread
From: YuanZhe Liu @ 2026-11-16 16:39 UTC (permalink / raw)
To: Alan Stern
Cc: Greg Kroah-Hartman, linux-usb, usb-storage, linux-kernel, stable,
Bin Yu, Cheng Wen
Writing a value that is smaller than a page worth of sectors, or
smaller than one logical block, 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 at least one
logical block, 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 such values with -EINVAL on the limits snapshot returned by
queue_limits_start_update(), cancelling the update. This keeps the
return value for values below a page 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. Checking the logical block size as
well covers devices that report a block size larger than a page, where
a value above PAGE_SECTORS can still be smaller than one logical block.
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>
---
Changes in v2:
- Also reject values below one logical block and cancel the limits
update; with a device reporting a logical block size larger than a
page, such a value reaches the second WARN_ON_ONCE() in
blk_validate_limits().
---
drivers/usb/storage/scsiglue.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 97de28e85562..7a55cfc18236 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -593,6 +593,10 @@ static ssize_t max_sectors_store(struct device *dev, struct device_attribute *at
return -EINVAL;
lim = queue_limits_start_update(sdev->request_queue);
+ if (ms < PAGE_SECTORS || ms < lim.logical_block_size >> SECTOR_SHIFT) {
+ queue_limits_cancel_update(sdev->request_queue);
+ return -EINVAL;
+ }
lim.max_hw_sectors = ms;
ret = queue_limits_commit_update_frozen(sdev->request_queue, &lim);
if (ret)
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] usb-storage: reject too small values in max_sectors_store()
2026-11-16 16:39 [PATCH v2] usb-storage: reject too small values in max_sectors_store() YuanZhe Liu
@ 2026-11-16 16:44 ` sashiko-bot
2026-11-16 18:39 ` [usb-storage] " Alan Stern
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-16 16:44 UTC (permalink / raw)
To: YuanZhe Liu; +Cc: linux-usb
> Writing a value that is smaller than a page worth of sectors, or
> smaller than one logical block, 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 at least one
> logical block, 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
>
> [ ... ]
> 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>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116163946.2502-1-25031212351@stu.xidian.edu.cn?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [usb-storage] [PATCH v2] usb-storage: reject too small values in max_sectors_store()
2026-11-16 16:39 [PATCH v2] usb-storage: reject too small values in max_sectors_store() YuanZhe Liu
2026-11-16 16:44 ` sashiko-bot
@ 2026-11-16 18:39 ` Alan Stern
1 sibling, 0 replies; 3+ messages in thread
From: Alan Stern @ 2026-11-16 18:39 UTC (permalink / raw)
To: YuanZhe Liu
Cc: Greg Kroah-Hartman, linux-usb, usb-storage, linux-kernel, stable,
Bin Yu, Cheng Wen
On Tue, Nov 17, 2026 at 12:39:46AM +0800, 'YuanZhe Liu' via USB Mass Storage on Linux wrote:
> Writing a value that is smaller than a page worth of sectors, or
> smaller than one logical block, 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 at least one
> logical block, 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 such values with -EINVAL on the limits snapshot returned by
> queue_limits_start_update(), cancelling the update. This keeps the
> return value for values below a page 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. Checking the logical block size as
> well covers devices that report a block size larger than a page, where
> a value above PAGE_SECTORS can still be smaller than one logical block.
>
> 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>
> ---
> Changes in v2:
> - Also reject values below one logical block and cancel the limits
> update; with a device reporting a logical block size larger than a
> page, such a value reaches the second WARN_ON_ONCE() in
> blk_validate_limits().
> ---
Acked-by: Alan Stern <stern@rowland.harvard.edu>
> drivers/usb/storage/scsiglue.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
> index 97de28e85562..7a55cfc18236 100644
> --- a/drivers/usb/storage/scsiglue.c
> +++ b/drivers/usb/storage/scsiglue.c
> @@ -593,6 +593,10 @@ static ssize_t max_sectors_store(struct device *dev, struct device_attribute *at
> return -EINVAL;
>
> lim = queue_limits_start_update(sdev->request_queue);
> + if (ms < PAGE_SECTORS || ms < lim.logical_block_size >> SECTOR_SHIFT) {
> + queue_limits_cancel_update(sdev->request_queue);
> + return -EINVAL;
> + }
> lim.max_hw_sectors = ms;
> ret = queue_limits_commit_update_frozen(sdev->request_queue, &lim);
> if (ret)
> --
> 2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-16 18:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 16:39 [PATCH v2] usb-storage: reject too small values in max_sectors_store() YuanZhe Liu
2026-11-16 16:44 ` sashiko-bot
2026-11-16 18:39 ` [usb-storage] " Alan Stern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox