From: Damien Le Moal <dlemoal@kernel.org>
To: ZHOU Jiaxiang <26066541r@connect.polyu.hk>, Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org,
"Martin K . Petersen" <mkp@kernel.org>,
linux-scsi@vger.kernel.org
Subject: Re: [PATCH 2/2] scsi: sd_zbc: reject disks with too many zones
Date: Fri, 11 Sep 2026 17:11:53 +0900 [thread overview]
Message-ID: <d6afb373-0e01-41e7-bc57-fb9cfc28600e@kernel.org> (raw)
In-Reply-To: <20260911041129.128280-3-26066541r@connect.polyu.hk>
On 9/11/26 13:11, ZHOU Jiaxiang wrote:
> sd_zbc_read_zones() computes the number of zones with 64-bit
> arithmetic and stores the result in the unsigned int nr_zones field
> of struct zoned_disk_info, silently truncating counts that exceed 32
> bits. The truncated count is later used to size per-zone resources,
> while the device may still report more zones than fit.
>
> Reject such devices at scan time: more than 4 billion zones is not
> realistic for any medium that exists today, and accepting the
> truncated count produces inconsistent zone bookkeeping.
>
> Signed-off-by: ZHOU Jiaxiang <26066541r@connect.polyu.hk>
> ---
> drivers/scsi/sd_zbc.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
> index 56e455fb5addd..446628cb3db02 100644
> --- a/drivers/scsi/sd_zbc.c
> +++ b/drivers/scsi/sd_zbc.c
> @@ -589,6 +589,7 @@ int sd_zbc_revalidate_zones(struct scsi_disk *sdkp)
> int sd_zbc_read_zones(struct scsi_disk *sdkp, struct queue_limits *lim,
> u8 buf[SD_BUF_SIZE])
> {
> + unsigned long long nr_zones64;
> unsigned int nr_zones;
Keep the name nr_zones and drop the unsigned int nr_zones variable, it is not
needed.
> u32 zone_blocks = 0;
> int ret;
> @@ -620,7 +621,15 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, struct queue_limits *lim,
> if (ret != 0)
> goto err;
>
> - nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks);
> + nr_zones64 = round_up(sdkp->capacity, zone_blocks) >>
> + ilog2(zone_blocks);
> + if (nr_zones64 > UINT_MAX) {
> + sd_printk(KERN_ERR, sdkp, "Too many zones (%llu)\n",
> + nr_zones64);
> + ret = -EINVAL;
> + goto err;
> + }
> + nr_zones = nr_zones64;
> sdkp->early_zone_info.nr_zones = nr_zones;
> sdkp->early_zone_info.zone_blocks = zone_blocks;
>
> --
> 2.34.1
>
> [https://www.polyu.edu.hk/emaildisclaimer/PolyU_Email_Signature-v2.jpg]
>
> Disclaimer:
>
> This message (including any attachments) contains confidential information intended for a specific individual and purpose. If you are not the intended recipient, you should delete this message and notify the sender and The Hong Kong Polytechnic University (the University) immediately. Any disclosure, copying, or distribution of this message, or the taking of any action based on it, is strictly prohibited and may be unlawful.
>
> The University specifically denies any responsibility for the accuracy or quality of information obtained through University E-mail Facilities. Any views and opinions expressed are only those of the author(s) and do not necessarily represent those of the University and the University accepts no liability whatsoever for any losses or damages incurred or caused to any party as a result of the use of such information.
--
Damien Le Moal
Western Digital Research
prev parent reply other threads:[~2026-09-11 8:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 4:11 [PATCH 0/2] block/scsi: fix zones_cond out-of-bounds write on zone report ZHOU Jiaxiang
2026-09-11 4:11 ` [PATCH 1/2] block: " ZHOU Jiaxiang
2026-09-11 8:13 ` Damien Le Moal
2026-09-11 4:11 ` [PATCH 2/2] scsi: sd_zbc: reject disks with too many zones ZHOU Jiaxiang
2026-09-11 8:11 ` Damien Le Moal [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=d6afb373-0e01-41e7-bc57-fb9cfc28600e@kernel.org \
--to=dlemoal@kernel.org \
--cc=26066541r@connect.polyu.hk \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox