summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJianglei Nie <niejianglei2021@163.com>2022-03-09 20:18:24 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-03-16 14:26:45 +0100
commit84c831803785c2c3bec5c28c0e8a0b72f6b41d4d (patch)
treed9c55896b0197e1912bcb0fc5358b3cb36a10005
parentd828b0fe6631f3ae8709ac9a10c77c5836c76a08 (diff)
downloadlinux-stable-84c831803785c2c3bec5c28c0e8a0b72f6b41d4d.tar.gz
linux-stable-84c831803785c2c3bec5c28c0e8a0b72f6b41d4d.tar.bz2
linux-stable-84c831803785c2c3bec5c28c0e8a0b72f6b41d4d.zip
net: arc_emac: Fix use after free in arc_mdio_probe()
[ Upstream commit bc0e610a6eb0d46e4123fafdbe5e6141d9fff3be ] 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: 95b5fc03c189 ("net: arc_emac: Make use of the helper function dev_err_probe()") Signed-off-by: Jianglei Nie <niejianglei2021@163.com> Link: https://lore.kernel.org/r/20220309121824.36529-1-niejianglei2021@163.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/net/ethernet/arc/emac_mdio.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/drivers/net/ethernet/arc/emac_mdio.c b/drivers/net/ethernet/arc/emac_mdio.c
index 9acf589b1178..87f40c2ba904 100644
--- a/drivers/net/ethernet/arc/emac_mdio.c
+++ b/drivers/net/ethernet/arc/emac_mdio.c
@@ -132,6 +132,7 @@ int arc_mdio_probe(struct arc_emac_priv *priv)
{
struct arc_emac_mdio_bus_data *data = &priv->bus_data;
struct device_node *np = priv->dev->of_node;
+ const char *name = "Synopsys MII Bus";
struct mii_bus *bus;
int error;
@@ -142,7 +143,7 @@ int arc_mdio_probe(struct arc_emac_priv *priv)
priv->bus = bus;
bus->priv = priv;
bus->parent = priv->dev;
- bus->name = "Synopsys MII Bus";
+ bus->name = name;
bus->read = &arc_mdio_read;
bus->write = &arc_mdio_write;
bus->reset = &arc_mdio_reset;
@@ -167,7 +168,7 @@ int arc_mdio_probe(struct arc_emac_priv *priv)
if (error) {
mdiobus_free(bus);
return dev_err_probe(priv->dev, error,
- "cannot register MDIO bus %s\n", bus->name);
+ "cannot register MDIO bus %s\n", name);
}
return 0;