Root Cause
The warning in ___kmalloc_large_node() (mm/slub.c:5459) is caused by missing upper-bound validation on mddev->raid_disks in MD array configuration (drivers/md/md.c) and RAID10 configuration setup (drivers/md/raid10.c), allowing an oversized kmalloc() request (> KMALLOC_MAX_SIZE) to be issued when creating r10conf->r10bio_pool.
Detailed Mechanism
-
Unbounded mddev->raid_disks configuration (drivers/md/md.c):
- In
md_set_array_info() (reachable via md_ioctl() with SET_ARRAY_INFO -> __md_set_array_info()), when info->raid_disks != 0, mddev->raid_disks = info->raid_disks; is assigned directly without validating any upper bound (or checking against mddev->max_disks, which is only set to MD_SB_DISKS when mddev->persistent is true and remains 0 for non-persistent arrays).
- Similarly,
raid_disks_store() in sysfs writes mddev->raid_disks = n; without an upper bound check when !mddev->pers (and super_1_validate() assigns mddev->raid_disks = le32_to_cpu(sb->raid_disks) without checking against mddev->max_disks).
-
Allocation size exceeding KMALLOC_MAX_SIZE (drivers/md/raid10.c):
-
Additional notes on related paths:
- Note that
calc_r10bio_size() returns int rather than size_t (though in setup_conf(), conf->mirrors allocation fails kmalloc before raid_disks is large enough to overflow int).
- A similar pattern exists in
raid10_start_reshape() when mddev->delta_disks > 0 (create_r10bio_pool(new.raid_disks)), as well as in drivers/md/raid1.c (setup_conf() / raid1_reshape() sizing struct r1bio with bios[raid_disks * 2]) if mddev->raid_disks is not bounded.
Potential Fix Direction
Enforce a sensible upper limit on mddev->raid_disks (and raid_disks in md_set_array_info() / raid_disks_store() / super_1_validate()), and/or validate in raid10.c setup_conf() (and raid10_start_reshape()) that raid_disks and calc_r10bio_size(raid_disks) (using size_t / struct_size()) do not exceed KMALLOC_MAX_SIZE (or a RAID10 disk maximum) before calling kzalloc_objs() or create_r10bio_pool().