Skip to content

Commit c98bed6

Browse files
vladimirolteangregkh
authored andcommitted
net: mscc: ocelot: fix use-after-free in ocelot_vlan_del()
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>
1 parent 54abd57 commit c98bed6

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎drivers/net/ethernet/mscc/ocelot.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,14 +480,18 @@ EXPORT_SYMBOL(ocelot_vlan_add);
480480
int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid)
481481
{
482482
struct ocelot_port *ocelot_port = ocelot->ports[port];
483+
bool del_pvid = false;
483484
int err;
484485

486+
if (ocelot_port->pvid_vlan && ocelot_port->pvid_vlan->vid == vid)
487+
del_pvid = true;
488+
485489
err = ocelot_vlan_member_del(ocelot, port, vid);
486490
if (err)
487491
return err;
488492

489493
/* Ingress */
490-
if (ocelot_port->pvid_vlan && ocelot_port->pvid_vlan->vid == vid)
494+
if (del_pvid)
491495
ocelot_port_set_pvid(ocelot, port, NULL);
492496

493497
/* Egress */

0 commit comments

Comments
 (0)