* [PATCH v2 0/3] null_blk: validate configfs values before power-on
@ 2026-11-26 7:47 Yingjie Wang
2026-11-26 7:47 ` [PATCH v2 1/3] null_blk: reject device size overflow Yingjie Wang
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Yingjie Wang @ 2026-11-26 7:47 UTC (permalink / raw)
To: axboe@kernel.dk
Cc: linux-block@vger.kernel.org, dlemoal@kernel.org,
stable@vger.kernel.org
This series fixes three bugs found while fuzzing null_blk's configfs
interface. Setting size or home_node to the values below and writing 1
to power triggers a crash:
1/3 size=2^44 MiB with zoned=1 wraps the byte capacity to zero.
The resulting zero zone count causes zone_nr_conv to underflow.
2/3 size=2^40 MiB with zoned=1 and the default 256 MiB zone size
requires 2^32 zones. Storing this count in nr_zones truncates
it to zero, leading to the same failure.
3/3 home_node=2147483647 is passed to kzalloc_node() without
validation, causing an out-of-bounds access in SLUB.
The zone count overflow still occurs with only patch 1 applied.
Testing used x86_64 with KASAN, CONFIG_NUMA=y, a two-node QEMU guest,
oops=panic panic_on_warn=1, and null_blk built as a module:
- The unpatched module crashes for all three cases above.
- With only patch 1 applied, the size=2^40 MiB zoned case still crashes.
- With the full series, writing 1 to power fails with EINVAL for all
three cases and leaves power at 0. Correcting the value and retrying
succeeds.
- Valid non-zoned devices were tested at 0, 1 and LLONG_MAX / SZ_1M MiB;
valid zoned devices were tested at 256, 257 and 512 MiB. Tests also
covered memory-backed read/write, zone reports and a conventional zone.
- home_node values NUMA_NO_NODE, 0 and 1 succeed. Values 2, 63, 64 and
2147483647 are rejected on power-on.
Testing was limited to x86_64. Sparse NUMA node numbering was not tested.
The reproducers are available on request.
---
Changes in v2:
- Add the missing Signed-off-by tags.
- State in each commit message that the bug was found by a fuzzer.
- No code changes.
v1: https://lore.kernel.org/linux-block/20261126063404.1051061-1-x-professor@outlook.com/
Yingjie Wang (3):
null_blk: reject device size overflow
null_blk: reject zone counts that overflow unsigned int
null_blk: validate the configfs home_node attribute
drivers/block/null_blk/main.c | 11 +++++++++++
drivers/block/null_blk/zoned.c | 8 +++++++-
2 files changed, 18 insertions(+), 1 deletion(-)
base-commit: 5a29cfaf51105039d156dd8a61d2783e8b653667
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/3] null_blk: reject device size overflow
2026-11-26 7:47 [PATCH v2 0/3] null_blk: validate configfs values before power-on Yingjie Wang
@ 2026-11-26 7:47 ` Yingjie Wang
2026-11-26 7:56 ` Damien Le Moal
2026-11-26 16:55 ` kernel test robot
2026-11-26 7:47 ` [PATCH v2 2/3] null_blk: reject zone counts that overflow unsigned int Yingjie Wang
2026-11-26 7:47 ` [PATCH v2 3/3] null_blk: validate the configfs home_node attribute Yingjie Wang
2 siblings, 2 replies; 7+ messages in thread
From: Yingjie Wang @ 2026-11-26 7:47 UTC (permalink / raw)
To: axboe@kernel.dk
Cc: linux-block@vger.kernel.org, dlemoal@kernel.org,
stable@vger.kernel.org
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
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;
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/3] null_blk: reject zone counts that overflow unsigned int
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:47 ` 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
2 siblings, 1 reply; 7+ messages in thread
From: Yingjie Wang @ 2026-11-26 7:47 UTC (permalink / raw)
To: axboe@kernel.dk
Cc: linux-block@vger.kernel.org, dlemoal@kernel.org,
stable@vger.kernel.org
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;
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);
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 3/3] null_blk: validate the configfs home_node attribute
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:47 ` [PATCH v2 2/3] null_blk: reject zone counts that overflow unsigned int Yingjie Wang
@ 2026-11-26 7:47 ` Yingjie Wang
2 siblings, 0 replies; 7+ messages in thread
From: Yingjie Wang @ 2026-11-26 7:47 UTC (permalink / raw)
To: axboe@kernel.dk
Cc: linux-block@vger.kernel.org, dlemoal@kernel.org,
stable@vger.kernel.org
The home_node module parameter is checked at module initialization, but
the configfs home_node attribute is stored without any validation.
Powering on the device then passes the value to kzalloc_node() and uses
it as the tag set NUMA node.
With CONFIG_NUMA enabled, writing 2147483647 to home_node and then 1 to
power makes SLUB use that node ID as an index into kmem_cache's
per_node[] array, causing an out-of-bounds read:
BUG: unable to handle page fault for address: ffff88880b042e80
#PF: supervisor read access in kernel mode
RIP: 0010:___slab_alloc+0x5ad/0x760
Call Trace:
__kmalloc_cache_node_noprof+0x2dc/0x600
null_add_dev+0x588/0x1e70 [null_blk]
nullb_device_power_store+0x29d/0x350 [null_blk]
configfs_write_iter+0x306/0x500
vfs_write+0x6a4/0x1030
ksys_write+0x12a/0x250
Reject home_node values other than NUMA_NO_NODE that do not name an
online node in null_validate_conf(), before any allocation uses the
value. Checking against nr_node_ids alone is not sufficient, because
node IDs below it need not be possible when node numbering is sparse.
This matches the validation done for the PCI numa_node sysfs attribute.
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 | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 2d6d71690d10..22c284748645 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1898,6 +1898,12 @@ static int null_validate_conf(struct nullb_device *dev)
return -EINVAL;
}
+ if (dev->home_node != NUMA_NO_NODE &&
+ (dev->home_node >= nr_node_ids || !node_online(dev->home_node))) {
+ pr_err("invalid home_node value\n");
+ return -EINVAL;
+ }
+
if (dev->queue_mode == NULL_Q_RQ) {
pr_err("legacy IO path is no longer available\n");
return -EINVAL;
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/3] null_blk: reject device size overflow
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 16:55 ` kernel test robot
1 sibling, 0 replies; 7+ messages in thread
From: Damien Le Moal @ 2026-11-26 7:56 UTC (permalink / raw)
To: Yingjie Wang, axboe@kernel.dk
Cc: linux-block@vger.kernel.org, stable@vger.kernel.org
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/3] null_blk: reject zone counts that overflow unsigned int
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
0 siblings, 0 replies; 7+ messages in thread
From: Damien Le Moal @ 2026-11-26 7:58 UTC (permalink / raw)
To: Yingjie Wang, axboe@kernel.dk
Cc: linux-block@vger.kernel.org, stable@vger.kernel.org
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/3] null_blk: reject device size overflow
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 16:55 ` kernel test robot
1 sibling, 0 replies; 7+ messages in thread
From: kernel test robot @ 2026-11-26 16:55 UTC (permalink / raw)
To: Yingjie Wang, axboe@kernel.dk
Cc: llvm, oe-kbuild-all, linux-block@vger.kernel.org,
dlemoal@kernel.org, stable@vger.kernel.org
Hi Yingjie,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 5a29cfaf51105039d156dd8a61d2783e8b653667]
url: https://github.com/intel-lab-lkp/linux/commits/Yingjie-Wang/null_blk-reject-device-size-overflow/20261126-074752
base: 5a29cfaf51105039d156dd8a61d2783e8b653667
patch link: https://lore.kernel.org/r/20261126074748.1076774-2-x-professor%40outlook.com
patch subject: [PATCH v2 1/3] null_blk: reject device size overflow
config: hexagon-allmodconfig (https://download.01.org/0day-ci/archive/20261127/20261127004636.Zw6bu9Dk-lkp@intel.com/config)
compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project fb29ca8163c3309160711e5a14eb46bc6d4fdad2)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261127/20261127004636.Zw6bu9Dk-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261127004636.Zw6bu9Dk-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> drivers/block/null_blk/main.c:1896:16: warning: result of comparison of constant 8796093022207 with expression of type 'unsigned long' is always false [-Wtautological-constant-out-of-range-compare]
1896 | if (dev->size > LLONG_MAX / SZ_1M) {
| ~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~
1 warning generated.
vim +1896 drivers/block/null_blk/main.c
1893
1894 static int null_validate_conf(struct nullb_device *dev)
1895 {
> 1896 if (dev->size > LLONG_MAX / SZ_1M) {
1897 pr_err("Device size is too large\n");
1898 return -EINVAL;
1899 }
1900
1901 if (dev->queue_mode == NULL_Q_RQ) {
1902 pr_err("legacy IO path is no longer available\n");
1903 return -EINVAL;
1904 }
1905 if (dev->queue_mode == NULL_Q_BIO) {
1906 pr_err("BIO-based IO path is no longer available, using blk-mq instead.\n");
1907 dev->queue_mode = NULL_Q_MQ;
1908 }
1909
1910 if (dev->use_per_node_hctx) {
1911 if (dev->submit_queues != nr_online_nodes)
1912 dev->submit_queues = nr_online_nodes;
1913 } else if (dev->submit_queues > nr_cpu_ids)
1914 dev->submit_queues = nr_cpu_ids;
1915 else if (dev->submit_queues == 0)
1916 dev->submit_queues = 1;
1917 dev->prev_submit_queues = dev->submit_queues;
1918
1919 if (dev->poll_queues > g_poll_queues)
1920 dev->poll_queues = g_poll_queues;
1921 dev->prev_poll_queues = dev->poll_queues;
1922 dev->irqmode = min_t(unsigned int, dev->irqmode, NULL_IRQ_TIMER);
1923
1924 /* Do memory allocation, so set blocking */
1925 if (dev->memory_backed)
1926 dev->blocking = true;
1927 else /* cache is meaningless */
1928 dev->cache_size = 0;
1929 dev->cache_size = min_t(unsigned long, ULONG_MAX / 1024 / 1024,
1930 dev->cache_size);
1931 dev->mbps = min_t(unsigned int, 1024 * 40, dev->mbps);
1932
1933 if (dev->zoned &&
1934 (!dev->zone_size || !is_power_of_2(dev->zone_size))) {
1935 pr_err("zone_size must be power-of-two\n");
1936 return -EINVAL;
1937 }
1938
1939 return 0;
1940 }
1941
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-26 16:55 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 16:55 ` kernel test robot
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox