Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1785362pxp; Mon, 7 Mar 2022 02:15:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJyZETqBqnGKv7MDjzKcD9YxzcAUXo1FOx5XlZcMsFY0e2uGzeg+D2+G4cOtqQ4chiKDtDNR X-Received: by 2002:a05:6402:370b:b0:413:3bcd:3d0e with SMTP id ek11-20020a056402370b00b004133bcd3d0emr10516507edb.178.1646648147552; Mon, 07 Mar 2022 02:15:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646648147; cv=none; d=google.com; s=arc-20160816; b=Fv/2o95WoLoDCr8QcZAVrcumMQazifiZCZsJLNsVTNLBa4e/TQtZ3MGV0bw8HvnQsY K+LgFdwz2BP/oXObFvBiMHqukQTawXNm7uAdcYnmsQXGxVX01UMUX7X8CexCpEI6c0tN +cIxfmQ78IVaqSg+6Wi/hfeJB3mcRGLokSlrRU9OwqiMk7MJkh+jH/oeZGTgOz+v2Gr0 7xvGw5soVN4hrpelZhhTmcaricWUO64Bl5n7y3ZtX4cdWDA+pBTYPWicXNK6mrEbIaTK qDthGy2VDTlTqcHLOXFy69Qbr/K1RCJAsJwc/3486US70079mfPWRj9rj5YNbkfXuwXl BdPA== 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=ml0gTWl4gOTNLp6rDw6PwCGH/rH7OKN+eI4gTZDOdwI=; b=IPcLYY74Rb/4khSb/uVwueF5I8t843O1uDJtNfELClaJ1WNqOS8kHzZ8isXS9aPWvF ArVxMcOB0J/xUd7675RBdqxx9rTgRBCRj9Kc27oAzwkVECOEei9i78n6udFcbUh6U+HR CKX3qlH91Y3dQ2dmW/zAi+1x6iZaS0X7m+uvRU0pXp6P/af6ouFyCkRnu0VjxgtfiJ9d gTv3BMULfrfervYIYcxQNqQN5mLyuemWT+JGMbBoN8ZLHG0NK2+IkFZLof4dFejnHX5N nIami5HaaNlDhlEgkGTvLPo1vzNZdtOqXab1LS9Lsq54Nfr2S++1Mjdzawppo9u9lUS5 QchQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nGFevt2E; 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 sb37-20020a1709076da500b006d9f7b3e732si8493574ejc.796.2022.03.07.02.15.24; Mon, 07 Mar 2022 02:15:47 -0800 (PST) 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=nGFevt2E; 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 S238555AbiCGJr4 (ORCPT + 99 others); Mon, 7 Mar 2022 04:47:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238276AbiCGJiI (ORCPT ); Mon, 7 Mar 2022 04:38:08 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A59B565831; Mon, 7 Mar 2022 01:32:23 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id 0DE00B810D5; Mon, 7 Mar 2022 09:31:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D0CCC340E9; Mon, 7 Mar 2022 09:31:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646645498; bh=++8/Vsf784pHB+1al/o8A7fD/NLBE4ezvlAl4JnQCrA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nGFevt2EsGJePgXVhBrY/WGlzaDB5Ol9Kbki06zgzBFEKdhIXDtrz8/HzRJUpxClH EEh/xo4sck1/G0uYO62NKRy83KlDO8tE8Jr22g6so9Es9molqgpJF4DgD6Pu7DoRUu qm6k346MMyHwQfp9SA9s2I5GCFgXWNr5x3Pa/gE4= 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.10 049/105] net: ipv6: ensure we call ipv6_mc_down() at most once Date: Mon, 7 Mar 2022 10:18:52 +0100 Message-Id: <20220307091645.564178487@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091644.179885033@linuxfoundation.org> References: <20220307091644.179885033@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.6 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 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 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 @@ -3712,6 +3712,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(); @@ -3777,7 +3778,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 (!unregister) idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY); @@ -3851,7 +3855,7 @@ restart: if (unregister) { ipv6_ac_destroy_dev(idev); ipv6_mc_destroy_dev(idev); - } else { + } else if (was_ready) { ipv6_mc_down(idev); }