Skip to content

Commit ef57640

Browse files
vladimirolteandavem330
authored andcommitted
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: 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>
1 parent 9ceaf6f commit ef57640

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/net/ethernet/mscc/ocelot.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,14 +549,18 @@ EXPORT_SYMBOL(ocelot_vlan_add);
549549
int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid)
550550
{
551551
struct ocelot_port *ocelot_port = ocelot->ports[port];
552+
bool del_pvid = false;
552553
int err;
553554

555+
if (ocelot_port->pvid_vlan && ocelot_port->pvid_vlan->vid == vid)
556+
del_pvid = true;
557+
554558
err = ocelot_vlan_member_del(ocelot, port, vid);
555559
if (err)
556560
return err;
557561

558562
/* Ingress */
559-
if (ocelot_port->pvid_vlan && ocelot_port->pvid_vlan->vid == vid)
563+
if (del_pvid)
560564
ocelot_port_set_pvid(ocelot, port, NULL);
561565

562566
/* Egress */

0 commit comments

Comments
 (0)