Skip to content

Commit 8940e6b

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: avoid call to __dev_set_promiscuity() while rtnl_mutex isn't held
If the DSA master doesn't support IFF_UNICAST_FLT, then the following call path is possible: dsa_slave_switchdev_event_work -> dsa_port_host_fdb_add -> dev_uc_add -> __dev_set_rx_mode -> __dev_set_promiscuity Since the blamed commit, dsa_slave_switchdev_event_work() no longer holds rtnl_lock(), which triggers the ASSERT_RTNL() from __dev_set_promiscuity(). Taking rtnl_lock() around dev_uc_add() is impossible, because all the code paths that call dsa_flush_workqueue() do so from contexts where the rtnl_mutex is already held - so this would lead to an instant deadlock. dev_uc_add() in itself doesn't require the rtnl_mutex for protection. There is this comment in __dev_set_rx_mode() which assumes so: /* Unicast addresses changes may only happen under the rtnl, * therefore calling __dev_set_promiscuity here is safe. */ but it is from commit 4417da6 ("[NET]: dev: secondary unicast address support") dated June 2007, and in the meantime, commit f1f28aa ("netdev: Add addr_list_lock to struct net_device."), dated July 2008, has added &dev->addr_list_lock to protect this instead of the global rtnl_mutex. Nonetheless, __dev_set_promiscuity() does assume rtnl_mutex protection, but it is the uncommon path of what we typically expect dev_uc_add() to do. So since only the uncommon path requires rtnl_lock(), just check ahead of time whether dev_uc_add() would result into a call to __dev_set_promiscuity(), and handle that condition separately. DSA already configures the master interface to be promiscuous if the tagger requires this. We can extend this to also cover the case where the master doesn't handle dev_uc_add() (doesn't support IFF_UNICAST_FLT), and on the premise that we'd end up making it promiscuous during operation anyway, either if a DSA slave has a non-inherited MAC address, or if the bridge notifies local FDB entries for its own MAC address, the address of a station learned on a foreign port, etc. Fixes: 0faf890 ("net: dsa: drop rtnl_lock from dsa_slave_switchdev_event_work") Reported-by: Oleksij Rempel <[email protected]> Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3d00827 commit 8940e6b

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

net/dsa/master.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,16 @@ static void dsa_netdev_ops_set(struct net_device *dev,
260260
dev->dsa_ptr->netdev_ops = ops;
261261
}
262262

263+
/* Keep the master always promiscuous if the tagging protocol requires that
264+
* (garbles MAC DA) or if it doesn't support unicast filtering, case in which
265+
* it would revert to promiscuous mode as soon as we call dev_uc_add() on it
266+
* anyway.
267+
*/
263268
static void dsa_master_set_promiscuity(struct net_device *dev, int inc)
264269
{
265270
const struct dsa_device_ops *ops = dev->dsa_ptr->tag_ops;
266271

267-
if (!ops->promisc_on_master)
272+
if ((dev->priv_flags & IFF_UNICAST_FLT) && !ops->promisc_on_master)
268273
return;
269274

270275
ASSERT_RTNL();

net/dsa/port.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,15 @@ int dsa_port_host_fdb_add(struct dsa_port *dp, const unsigned char *addr,
781781
struct dsa_port *cpu_dp = dp->cpu_dp;
782782
int err;
783783

784-
err = dev_uc_add(cpu_dp->master, addr);
785-
if (err)
786-
return err;
784+
/* Avoid a call to __dev_set_promiscuity() on the master, which
785+
* requires rtnl_lock(), since we can't guarantee that is held here,
786+
* and we can't take it either.
787+
*/
788+
if (cpu_dp->master->priv_flags & IFF_UNICAST_FLT) {
789+
err = dev_uc_add(cpu_dp->master, addr);
790+
if (err)
791+
return err;
792+
}
787793

788794
return dsa_port_notify(dp, DSA_NOTIFIER_HOST_FDB_ADD, &info);
789795
}
@@ -800,9 +806,11 @@ int dsa_port_host_fdb_del(struct dsa_port *dp, const unsigned char *addr,
800806
struct dsa_port *cpu_dp = dp->cpu_dp;
801807
int err;
802808

803-
err = dev_uc_del(cpu_dp->master, addr);
804-
if (err)
805-
return err;
809+
if (cpu_dp->master->priv_flags & IFF_UNICAST_FLT) {
810+
err = dev_uc_del(cpu_dp->master, addr);
811+
if (err)
812+
return err;
813+
}
806814

807815
return dsa_port_notify(dp, DSA_NOTIFIER_HOST_FDB_DEL, &info);
808816
}

0 commit comments

Comments
 (0)