CVE-2026-138869: md: don't hand out the array before md_alloc() has added mddev->kobj
In the Linux kernel, the following vulnerability has been resolved:
md: don't hand out the array before mdalloc() has added mddev->kobj
mdalloc() publishes the gendisk before it is done setting the mddev up:
disk->privatedata = mddev; ... error = adddisk(disk); if (error) goto outputdisk;
kobjectinit(&mddev->kobj, &mdktype); error = kobjectadd(&mddev->kobj, &disktodev(disk)->kobj, "%s", "md");
adddisk() makes /dev/mdN openable. mddev comes from mddevalloc() and is zeroed, so anything that gets in between adddisk() and kobjectadd() sees an mddev->kobj that has never been through kobjectinit() - no ktype, no kref, stateinitialized clear.
syzbot opens the array in that window and issues ADDNEWDISK:
kobject: '(null)' (ffff8880120640f0): is not initialized, yet kobjectget() is being called. WARNING: lib/kobject.c:642 at kobjectaddinternal+0xea/0xcd0 lib/kobject.c:225 kobjectaddvarg lib/kobject.c:374 [inline] kobjectadd+0x163/0x240 lib/kobject.c:426 bindrdevtoarray+0x80c/0xdd0 drivers/md/md.c:2621 mdaddnewdisk+0xe3b/0x1850 drivers/md/md.c:7684 mdioctl+0x200a/0x2610 drivers/md/md.c:8499
bindrdevtoarray() is not the only way in. mdrun() calls sysfscreategroup(&mddev->kobj, &mdredundancygroup), and internalcreategroup() has its own WARNON(!kobj->sd), so RUNARRAY in the same window warns too.
Every ioctl that can reach mddev->kobj runs under reconfigmutex, so hold it across adddisk() and kobjectadd(). An ioctl issued in the window now waits for mdalloc() to finish instead of seeing a half-built mddev, and opening the array still succeeds. The ioctls mdioctl() serves without the mutex only read array state and return -ENODEV on an array with no disks.
Hoisting kobjectinit() above adddisk() is not an option: commit ca39f7502425 ("md: fix mddev->kobj lifetime") moved it below adddisk() so that mdalloc()'s error paths, which free the mddev directly, never see an initialised kobject.