Skip to content

Commit b5e4f73

Browse files
Joseph Huangksacilotto
authored andcommitted
bridge: Fix a deadlock when enabling multicast snooping
BugLink: https://bugs.launchpad.net/bugs/1910817 [ Upstream commit 851d0a7 ] When enabling multicast snooping, bridge module deadlocks on multicast_lock if 1) IPv6 is enabled, and 2) there is an existing querier on the same L2 network. The deadlock was caused by the following sequence: While holding the lock, br_multicast_open calls br_multicast_join_snoopers, which eventually causes IP stack to (attempt to) send out a Listener Report (in igmp6_join_group). Since the destination Ethernet address is a multicast address, br_dev_xmit feeds the packet back to the bridge via br_multicast_rcv, which in turn calls br_multicast_add_group, which then deadlocks on multicast_lock. The fix is to move the call br_multicast_join_snoopers outside of the critical section. This works since br_multicast_join_snoopers only deals with IP and does not modify any multicast data structures of the bridge, so there's no need to hold the lock. Steps to reproduce: 1. sysctl net.ipv6.conf.all.force_mld_version=1 2. have another querier 3. ip link set dev bridge type bridge mcast_snooping 0 && \ ip link set dev bridge type bridge mcast_snooping 1 < deadlock > A typical call trace looks like the following: [ 936.251495] _raw_spin_lock+0x5c/0x68 [ 936.255221] br_multicast_add_group+0x40/0x170 [bridge] [ 936.260491] br_multicast_rcv+0x7ac/0xe30 [bridge] [ 936.265322] br_dev_xmit+0x140/0x368 [bridge] [ 936.269689] dev_hard_start_xmit+0x94/0x158 [ 936.273876] __dev_queue_xmit+0x5ac/0x7f8 [ 936.277890] dev_queue_xmit+0x10/0x18 [ 936.281563] neigh_resolve_output+0xec/0x198 [ 936.285845] ip6_finish_output2+0x240/0x710 [ 936.290039] __ip6_finish_output+0x130/0x170 [ 936.294318] ip6_output+0x6c/0x1c8 [ 936.297731] NF_HOOK.constprop.0+0xd8/0xe8 [ 936.301834] igmp6_send+0x358/0x558 [ 936.305326] igmp6_join_group.part.0+0x30/0xf0 [ 936.309774] igmp6_group_added+0xfc/0x110 [ 936.313787] __ipv6_dev_mc_inc+0x1a4/0x290 [ 936.317885] ipv6_dev_mc_inc+0x10/0x18 [ 936.321677] br_multicast_open+0xbc/0x110 [bridge] [ 936.326506] br_multicast_toggle+0xec/0x140 [bridge] Fixes: 4effd28 ("bridge: join all-snoopers multicast address") Signed-off-by: Joseph Huang <Joseph.Huang@garmin.com> Acked-by: Nikolay Aleksandrov <nikolay@nvidia.com> Link: https://lore.kernel.org/r/20201204235628.50653-1-Joseph.Huang@garmin.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
1 parent 664124b commit b5e4f73

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

net/bridge/br_device.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ static int br_dev_open(struct net_device *dev)
168168
br_stp_enable_bridge(br);
169169
br_multicast_open(br);
170170

171+
if (br_opt_get(br, BROPT_MULTICAST_ENABLED))
172+
br_multicast_join_snoopers(br);
173+
171174
return 0;
172175
}
173176

@@ -188,6 +191,9 @@ static int br_dev_stop(struct net_device *dev)
188191
br_stp_disable_bridge(br);
189192
br_multicast_stop(br);
190193

194+
if (br_opt_get(br, BROPT_MULTICAST_ENABLED))
195+
br_multicast_leave_snoopers(br);
196+
191197
netif_stop_queue(dev);
192198

193199
return 0;

net/bridge/br_multicast.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ static inline void br_ip6_multicast_join_snoopers(struct net_bridge *br)
18481848
}
18491849
#endif
18501850

1851-
static void br_multicast_join_snoopers(struct net_bridge *br)
1851+
void br_multicast_join_snoopers(struct net_bridge *br)
18521852
{
18531853
br_ip4_multicast_join_snoopers(br);
18541854
br_ip6_multicast_join_snoopers(br);
@@ -1879,7 +1879,7 @@ static inline void br_ip6_multicast_leave_snoopers(struct net_bridge *br)
18791879
}
18801880
#endif
18811881

