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 --- 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