From nobody Tue Jun 23 23:45:19 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98D7EC433EF for ; Thu, 24 Feb 2022 09:15:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232712AbiBXJPv (ORCPT ); Thu, 24 Feb 2022 04:15:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232704AbiBXJPt (ORCPT ); Thu, 24 Feb 2022 04:15:49 -0500 X-Greylist: delayed 508 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 24 Feb 2022 01:15:19 PST Received: from mail.avm.de (mail.avm.de [IPv6:2001:bf0:244:244::94]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDAC223BF17; Thu, 24 Feb 2022 01:15:19 -0800 (PST) Received: from mail-notes.avm.de (mail-notes.avm.de [172.16.0.1]) by mail.avm.de (Postfix) with ESMTP; Thu, 24 Feb 2022 10:06:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=avm.de; s=mail; t=1645693610; bh=zOitn8r3Zy50HUJEKlb+OOGXVNbcWgsJdUJYtMJP3Rk=; h=In-Reply-To:References:Subject:From:To:Date:From; b=EFW8EQ1GmnTAGbouXKP9xookZUHWkDYvBo7hXqb93juxFsILPBjVqyRtCZ5WbKVbU rda5ZZLehsbJcvvk0KtQQ8cf30KhNYjAknPYIFY3zHhi0okdTGpy5onSyOgpFu6o/t 4tSoqNAli5wE9cvIymW87mC5h48qObeQe87WZX/s= MIME-Version: 1.0 X-Disclaimed: 1 Sensitivity: Importance: Normal X-Priority: 3 (Normal) In-Reply-To: References: Subject: [PATCH] net: ipv6: ensure we call ipv6_mc_down() at most once From: j.nixdorf@avm.de To: "David S. Miller" , Hideaki YOSHIFUJI , David Ahern , Jakub Kicinski , WANG Cong , Hannes Frederic Sowa , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 24 Feb 2022 10:06:49 +0100 Message-ID: X-Mailer: Lotus Domino Web Server Release 12.0.1HF14 December 15, 2021 X-MIMETrack: Serialize by http on ANIS1/AVM(Release 12.0.1HF14 | December 15, 2021) at 24.02.2022 10:06:49, Serialize complete at 24.02.2022 10:06:49, Serialize by Router on ANIS1/AVM(Release 12.0.1HF14 | December 15, 2021) at 24.02.2022 10:06:49 Content-Transfer-Encoding: quoted-printable X-purgate-ID: 149429::1645693610-00001F4B-77E04A23/0/0 X-purgate-type: clean X-purgate-size: 3385 X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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=3D1 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 (=3D> 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=3D0 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: 3ce62a84d53c ("ipv6: exit early in addrconf_notify() if IPv6 is disa= bled") Signed-off-by: Johannes Nixdorf --- net/ipv6/addrconf.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index f927c199a93c..c5e9ca244175 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -3732,6 +3732,7 @@ static int addrconf_ifdown(struct net_device *dev, bo= ol unregister) struct inet6_dev *idev; struct inet6_ifaddr *ifa, *tmp; bool keep_addr =3D false; + bool was_ready; int state, i; =20 ASSERT_RTNL(); @@ -3797,7 +3798,10 @@ static int addrconf_ifdown(struct net_device *dev, b= ool unregister) =20 addrconf_del_rs_timer(idev); =20 - /* Step 2: clear flags for stateless addrconf */ + /* Step 2: clear flags for stateless addrconf, repeated down + * detection + */ + was_ready =3D idev->if_flags & IF_READY; if (!unregister) idev->if_flags &=3D ~(IF_RS_SENT|IF_RA_RCVD|IF_READY); =20 @@ -3871,7 +3875,7 @@ static int addrconf_ifdown(struct net_device *dev, bo= ol unregister) if (unregister) { ipv6_ac_destroy_dev(idev); ipv6_mc_destroy_dev(idev); - } else { + } else if (was_ready) { ipv6_mc_down(idev); } =20 --=20 2.35.1