[PATCH 5.13 038/351] net: bridge: multicast: fix MRD advertisement router port marking race

From: Greg Kroah-Hartman
Date: Mon Jul 19 2021 - 13:23:10 EST


From: Nikolay Aleksandrov <nikolay@xxxxxxxxxx>

commit 000b7287b67555fee39d39fff75229dedde0dcbf upstream.

When an MRD advertisement is received on a bridge port with multicast
snooping enabled, we mark it as a router port automatically, that
includes adding that port to the router port list. The multicast lock
protects that list, but it is not acquired in the MRD advertisement case
leading to a race condition, we need to take it to fix the race.

Cc: stable@xxxxxxxxxxxxxxx
Cc: linus.luessing@xxxxxxxxx
Fixes: 4b3087c7e37f ("bridge: Snoop Multicast Router Advertisements")
Signed-off-by: Nikolay Aleksandrov <nikolay@xxxxxxxxxx>
Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
net/bridge/br_multicast.c | 4 ++++
1 file changed, 4 insertions(+)

--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -3100,7 +3100,9 @@ static int br_ip4_multicast_mrd_rcv(stru
igmp_hdr(skb)->type != IGMP_MRDISC_ADV)
return -ENOMSG;

+ spin_lock(&br->multicast_lock);
br_multicast_mark_router(br, port);
+ spin_unlock(&br->multicast_lock);

return 0;
}
@@ -3168,7 +3170,9 @@ static void br_ip6_multicast_mrd_rcv(str
if (icmp6_hdr(skb)->icmp6_type != ICMPV6_MRDISC_ADV)
return;

+ spin_lock(&br->multicast_lock);
br_multicast_mark_router(br, port);
+ spin_unlock(&br->multicast_lock);
}

static int br_multicast_ipv6_rcv(struct net_bridge *br,