Skip to content

Commit 51a04eb

Browse files
vladimirolteankuba-moo
authored andcommitted
net: dsa: mv88e6xxx: fix use-after-free in mv88e6xxx_mdios_unregister
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: f53a2ce ("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]>
1 parent a19f7d7 commit 51a04eb

File tree

1 file changed

+2
-2
lines changed
  • drivers/net/dsa/mv88e6xxx

1 file changed

+2
-2
lines changed

drivers/net/dsa/mv88e6xxx/chip.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3449,10 +3449,10 @@ static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip,
34493449
static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip)
34503450

34513451
{
3452-
struct mv88e6xxx_mdio_bus *mdio_bus;
3452+
struct mv88e6xxx_mdio_bus *mdio_bus, *p;
34533453
struct mii_bus *bus;
34543454

3455-
list_for_each_entry(mdio_bus, &chip->mdios, list) {
3455+
list_for_each_entry_safe(mdio_bus, p, &chip->mdios, list) {
34563456
bus = mdio_bus->bus;
34573457

34583458
if (!mdio_bus->external)

0 commit comments

Comments
 (0)