From patchwork Wed Jul 12 13:55:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Maciej_=C5=BBenczykowski?= X-Patchwork-Id: 13310408 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A59F5100AE for ; Wed, 12 Jul 2023 13:55:30 +0000 (UTC) Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 812FF10C7 for ; Wed, 12 Jul 2023 06:55:28 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-57320c10635so71735147b3.3 for ; Wed, 12 Jul 2023 06:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689170127; x=1691762127; h=content-transfer-encoding:cc:to:from:subject:mime-version :message-id:date:from:to:cc:subject:date:message-id:reply-to; bh=YOyxg8DmgqkozTi4nw3StFZkKAVktiq79mWFvDEFLjI=; b=5eu9WR3WSPE/ukrDZckifZoEcHNhKzj8+LqwwdOxNeib4RM95LQNdvUUaWKyToyWmh sdIdLo8SJR9qTl068+bGjVpWorBVvQ6H+w8U1+JaDrbW7znhayN3AvfoCee58ULl5aCC TX9lC5kFljb5I9ZW9A2GxmzxN2PtaPIC+OvMN29uEWGK7mfgGdlmtCa6Ybb/m02n0ze/ IK4nuiH7VXvT+QScjoQL2alCzCi1ZHXpyFvjp2VpPc9r6MNY7W+m5tCoYC4Krc3AwZmZ 7QaIw+iaJ2jBX6EfTqoy4ASaRnpo1K519rRHRFCIVhrIDqicjlvVfUarptOJwt/o3Ftb Qenw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689170127; x=1691762127; h=content-transfer-encoding:cc:to:from:subject:mime-version :message-id:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=YOyxg8DmgqkozTi4nw3StFZkKAVktiq79mWFvDEFLjI=; b=VyqR8hmWogrdFYxfO60qIJH/kVOfH9SbMp0SdTPZvSTf2BYw3HogFSQD8IFd2H8dGp uiylbzif2AK7L198mZ52WsQUoOaUdDhGC2PWQaM/zKNG+tljdpGdkC7DUxkMWmPHrSBX HTRRxFhE5gJswinvdvPxT5oacdp4L5lp6bJXkGe097WClUxy9rNnZi4JEHy+Y8DSAAQt kuRx/sHknLb3cYUSFORiY/D3O3hkkdRuzjVhy9VElOWVjXN4hIMGkR1BvC2nxxKhUBwj qCDGBTpfzyJPvlCY1nGyXWIthibO90z+dSZdux1Xzh7b55TAoAeyyeYYT7r16TiXofow 6iQA== X-Gm-Message-State: ABy/qLZfjWMAzDv8uV06wg5FzVc7OIinbP7trrLzBruQwn/OTZDsTls/ BZlwqf8P5Xbv1iR5pYIc+dgbhk3B X-Google-Smtp-Source: APBJJlExgN+6v6onn9+SdCKtPJitBXVABkVNIs/0lzM49gzgUND2OEXfDQ4efZrnYUse8ykWizC/HpYA X-Received: from athina.mtv.corp.google.com ([2620:15c:211:200:cdf9:6213:9376:ab44]) (user=maze job=sendgmr) by 2002:a81:404d:0:b0:570:75a8:7867 with SMTP id m13-20020a81404d000000b0057075a87867mr159778ywn.4.1689170127706; Wed, 12 Jul 2023 06:55:27 -0700 (PDT) Date: Wed, 12 Jul 2023 06:55:19 -0700 Message-Id: <20230712135520.743211-1-maze@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Subject: [PATCH net] ipv6 addrconf: fix bug where deleting a mngtmpaddr can create a new temporary address From: " =?utf-8?q?Maciej_=C5=BBenczykowski?= " To: " =?utf-8?q?Maciej_=C5=BBenczykowski?= " Cc: Linux Network Development Mailing List , " =?utf-8?q?Maciej_=C5=BBenczykowski?= " , "David S. Miller" , David Ahern , Jiri Pirko X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org currently on 6.4 net/main: # ip link add dummy1 type dummy # echo 1 > /proc/sys/net/ipv6/conf/dummy1/use_tempaddr # ip link set dummy1 up # ip -6 addr add 2000::1/64 mngtmpaddr dev dummy1 # ip -6 addr show dev dummy1 11: dummy1: mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000 inet6 2000::44f3:581c:8ca:3983/64 scope global temporary dynamic valid_lft 604800sec preferred_lft 86172sec inet6 2000::1/64 scope global mngtmpaddr valid_lft forever preferred_lft forever inet6 fe80::e8a8:a6ff:fed5:56d4/64 scope link valid_lft forever preferred_lft forever # ip -6 addr del 2000::44f3:581c:8ca:3983/64 dev dummy1 (can wait a few seconds if you want to, the above delete isn't [directly] the problem) # ip -6 addr show dev dummy1 11: dummy1: mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000 inet6 2000::1/64 scope global mngtmpaddr valid_lft forever preferred_lft forever inet6 fe80::e8a8:a6ff:fed5:56d4/64 scope link valid_lft forever preferred_lft forever # ip -6 addr del 2000::1/64 mngtmpaddr dev dummy1 # ip -6 addr show dev dummy1 11: dummy1: mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000 inet6 2000::81c9:56b7:f51a:b98f/64 scope global temporary dynamic valid_lft 604797sec preferred_lft 86169sec inet6 fe80::e8a8:a6ff:fed5:56d4/64 scope link valid_lft forever preferred_lft forever This patch prevents this new 'global temporary dynamic' address from being created by the deletion of the related (same subnet prefix) 'mngtmpaddr' (which is triggered by there already being no temporary addresses). Cc: "David S. Miller" Cc: David Ahern Cc: Jiri Pirko Fixes: 53bd67491537 ("ipv6 addrconf: introduce IFA_F_MANAGETEMPADDR to tell kernel to manage temporary addresses") Signed-off-by: Maciej Żenczykowski Reported-by: Xiao Ma --- net/ipv6/addrconf.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index e5213e598a04..94cec2075eee 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -2561,12 +2561,18 @@ static void manage_tempaddrs(struct inet6_dev *idev, ipv6_ifa_notify(0, ift); } - if ((create || list_empty(&idev->tempaddr_list)) && - idev->cnf.use_tempaddr > 0) { + /* Also create a temporary address if it's enabled but no temporary + * address currently exists. + * However, we get called with valid_lft == 0, prefered_lft == 0, create == false + * as part of cleanup (ie. deleting the mngtmpaddr). + * We don't want that to result in creating a new temporary ip address. + */ + if (list_empty(&idev->tempaddr_list) && (valid_lft || prefered_lft)) + create = true; + + if (create && idev->cnf.use_tempaddr > 0) { /* When a new public address is created as described * in [ADDRCONF], also create a new temporary address. - * Also create a temporary address if it's enabled but - * no temporary address currently exists. */ read_unlock_bh(&idev->lock); ipv6_create_tempaddr(ifp, false);