]> Git Repo - linux.git/commitdiff
net: dsa: mv88e6xxx: fix use-after-free in mv88e6xxx_mdios_unregister
authorVladimir Oltean <[email protected]>
Thu, 10 Feb 2022 17:40:17 +0000 (19:40 +0200)
committerJakub Kicinski <[email protected]>
Thu, 10 Feb 2022 19:46:03 +0000 (11:46 -0800)
Since struct mv88e6xxx_mdio_bus *mdio_bus is the bus->priv of something
allocated with mdiobus_alloc_size(), this means that mdiobus_free(bus)
will free the memory backing the mdio_bus as well. Therefore, the
mdio_bus->list element is freed memory, but we continue to iterate
through the list of MDIO buses using that list element.

To fix this, use the proper list iterator that handles element deletion
by keeping a copy of the list element next pointer.

Fixes: f53a2ce893b2 ("net: dsa: mv88e6xxx: don't use devres for mdiobus")
Reported-by: Rafael Richter <[email protected]>
Signed-off-by: Vladimir Oltean <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
drivers/net/dsa/mv88e6xxx/chip.c

index 659f295824069dcd1cd69432efed01e080f81b2a..8530dbe403f4dc6c970d2c19bbf104aec6dc7419 100644 (file)
@@ -3449,10 +3449,10 @@ out:
 static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
 
 {
-       struct mv88e6xxx_mdio_bus *mdio_bus;
+       struct mv88e6xxx_mdio_bus *mdio_bus, *p;
        struct mii_bus *bus;
 
-       list_for_each_entry(mdio_bus, &chip->mdios, list) {
+       list_for_each_entry_safe(mdio_bus, p, &chip->mdios, list) {
                bus = mdio_bus->bus;
 
                if (!mdio_bus->external)
This page took 0.073216 seconds and 4 git commands to generate.