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 v3 2/4] null_blk: reject device size overflow
Date: Mon, 30 Nov 2026 13:52:04 +0900 [thread overview]
Message-ID: <fc82b9a0-7a06-4a39-acaf-9a92b4c289c0@kernel.org> (raw)
In-Reply-To: <20261127125738.1654012-3-x-professor@outlook.com>
On 11/27/26 21:58, 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.
>
> In null_validate_conf(), convert the size to sectors with
> check_mul_overflow() and reject it if the conversion overflows or the
> result exceeds BLK_DEV_MAX_SECTORS. This happens before any device
> resources are allocated or zones are initialized. Only checking for the
> wrap would not be enough: set_capacity() truncates capacities above
> BLK_DEV_MAX_SECTORS, so null_blk would register a disk smaller than the
> configured size. 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>
Looks OK to me.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2026-11-30 4:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 12:57 [PATCH v3 0/4] null_blk: validate configfs values before power-on Yingjie Wang
2026-11-27 12:58 ` [PATCH v3 1/4] block: move BLK_DEV_MAX_SECTORS to <linux/blkdev.h> Yingjie Wang
2026-11-30 4:50 ` Damien Le Moal
2026-11-27 12:58 ` [PATCH v3 2/4] null_blk: reject device size overflow Yingjie Wang
2026-11-30 4:52 ` Damien Le Moal [this message]
2026-11-27 12:58 ` [PATCH v3 3/4] null_blk: reject zone counts that overflow unsigned int Yingjie Wang
2026-11-30 4:54 ` Damien Le Moal
2026-11-27 12:59 ` [PATCH v3 4/4] null_blk: validate the configfs home_node attribute Yingjie Wang
2026-11-30 4:54 ` Damien Le Moal
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=fc82b9a0-7a06-4a39-acaf-9a92b4c289c0@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