Skip to content

Commit 9995b40

Browse files
mixi-workdavem330
authored andcommitted
net: ipv6: ensure we call ipv6_mc_down() at most once
There are two reasons for addrconf_notify() to be called with NETDEV_DOWN: either the network device is actually going down, or IPv6 was disabled on the interface. If either of them stays down while the other is toggled, we repeatedly call the code for NETDEV_DOWN, including ipv6_mc_down(), while never calling the corresponding ipv6_mc_up() in between. This will cause a new entry in idev->mc_tomb to be allocated for each multicast group the interface is subscribed to, which in turn leaks one struct ifmcaddr6 per nontrivial multicast group the interface is subscribed to. The following reproducer will leak at least $n objects: ip addr add ff2e::4242/32 dev eth0 autojoin sysctl -w net.ipv6.conf.eth0.disable_ipv6=1 for i in $(seq 1 $n); do ip link set up eth0; ip link set down eth0 done Joining groups with IPV6_ADD_MEMBERSHIP (unprivileged) or setting the sysctl net.ipv6.conf.eth0.forwarding to 1 (=> subscribing to ff02::2) can also be used to create a nontrivial idev->mc_list, which will the leak objects with the right up-down-sequence. Based on both sources for NETDEV_DOWN events the interface IPv6 state should be considered: - not ready if the network interface is not ready OR IPv6 is disabled for it - ready if the network interface is ready AND IPv6 is enabled for it The functions ipv6_mc_up() and ipv6_down() should only be run when this state changes. Implement this by remembering when the IPv6 state is ready, and only run ipv6_mc_down() if it actually changed from ready to not ready. The other direction (not ready -> ready) already works correctly, as: - the interface notification triggered codepath for NETDEV_UP / NETDEV_CHANGE returns early if ipv6 is disabled, and - the disable_ipv6=0 triggered codepath skips fully initializing the interface as long as addrconf_link_ready(dev) returns false - calling ipv6_mc_up() repeatedly does not leak anything Fixes: 3ce62a8 ("ipv6: exit early in addrconf_notify() if IPv6 is disabled") Signed-off-by: Johannes Nixdorf <j.nixdorf@avm.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 519ca6f commit 9995b40

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

net/ipv6/addrconf.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3732,6 +3732,7 @@ static int addrconf_ifdown(struct net_device *dev, bool unregister)
37323732
struct inet6_dev *idev;
37333733
struct inet6_ifaddr *ifa, *tmp;
37343734
bool keep_addr = false;
3735+
bool was_ready;
37353736
int state, i;
37363737

37373738
ASSERT_RTNL();
@@ -3797,7 +3798,10 @@ static int addrconf_ifdown(struct net_device *dev, bool unregister)
37973798

37983799
addrconf_del_rs_timer(idev);
37993800

3800-
/* Step 2: clear flags for stateless addrconf */
3801+
/* Step 2: clear flags for stateless addrconf, repeated down
3802+
* detection
3803+
*/
3804+
was_ready = idev->if_flags & IF_READY;
38013805
if (!unregister)
38023806
idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY);
38033807

@@ -3871,7 +3875,7 @@ static int addrconf_ifdown(struct net_device *dev, bool unregister)
38713875
if (unregister) {
38723876
ipv6_ac_destroy_dev(idev);
38733877
ipv6_mc_destroy_dev(idev);
3874-
} else {
3878+
} else if (was_ready) {
38753879
ipv6_mc_down(idev);
38763880
}
38773881

0 commit comments

Comments
 (0)