1882-
static void br_multicast_leave_snoopers(struct net_bridge *br)
1882+
void br_multicast_leave_snoopers(struct net_bridge *br)
18831883
{
18841884
br_ip4_multicast_leave_snoopers(br);
18851885
br_ip6_multicast_leave_snoopers(br);
@@ -1898,9 +1898,6 @@ static void __br_multicast_open(struct net_bridge *br,
18981898

18991899
void br_multicast_open(struct net_bridge *br)
19001900
{
1901-
if (br_opt_get(br, BROPT_MULTICAST_ENABLED))
1902-
br_multicast_join_snoopers(br);
1903-
19041901
__br_multicast_open(br, &br->ip4_own_query);
19051902
#if IS_ENABLED(CONFIG_IPV6)
19061903
__br_multicast_open(br, &br->ip6_own_query);
@@ -1916,9 +1913,6 @@ void br_multicast_stop(struct net_bridge *br)
19161913
del_timer_sync(&br->ip6_other_query.timer);
19171914
del_timer_sync(&br->ip6_own_query.timer);
19181915
#endif
1919-
1920-
if (br_opt_get(br, BROPT_MULTICAST_ENABLED))
1921-
br_multicast_leave_snoopers(br);
19221916
}
19231917

19241918
void br_multicast_dev_del(struct net_bridge *br)
@@ -2049,6 +2043,7 @@ static void br_multicast_start_querier(struct net_bridge *br,
20492043
int br_multicast_toggle(struct net_bridge *br, unsigned long val)
20502044
{
20512045
struct net_bridge_port *port;
2046+
bool change_snoopers = false;
20522047

20532048
spin_lock_bh(&br->multicast_lock);
20542049
if (!!br_opt_get(br, BROPT_MULTICAST_ENABLED) == !!val)
@@ -2057,7 +2052,7 @@ int br_multicast_toggle(struct net_bridge *br, unsigned long val)
20572052
br_mc_disabled_update(br->dev, val);
20582053
br_opt_toggle(br, BROPT_MULTICAST_ENABLED, !!val);
20592054
if (!br_opt_get(br, BROPT_MULTICAST_ENABLED)) {
2060-
br_multicast_leave_snoopers(br);
2055+
change_snoopers = true;
20612056
goto unlock;
20622057
}
20632058

@@ -2068,9 +2063,30 @@ int br_multicast_toggle(struct net_bridge *br, unsigned long val)
20682063
list_for_each_entry(port, &br->port_list, list)
20692064
__br_multicast_enable_port(port);
20702065

2066+
change_snoopers = true;
2067+
20712068
unlock:
20722069
spin_unlock_bh(&br->multicast_lock);
20732070

2071+
/* br_multicast_join_snoopers has the potential to cause
2072+
* an MLD Report/Leave to be delivered to br_multicast_rcv,
2073+
* which would in turn call br_multicast_add_group, which would
2074+
* attempt to acquire multicast_lock. This function should be
2075+
* called after the lock has been released to avoid deadlocks on
2076+
* multicast_lock.
2077+
*
2078+
* br_multicast_leave_snoopers does not have the problem since
2079+
* br_multicast_rcv first checks BROPT_MULTICAST_ENABLED, and
2080+
* returns without calling br_multicast_ipv4/6_rcv if it's not
2081+
* enabled. Moved both functions out just for symmetry.
2082+
*/
2083+
if (change_snoopers) {
2084+
if (br_opt_get(br, BROPT_MULTICAST_ENABLED))
2085+
br_multicast_join_snoopers(br);
2086+
else
2087+
br_multicast_leave_snoopers(br);
2088+
}
2089+
20742090
return 0;
20752091
}
20762092

net/bridge/br_private.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,8 @@ void br_multicast_del_port(struct net_bridge_port *port);
665665
void br_multicast_enable_port(struct net_bridge_port *port);
666666
void br_multicast_disable_port(struct net_bridge_port *port);
667667
void br_multicast_init(struct net_bridge *br);
668+
void br_multicast_join_snoopers(struct net_bridge *br);
669+
void br_multicast_leave_snoopers(struct net_bridge *br);
668670
void br_multicast_open(struct net_bridge *br);
669671
void br_multicast_stop(struct net_bridge *br);
670672
void br_multicast_dev_del(struct net_bridge *br);
@@ -792,6 +794,14 @@ static inline void br_multicast_init(struct net_bridge *br)
792794
{
793795
}
794796

797+
static inline void br_multicast_join_snoopers(struct net_bridge *br)
798+
{
799+
}
800+
801+
static inline void br_multicast_leave_snoopers(struct net_bridge *br)
802+
{
803+
}
804+
795805
static inline void br_multicast_open(struct net_bridge *br)
796806
{
797807
}

0 commit comments

Comments
 (0)