Skip to content

Commit 1699b4d

Browse files
vladimirolteankuba-moo
authored andcommitted
net: dsa: fix NULL pointer dereference in dsa_port_reset_vlan_filtering
The "ds" iterator variable used in dsa_port_reset_vlan_filtering() -> dsa_switch_for_each_port() overwrites the "dp" received as argument, which is later used to call dsa_port_vlan_filtering() proper. As a result, switches which do enter that code path (the ones with vlan_filtering_is_global=true) will dereference an invalid dp in dsa_port_reset_vlan_filtering() after leaving a VLAN-aware bridge. Use a dedicated "other_dp" iterator variable to avoid this from happening. Fixes: d0004a0 ("net: dsa: remove the "dsa_to_port in a loop" antipattern from the core") Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 4db2a5e commit 1699b4d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

net/dsa/port.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ static void dsa_port_reset_vlan_filtering(struct dsa_port *dp,
248248
struct netlink_ext_ack extack = {0};
249249
bool change_vlan_filtering = false;
250250
struct dsa_switch *ds = dp->ds;
251+
struct dsa_port *other_dp;
251252
bool vlan_filtering;
252253
int err;
253254

@@ -270,8 +271,8 @@ static void dsa_port_reset_vlan_filtering(struct dsa_port *dp,
270271
* VLAN-aware bridge.
271272
*/
272273
if (change_vlan_filtering && ds->vlan_filtering_is_global) {
273-
dsa_switch_for_each_port(dp, ds) {
274-
struct net_device *br = dsa_port_bridge_dev_get(dp);
274+
dsa_switch_for_each_port(other_dp, ds) {
275+
struct net_device *br = dsa_port_bridge_dev_get(other_dp);
275276

276277
if (br && br_vlan_enabled(br)) {
277278
change_vlan_filtering = false;

0 commit comments

Comments
 (0)