Commit ef576405 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller

net: mscc: ocelot: fix use-after-free in ocelot_vlan_del()

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: d4004422 ("net: mscc: ocelot: track the port pvid using a pointer")
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9ceaf6f7
...@@ -549,14 +549,18 @@ EXPORT_SYMBOL(ocelot_vlan_add); ...@@ -549,14 +549,18 @@ EXPORT_SYMBOL(ocelot_vlan_add);
int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid) int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid)
{ {
struct ocelot_port *ocelot_port = ocelot->ports[port]; struct ocelot_port *ocelot_port = ocelot->ports[port];
bool del_pvid = false;
int err; int err;
if (ocelot_port->pvid_vlan && ocelot_port->pvid_vlan->vid == vid)
del_pvid = true;
err = ocelot_vlan_member_del(ocelot, port, vid); err = ocelot_vlan_member_del(ocelot, port, vid);
if (err) if (err)
return err; return err;
/* Ingress */ /* Ingress */
if (ocelot_port->pvid_vlan && ocelot_port->pvid_vlan->vid == vid) if (del_pvid)
ocelot_port_set_pvid(ocelot, port, NULL); ocelot_port_set_pvid(ocelot, port, NULL);
/* Egress */ /* Egress */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment