net/phy/fixed.c: fix a use-after-free
Subsystems (3)
PATCH 1/1 net/phy/fixed.c: fix a use-after-free
This patch fixes a use-after-free introduced by
commit a79d8e93d300adb84cccc38ac396cfb118c238ad and spotted by the Coverity checker.
---20c51455b2faed63c3026fd4d7139e5a6a917d31
drivers/net/phy/fixed.c +2 -2
@@ -236,12 +236,12 @@ module_init(fixed_mdio_bus_init); static void __exit fixed_mdio_bus_exit(void) {struct fixed_mdio_bus *fmb = &platform_fmb; -struct fixed_phy *fp; +struct fixed_phy *fp, *tmp;mdiobus_unregister (&fmb->mii_bus);platform_device_unregister (pdev); -list_for_each_entry (fp, &fmb->phys, node) { +list_for_each_entry_safe (fp, tmp, &fmb->phys, node) {list_del (&fp->node);kfree (fp); }
Quoted 3 lines · Adrian Bunk
This patch fixes a use-after-free introduced by
commita79d8e93d300adb84cccc38ac396cfb118c238adand spotted by the Coverity checker.
Nice catch.
We didn't encounter this bug because fixed.c is bool, so module_exit isn't used. Thus, technically, we can remove it completely.
But I prefer your patch, because later, we might want to create library versions of the fixed_mdio_bus_{init,exit}. To use, for example, with PCI ethernet card that might have MDIO-less PHY, i.e. configuration is hardwired in the eeprom, but driver still want to use phylib framework.
Thanks,
Quoted 25 lines
Signed-off-by Adrian Bunk <[email protected]>---
20c51455b2faed63c3026fd4d7139e5a6a917d31drivers/net/phy/fixed.c +2
-2@@ -236,12 +236,12 @@ module_init(fixed_mdio_bus_init); static void __exit fixed_mdio_bus_exit(void) {struct fixed_mdio_bus *fmb = &platform_fmb; -struct fixed_phy *fp; +struct fixed_phy *fp, *tmp;mdiobus_unregister (&fmb->mii_bus);platform_device_unregister (pdev); -list_for_each_entry (fp, &fmb->phys, node) { +list_for_each_entry_safe (fp, tmp, &fmb->phys, node) {list_del (&fp->node);kfree (fp); }
Signature · 4 lines
Anton Vorontsov email: [email protected] backup email: [email protected] irc://irc.freenode.net/bd2