Skip to content

Commit bc0e610

Browse files
Jianglei Niekuba-moo
authored andcommitted
net: arc_emac: Fix use after free in arc_mdio_probe()
If bus->state is equal to MDIOBUS_ALLOCATED, mdiobus_free(bus) will free the "bus". But bus->name is still used in the next line, which will lead to a use after free. We can fix it by putting the name in a local variable and make the bus->name point to the rodata section "name",then use the name in the error message without referring to bus to avoid the uaf. Fixes: 95b5fc0 ("net: arc_emac: Make use of the helper function dev_err_probe()") Signed-off-by: Jianglei Nie <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 633593a commit bc0e610

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/net/ethernet/arc/emac_mdio.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ int arc_mdio_probe(struct arc_emac_priv *priv)
132132
{
133133
struct arc_emac_mdio_bus_data *data = &priv->bus_data;
134134
struct device_node *np = priv->dev->of_node;
135+
const char *name = "Synopsys MII Bus";
135136
struct mii_bus *bus;
136137
int error;
137138

@@ -142,7 +143,7 @@ int arc_mdio_probe(struct arc_emac_priv *priv)
142143
priv->bus = bus;
143144
bus->priv = priv;
144145
bus->parent = priv->dev;
145-
bus->name = "Synopsys MII Bus";
146+
bus->name = name;
146147
bus->read = &arc_mdio_read;
147148
bus->write = &arc_mdio_write;
148149
bus->reset = &arc_mdio_reset;
@@ -167,7 +168,7 @@ int arc_mdio_probe(struct arc_emac_priv *priv)
167168
if (error) {
168169
mdiobus_free(bus);
169170
return dev_err_probe(priv->dev, error,
170-
"cannot register MDIO bus %s\n", bus->name);
171+
"cannot register MDIO bus %s\n", name);
171172
}
172173

173174
return 0;

0 commit comments

Comments
 (0)