In the Linux kernel, the following vulnerability has been resolved:
net: phy: fix null-ptr-deref while probe() failed
I got a null-ptr-deref report as following when doing fault injection test:
BUG: kernel NULL pointer dereference, address: 0000000000000058 Oops: 0000 [#1] PREEMPT SMP KASAN PTI CPU: 1 PID: 253 Comm: 507-spi-dm9051 Tainted: G B N 6.1.0-rc3+ Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 RIP: 0010:klistput+0x2d/0xd0 Call Trace: <TASK> klistremove+0xf1/0x1c0 devicereleasedriverinternal+0x23e/0x2d0 busremovedevice+0x1bd/0x240 devicedel+0x357/0x770 phydeviceremove+0x11/0x30 mdiobusunregister+0xa5/0x140 releasenodes+0x6a/0xa0 devresreleaseall+0xf8/0x150 deviceunbindcleanup+0x19/0xd0
//probe path: phydeviceregister() device_add()
phyconnect phyattachdirect() //set device driver probe() //it's failed, driver is not bound devicebind_driver() // probe failed, it's not called
//remove path: phydeviceremove() devicedel() devicereleasedriverinternal() _devicereleasedriver() //dev->drv is not NULL klistremove() <- knode_driver is not added yet, cause null-ptr-deref
In phyattachdirect(), after setting the 'dev->driver', probe() fails, devicebinddriver() is not called, so the knodedriver->nklist is not set, then it causes null-ptr-deref in _devicereleasedriver() while deleting device. Fix this by setting dev->driver to NULL in the error path in phyattach_direct().