* [PATCH v4 1/4] block: move BLK_DEV_MAX_SECTORS to <linux/blkdev.h>
[not found] <20261201140157.345892-1-x-professor@outlook.com>
@ 2026-12-01 14:02 ` Yingjie Wang
2026-12-02 5:51 ` Damien Le Moal
2026-12-01 14:02 ` [PATCH v4 2/4] null_blk: reject device size overflow Yingjie Wang
` (2 subsequent siblings)
3 siblings, 1 reply; 5+ messages in thread
From: Yingjie Wang @ 2026-12-01 14:02 UTC (permalink / raw)
To: axboe@kernel.dk
Cc: linux-block@vger.kernel.org, Damien Le Moal,
stable@vger.kernel.org
BLK_DEV_MAX_SECTORS is the largest disk capacity the block layer
supports: set_capacity() truncates larger capacities and add_disk()
rejects them. It is defined in block/blk.h, so drivers cannot use it to
validate a capacity they get from the user before calling
set_capacity().
Move it to <linux/blkdev.h>, using SECTOR_SHIFT instead of 9 while at
it. The next patch uses it in null_blk to reject a configured device
size that is too large. No functional change.
Cc: stable@vger.kernel.org # 6.14.x
Signed-off-by: Yingjie Wang <x-professor@outlook.com>
---
block/blk.h | 1 -
include/linux/blkdev.h | 6 ++++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/block/blk.h b/block/blk.h
index 105fff157bfb..13fa24aa05ea 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -23,7 +23,6 @@ struct elv_change_ctx;
*/
#define BLK_DEF_MAX_SECTORS_CAP (SZ_4M >> SECTOR_SHIFT)
-#define BLK_DEV_MAX_SECTORS (LLONG_MAX >> 9)
#define BLK_MIN_SEGMENT_SIZE 4096
/* Max future timer expiry for timeouts */
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 215753171cef..1786fddd00ac 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -834,6 +834,12 @@ static inline bool bdev_read_only(struct block_device *bdev)
return bdev_test_flag(bdev, BD_READ_ONLY) || get_disk_ro(bdev->bd_disk);
}
+/*
+ * Largest supported disk capacity in sectors: the capacity in bytes must fit
+ * in a loff_t.
+ */
+#define BLK_DEV_MAX_SECTORS (LLONG_MAX >> SECTOR_SHIFT)
+
bool set_capacity_and_notify(struct gendisk *disk, sector_t size);
void disk_force_media_change(struct gendisk *disk);
void bdev_mark_dead(struct block_device *bdev, bool surprise);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v4 1/4] block: move BLK_DEV_MAX_SECTORS to <linux/blkdev.h>
2026-12-01 14:02 ` [PATCH v4 1/4] block: move BLK_DEV_MAX_SECTORS to <linux/blkdev.h> Yingjie Wang
@ 2026-12-02 5:51 ` Damien Le Moal
0 siblings, 0 replies; 5+ messages in thread
From: Damien Le Moal @ 2026-12-02 5:51 UTC (permalink / raw)
To: Yingjie Wang, axboe@kernel.dk
Cc: linux-block@vger.kernel.org, stable@vger.kernel.org
On 12/1/26 23:02, Yingjie Wang wrote:
> BLK_DEV_MAX_SECTORS is the largest disk capacity the block layer
> supports: set_capacity() truncates larger capacities and add_disk()
> rejects them. It is defined in block/blk.h, so drivers cannot use it to
> validate a capacity they get from the user before calling
> set_capacity().
>
> Move it to <linux/blkdev.h>, using SECTOR_SHIFT instead of 9 while at
> it. The next patch uses it in null_blk to reject a configured device
> size that is too large. No functional change.
>
> Cc: stable@vger.kernel.org # 6.14.x
> Signed-off-by: Yingjie Wang <x-professor@outlook.com>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 2/4] null_blk: reject device size overflow
[not found] <20261201140157.345892-1-x-professor@outlook.com>
2026-12-01 14:02 ` [PATCH v4 1/4] block: move BLK_DEV_MAX_SECTORS to <linux/blkdev.h> Yingjie Wang
@ 2026-12-01 14:02 ` Yingjie Wang
2026-12-01 14:02 ` [PATCH v4 3/4] null_blk: reject zone counts that overflow unsigned int Yingjie Wang
2026-12-01 14:02 ` [PATCH v4 4/4] null_blk: validate the configfs home_node attribute Yingjie Wang
3 siblings, 0 replies; 5+ messages in thread
From: Yingjie Wang @ 2026-12-01 14:02 UTC (permalink / raw)
To: axboe@kernel.dk
Cc: linux-block@vger.kernel.org, Damien Le Moal,
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.
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>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
---
drivers/block/null_blk/main.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index ec0d7ba4d938..eb7617fd0964 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1893,6 +1893,15 @@ static int null_setup_tagset(struct nullb *nullb)
static int null_validate_conf(struct nullb_device *dev)
{
+ sector_t nr_sectors;
+
+ if (check_mul_overflow((sector_t)dev->size,
+ (sector_t)(SZ_1M >> SECTOR_SHIFT), &nr_sectors) ||
+ nr_sectors > BLK_DEV_MAX_SECTORS) {
+ 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;
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v4 3/4] null_blk: reject zone counts that overflow unsigned int
[not found] <20261201140157.345892-1-x-professor@outlook.com>
2026-12-01 14:02 ` [PATCH v4 1/4] block: move BLK_DEV_MAX_SECTORS to <linux/blkdev.h> Yingjie Wang
2026-12-01 14:02 ` [PATCH v4 2/4] null_blk: reject device size overflow Yingjie Wang
@ 2026-12-01 14:02 ` Yingjie Wang
2026-12-01 14:02 ` [PATCH v4 4/4] null_blk: validate the configfs home_node attribute Yingjie Wang
3 siblings, 0 replies; 5+ messages in thread
From: Yingjie Wang @ 2026-12-01 14:02 UTC (permalink / raw)
To: axboe@kernel.dk
Cc: linux-block@vger.kernel.org, Damien Le Moal,
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 an unsigned long long 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>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
---
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..28689f15a01a 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;
+ unsigned long long 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);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v4 4/4] null_blk: validate the configfs home_node attribute
[not found] <20261201140157.345892-1-x-professor@outlook.com>
` (2 preceding siblings ...)
2026-12-01 14:02 ` [PATCH v4 3/4] null_blk: reject zone counts that overflow unsigned int Yingjie Wang
@ 2026-12-01 14:02 ` Yingjie Wang
3 siblings, 0 replies; 5+ messages in thread
From: Yingjie Wang @ 2026-12-01 14:02 UTC (permalink / raw)
To: axboe@kernel.dk
Cc: linux-block@vger.kernel.org, Damien Le Moal,
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>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
---
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 eb7617fd0964..726c8c58aff4 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1902,6 +1902,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;
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread