Skip to content

Commit

Permalink
net: mscc: ocelot: fix use-after-free in ocelot_vlan_del()
Browse files Browse the repository at this point in the history
commit ef57640 upstream.

ocelot_vlan_member_del() will free the struct ocelot_bridge_vlan, so if
this is the same as the port's pvid_vlan which we access afterwards,
what we're accessing is freed memory.

Fix the bug by determining whether to clear ocelot_port->pvid_vlan prior
to calling ocelot_vlan_member_del().

Fixes: d400442 ("net: mscc: ocelot: track the port pvid using a pointer")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
vladimiroltean authored and gregkh committed Feb 23, 2022
1 parent 54abd57 commit c98bed6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drivers/net/ethernet/mscc/ocelot.c
Expand Up @@ -480,14 +480,18 @@ EXPORT_SYMBOL(ocelot_vlan_add);
int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid)
{
struct ocelot_port *ocelot_port = ocelot->ports[port];
bool del_pvid = false;
int err;

if (ocelot_port->pvid_vlan && ocelot_port->pvid_vlan->vid == vid)
del_pvid = true;

err = ocelot_vlan_member_del(ocelot, port, vid);
if (err)
return err;

/* Ingress */
if (ocelot_port->pvid_vlan && ocelot_port->pvid_vlan->vid == vid)
if (del_pvid)
ocelot_port_set_pvid(ocelot, port, NULL);

/* Egress */
Expand Down

0 comments on commit c98bed6

Please sign in to comment.