All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "YuanZhe Liu" <25031212351@stu.xidian.edu.cn>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb-storage: reject too small values in max_sectors_store()
Date: Mon, 16 Nov 2026 10:29:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-216736@kernel.org> (raw)
In-Reply-To: <20261116101604.42161-1-25031212351@stu.xidian.edu.cn>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb-storage: missing logical_block_size check in
  max_sectors_store()
--

commit 05440cadc022e6dcf9589e956d95f83a1aa8ca56
Author: YuanZhe Liu <25031212351@stu.xidian.edu.cn>

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

This commit rejects values below the page sector count in
max_sectors_store() before updating the request queue's max_hw_sectors
limit.

> diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
> index 97de28e855626..94131b726ade3 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;

[Severity: Medium]
Can max_sectors_store() still trigger a warning in blk_validate_limits()
when the device's logical_block_size is larger than a page?

block/blk-settings.c:blk_validate_limits() {
    ...
	if (WARN_ON_ONCE(lim->max_hw_sectors < PAGE_SECTORS))
		return -EINVAL;
	logical_block_sectors = lim->logical_block_size >> SECTOR_SHIFT;
	if (WARN_ON_ONCE(logical_block_sectors > lim->max_hw_sectors))
		return -EINVAL;
    ...
}

When transparent hugepages are enabled, sd_read_capacity() accepts
sector_size values up to 64 KiB via blk_validate_block_size().  On a 4 KiB
page system with a device reporting an 8 KiB to 64 KiB logical block size,
writing 8 to max_sectors passes the check added here and hits the second
warning in blk_validate_limits().

Checking that ms is at least lim.logical_block_size >> 9 after
queue_limits_start_update() (and calling queue_limits_cancel_update() on
failure) would avoid this warning as well.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116101604.42161-1-25031212351@stu.xidian.edu.cn?part=1

      reply	other threads:[~2026-11-16 10:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-216736@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=25031212351@stu.xidian.edu.cn \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.