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 1/3] null_blk: reject device size overflow
Date: Thu, 26 Nov 2026 16:56:09 +0900 [thread overview]
Message-ID: <fa532123-2fcf-4236-90c1-a47d5438502c@kernel.org> (raw)
In-Reply-To: <20261126074748.1076774-2-x-professor@outlook.com>
On 11/26/26 16:47, Yingjie Wang wrote:
> The configfs size attribute accepts an unsigned long value in MiB without
> checking whether it can be converted to bytes. Both null_add_dev() and
> mb_to_sects() multiply that value by SZ_1M before converting it to
> sectors, so on 64-bit systems a size of 2^44 MiB wraps the byte count to
> zero.
>
> For a zoned device with the default zone size, this also produces zero
> zones. The zero-length zone allocation returns ZERO_SIZE_PTR, and the
> conventional-zone adjustment underflows zone_nr_conv to UINT_MAX. The
> subsequent zone initialization then accesses invalid memory:
>
> null_blk: changed the number of conventional zones to 4294967295
> BUG: kernel NULL pointer dereference, address: 0000000000000030
> #PF: supervisor write access in kernel mode
> RIP: 0010:lockdep_init_map_type+0x1b/0x230
> Call Trace:
> __raw_spin_lock_init+0x3a/0x110
> null_init_zoned_dev+0x5a2/0x1270 [null_blk]
> null_add_dev+0x15f5/0x1e70 [null_blk]
> nullb_device_power_store+0x29d/0x350 [null_blk]
> configfs_write_iter+0x306/0x500
> vfs_write+0x6a4/0x1030
> ksys_write+0x12a/0x250
>
> Non-zoned devices can instead be registered with a wrapped capacity.
>
> Reject sizes above LLONG_MAX / SZ_1M in null_validate_conf(), before
Why not ULLONG_MAX / SZ_1M ?
Any particular reason?
> allocating device resources or initializing zones. This also keeps the
> byte capacity within the signed 64-bit range supported by the block
> layer. This check runs for both configfs power-on and module
> initialization.
>
> This bug was found by a fuzzer.
>
> Fixes: cedcafad8277 ("nullb: add interface to power on disk")
> Cc: stable@vger.kernel.org
> Signed-off-by: Yingjie Wang <x-professor@outlook.com>
> ---
> drivers/block/null_blk/main.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
> index ec0d7ba4d938..2d6d71690d10 100644
> --- a/drivers/block/null_blk/main.c
> +++ b/drivers/block/null_blk/main.c
> @@ -1893,6 +1893,11 @@ static int null_setup_tagset(struct nullb *nullb)
>
> static int null_validate_conf(struct nullb_device *dev)
> {
> + if (dev->size > LLONG_MAX / SZ_1M) {
> + pr_err("Device size is too large\n");
> + return -EINVAL;
> + }
> +
> if (dev->queue_mode == NULL_Q_RQ) {
> pr_err("legacy IO path is no longer available\n");
> return -EINVAL;
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2026-11-26 7:56 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 [this message]
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
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=fa532123-2fcf-4236-90c1-a47d5438502c@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