Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6254502iob; Tue, 10 May 2022 14:05:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgSo0jxsv3YQCZg1ZWTQVE/OfiiUO2V9JnavXP8n+iusve6iK/GGUubIu92hsS1GouusYt X-Received: by 2002:a17:907:16a2:b0:6f4:eeb1:f7de with SMTP id hc34-20020a17090716a200b006f4eeb1f7demr21766466ejc.446.1652216712040; Tue, 10 May 2022 14:05:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652216712; cv=none; d=google.com; s=arc-20160816; b=jf0lv6Y3fmJTUrhf0U+20QAsxDTl030FvwpBT9OZ3IPaO/vM3cOsnnClTeXZpZzCqR vGm8ZDaCWE94W0/uetE/6BkMgSLst3uEHytPyBqL/hL8emKQpoGBLmd6XcMQAKDOhEng H46nf6F3k1zOoY+wKl6g32lerxC8zVax+w+teT2eGNSI0Rh2vvX3XqhTzEGHRZUfzaPM FcdBUTBzKbXAG1G39kz91tpyxalUyj1xDM7TPG0ogbITZv6YqC9ejec9InFmkplV+nml jqX9v3Aat8eNXX9Ka/RXAKkGm5+HUIz9Wje/ZeOx4IE0zLbb9sM20X5W+mOqRTzKnoU6 SG4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+qD5esRweTg8ur+V0O/BO4vZ4QS75A4JfAlpr5dmzUM=; b=YRaEV7OewX/c6DSDDOSx6ZiajxMWhPw6/ijvJH5wmqDjp0KpYf6YTFICqg3DdDFwUq 38qLOEers/3Num2pm1L0L+8x21Yk9MjDOQX8+9t6pIVg5EDQtv7MLb4uDQyymPlTGMtS NWwOmXE8v46rxJc24eqTrKh2WHYfMTC2TKEyNzPJa/O4XjROsPqdtykZit0Xqe5Y1oGC GygWZB5viTlQm9qtntxuY2njcLZ/jss5+ttW0IwBm9+Rd7DlXMP9fQiH/n2VtMD03EC2 Wc6BJPsQCs7BB9Ooy4mgbrS48I6EKIOaVja3oqEeo2BtVPFZ/9f7jV/tOPwUO3nXeuJ7 AI2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="I//E6LbP"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i13-20020a1709064fcd00b006e7cd47a2d3si473718ejw.189.2022.05.10.14.04.39; Tue, 10 May 2022 14:05:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="I//E6LbP"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244493AbiEJNqs (ORCPT + 99 others); Tue, 10 May 2022 09:46:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243922AbiEJNcV (ORCPT ); Tue, 10 May 2022 09:32:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55CB647397; Tue, 10 May 2022 06:23:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E4EDC6170D; Tue, 10 May 2022 13:23:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEB09C385A6; Tue, 10 May 2022 13:23:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652189026; bh=cr94HvuOY+ar8/Psx+ZQoQk1dqg2cHIVgfMXgDzaZNY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I//E6LbPtBgbw3R6gptpgYlLgU3GFKYZdMhtuKabs2UZt0y8XPVz4EkYvld/5mF8X AE2tHNFOVUFOhOsilrLB9KBR4WqRgy+ZF467F69M8RIQmYECm78ydH7PSUSKG8ktDt 2DXd+O9kx2GfKJ9us7cho00t4eNy1oBBpFNjfM0A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Nixdorf , "David S. Miller" Subject: [PATCH 5.4 39/52] net: ipv6: ensure we call ipv6_mc_down() at most once Date: Tue, 10 May 2022 15:08:08 +0200 Message-Id: <20220510130730.996638140@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220510130729.852544477@linuxfoundation.org> References: <20220510130729.852544477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: j.nixdorf@avm.de commit 9995b408f17ff8c7f11bc725c8aa225ba3a63b1c upstream. 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: 3ce62a84d53c ("ipv6: exit early in addrconf_notify() if IPv6 is disabled") Signed-off-by: Johannes Nixdorf Signed-off-by: David S. Miller [jnixdorf: context updated for bpo to v4.19/v5.4] Signed-off-by: Johannes Nixdorf Signed-off-by: Greg Kroah-Hartman --- net/ipv6/addrconf.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -3715,6 +3715,7 @@ static int addrconf_ifdown(struct net_de struct inet6_dev *idev; struct inet6_ifaddr *ifa, *tmp; bool keep_addr = false; + bool was_ready; int state, i; ASSERT_RTNL(); @@ -3780,7 +3781,10 @@ restart: addrconf_del_rs_timer(idev); - /* Step 2: clear flags for stateless addrconf */ + /* Step 2: clear flags for stateless addrconf, repeated down + * detection + */ + was_ready = idev->if_flags & IF_READY; if (!how) idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY); @@ -3854,7 +3858,7 @@ restart: if (how) { ipv6_ac_destroy_dev(idev); ipv6_mc_destroy_dev(idev); - } else { + } else if (was_ready) { ipv6_mc_down(idev); }