In the Linux kernel, the following vulnerability has been resolved:
net: dsa: mv88e6xxx: don't use devres for mdiobus
As explained in commits: 74b6d7d13307 ("net: dsa: realtek: register the MDIO bus under devres") 5135e96a3dd2 ("net: dsa: don't allocate the slavemiibus using devres")
mdiobusfree() will panic when called from devmmdiobusfree() <- devresreleaseall() <- _devicereleasedriver(), and that mdiobus was not previously unregistered.
The mv88e6xxx is an MDIO device, so the initial set of constraints that I thought would cause this (I2C or SPI buses which call ->remove on ->shutdown) do not apply. But there is one more which applies here.
If the DSA master itself is on a bus that calls ->remove from ->shutdown (like dpaa2-eth, which is on the fsl-mc bus), there is a device link between the switch and the DSA master, and devicelinksunbind_consumers() will unbind the Marvell switch driver on shutdown.
systemd-shutdown[1]: Powering off. mv88e6085 0x0000000008b96000:00 swgl0: Link is Down fsl-mc dpbp.9: Removing from iommu group 7 fsl-mc dpbp.8: Removing from iommu group 7 ------------[ cut here ]------------ kernel BUG at drivers/net/phy/mdiobus.c:677! Internal error: Oops - BUG: 0 [#1] PREEMPT SMP Modules linked in: CPU: 0 PID: 1 Comm: systemd-shutdow Not tainted 5.16.5-00040-gdc05f73788e5 #15 pc : mdiobusfree+0x44/0x50 lr : devmmdiobusfree+0x10/0x20 Call trace: mdiobusfree+0x44/0x50 devmmdiobusfree+0x10/0x20 devresreleaseall+0xa0/0x100 _devicereleasedriver+0x190/0x220 devicereleasedriverinternal+0xac/0xb0 devicelinksunbindconsumers+0xd4/0x100 _devicereleasedriver+0x4c/0x220 devicereleasedriverinternal+0xac/0xb0 devicelinksunbindconsumers+0xd4/0x100 _devicereleasedriver+0x94/0x220 devicereleasedriver+0x28/0x40 busremovedevice+0x118/0x124 devicedel+0x174/0x420 fslmcdeviceremove+0x24/0x40 _fslmcdeviceremove+0xc/0x20 deviceforeachchild+0x58/0xa0 dprcremove+0x90/0xb0 fslmcdriverremove+0x20/0x5c _devicereleasedriver+0x21c/0x220 devicereleasedriver+0x28/0x40 busremovedevice+0x118/0x124 devicedel+0x174/0x420 fslmcbusremove+0x80/0x100 fslmcbusshutdown+0xc/0x1c platformshutdown+0x20/0x30 deviceshutdown+0x154/0x330 kernelpoweroff+0x34/0x6c _dosysreboot+0x15c/0x250 _arm64sysreboot+0x20/0x30 invokesyscall.constprop.0+0x4c/0xe0 doel0svc+0x4c/0x150 el0svc+0x24/0xb0 el0t64synchandler+0xa8/0xb0 el0t64_sync+0x178/0x17c
So the same treatment must be applied to all DSA switch drivers, which is: either use devres for both the mdiobus allocation and registration, or don't use devres at all.
The Marvell driver already has a good structure for mdiobus removal, so just plug in mdiobus_free and get rid of devres.
[
{
"signature_type": "Function",
"digest": {
"function_hash": "298934799915607516257398622355601827988",
"length": 1133.0
},
"target": {
"file": "drivers/net/dsa/mv88e6xxx/chip.c",
"function": "mv88e6xxx_mdio_register"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@8ccebe77df6e0d88c72ba5e69cf1835927e53b6c",
"id": "CVE-2022-48818-172f3c95",
"deprecated": false,
"signature_version": "v1"
},
{
"signature_type": "Function",
"digest": {
"function_hash": "298934799915607516257398622355601827988",
"length": 1133.0
},
"target": {
"file": "drivers/net/dsa/mv88e6xxx/chip.c",
"function": "mv88e6xxx_mdio_register"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@8b626d45127d6f5ada7d815b83cfdc09e8cb1394",
"id": "CVE-2022-48818-23b32049",
"deprecated": false,
"signature_version": "v1"
},
{
"signature_type": "Function",
"digest": {
"function_hash": "41615571691051530069398918410569727457",
"length": 219.0
},
"target": {
"file": "drivers/net/dsa/mv88e6xxx/chip.c",
"function": "mv88e6xxx_mdios_unregister"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@8ccebe77df6e0d88c72ba5e69cf1835927e53b6c",
"id": "CVE-2022-48818-4bbd57ce",
"deprecated": false,
"signature_version": "v1"
},
{
"signature_type": "Function",
"digest": {
"function_hash": "41615571691051530069398918410569727457",
"length": 219.0
},
"target": {
"file": "drivers/net/dsa/mv88e6xxx/chip.c",
"function": "mv88e6xxx_mdios_unregister"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@8b626d45127d6f5ada7d815b83cfdc09e8cb1394",
"id": "CVE-2022-48818-84a835be",
"deprecated": false,
"signature_version": "v1"
},
{
"signature_type": "Line",
"digest": {
"threshold": 0.9,
"line_hashes": [
"228152038975443292899992165842522939911",
"302208891796183161715379625450937895466",
"172685998742637077680468425554199959215",
"250049037369474060511603034658601217405",
"330551789707100980111868004832827281521",
"13750170314786508426608355118251362684",
"74992413596070427148416113738019467650",
"294319021935071684708295426222056310186",
"259940199392617323509369245624848424646",
"139704278564833028575068285283600804612",
"201870627774362144440704669868690357370",
"69832303887712706059257156090369209218",
"194478994882764134565077679310806761071",
"195151492555539690313898630395158010395",
"83337329793352358363311477113914609817",
"232310655587143756352324835980483315687",
"54564362286717805018732397266027255753",
"160305620380311810455843391525775256099",
"202266304092720349328924602492643381773",
"27098600637288971135473380264559321791",
"297828604033489641955995373715155017350",
"90486447092537971241378814578861314333"
]
},
"target": {
"file": "drivers/net/dsa/mv88e6xxx/chip.c"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@8b626d45127d6f5ada7d815b83cfdc09e8cb1394",
"id": "CVE-2022-48818-b9aa8ea9",
"deprecated": false,
"signature_version": "v1"
},
{
"signature_type": "Line",
"digest": {
"threshold": 0.9,
"line_hashes": [
"228152038975443292899992165842522939911",
"302208891796183161715379625450937895466",
"172685998742637077680468425554199959215",
"250049037369474060511603034658601217405",
"330551789707100980111868004832827281521",
"13750170314786508426608355118251362684",
"74992413596070427148416113738019467650",
"294319021935071684708295426222056310186",
"259940199392617323509369245624848424646",
"139704278564833028575068285283600804612",
"201870627774362144440704669868690357370",
"69832303887712706059257156090369209218",
"194478994882764134565077679310806761071",
"195151492555539690313898630395158010395",
"83337329793352358363311477113914609817",
"232310655587143756352324835980483315687",
"54564362286717805018732397266027255753",
"160305620380311810455843391525775256099",
"202266304092720349328924602492643381773",
"27098600637288971135473380264559321791",
"297828604033489641955995373715155017350",
"90486447092537971241378814578861314333"
]
},
"target": {
"file": "drivers/net/dsa/mv88e6xxx/chip.c"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@8ccebe77df6e0d88c72ba5e69cf1835927e53b6c",
"id": "CVE-2022-48818-d11a3ca0",
"deprecated": false,
"signature_version": "v1"
}
]