From: Damien Le Moal <dlemoal@kernel.org>
To: Yingjie Wang <x-professor@outlook.com>,
"axboe@kernel.dk" <axboe@kernel.dk>
Cc: "linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH v2 2/3] null_blk: reject zone counts that overflow unsigned int
Date: Thu, 26 Nov 2026 16:58:06 +0900 [thread overview]
Message-ID: <e8817800-21d7-43c3-954a-7a4814039f93@kernel.org> (raw)
In-Reply-To: <20261126074748.1076774-3-x-professor@outlook.com>
On 11/26/26 16:47, Yingjie Wang wrote:
> null_init_zoned_dev() calculates the zone count from sector_t values but
> stores it in the unsigned int nr_zones field without checking the range.
> For example, a size of 2^40 MiB with the default 256 MiB zone size
> requires 2^32 zones. This count is truncated to zero when stored in
> nr_zones.
>
> The resulting zero-length allocation returns ZERO_SIZE_PTR. Adjusting the
> number of conventional zones then underflows zone_nr_conv to UINT_MAX,
> and initializing those zones accesses invalid memory. This happens even
> when the device capacity itself fits in a signed 64-bit byte count.
>
> Keep the calculated zone count in a sector_t temporary and reject values
> above UINT_MAX before assigning nr_zones or allocating the zone array.
>
> This bug was found by a fuzzer.
>
> Fixes: ca4b2a011948 ("null_blk: add zone support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Yingjie Wang <x-professor@outlook.com>
> ---
> drivers/block/null_blk/zoned.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c
> index b271d0a88ff2..432a0a2f3893 100644
> --- a/drivers/block/null_blk/zoned.c
> +++ b/drivers/block/null_blk/zoned.c
> @@ -54,6 +54,7 @@ int null_init_zoned_dev(struct nullb_device *dev,
> struct queue_limits *lim)
> {
> sector_t dev_capacity_sects, zone_capacity_sects;
> + sector_t nr_zones;
Please use unsigned long long here. sector_t is for, well, sectors :)
Other than this, looks OK to me.
> struct nullb_zone *zone;
> sector_t sector = 0;
> unsigned int i;
> @@ -94,8 +95,13 @@ int null_init_zoned_dev(struct nullb_device *dev,
> pr_err("zone_size too large or too small, leads to zero sectors\n");
> return -EINVAL;
> }
> - dev->nr_zones = round_up(dev_capacity_sects, dev->zone_size_sects)
> + nr_zones = round_up(dev_capacity_sects, dev->zone_size_sects)
> >> ilog2(dev->zone_size_sects);
> + if (nr_zones > UINT_MAX) {
> + pr_err("Too many zones\n");
> + return -EINVAL;
> + }
> + dev->nr_zones = nr_zones;
>
> dev->zones = kvmalloc_objs(struct nullb_zone, dev->nr_zones,
> GFP_KERNEL | __GFP_ZERO);
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2026-11-26 7:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 7:47 [PATCH v2 0/3] null_blk: validate configfs values before power-on Yingjie Wang
2026-11-26 7:47 ` [PATCH v2 1/3] null_blk: reject device size overflow Yingjie Wang
2026-11-26 7:56 ` Damien Le Moal
2026-11-26 7:47 ` [PATCH v2 2/3] null_blk: reject zone counts that overflow unsigned int Yingjie Wang
2026-11-26 7:58 ` Damien Le Moal [this message]
2026-11-26 7:47 ` [PATCH v2 3/3] null_blk: validate the configfs home_node attribute Yingjie Wang
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=e8817800-21d7-43c3-954a-7a4814039f93@kernel.org \
--to=dlemoal@kernel.org \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=x-professor@outlook.com \
/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