Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2362037iof; Wed, 8 Jun 2022 03:23:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyp6HiYztxwnLIMkLqQThwJdzGKYd0F/w53z7JtsgMbvy8qjclkxMJmlCQTL61/+JG+XWBh X-Received: by 2002:a17:90b:4a0a:b0:1e8:5078:b574 with SMTP id kk10-20020a17090b4a0a00b001e85078b574mr24866827pjb.149.1654683831985; Wed, 08 Jun 2022 03:23:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654683831; cv=none; d=google.com; s=arc-20160816; b=lJ68L9HBkALx7BCqVfhnCjXRUK0wgli1NlrYSvxbZACOeuEBVEtxpSAIRfeLBPCM3+ SZT7hszXPZulmZud8eK2IE3+BCcu2QgNYL8QpqIGvIFPXJM1AzEmOnG2zqJWcOUwy3dM Bycw0tng16ioN/4Z13CtwiKpcgh/y6CoCTtNuovKLfVfRX/AUgFe5mqmRdVlM0+zwuVo eQst9lVMu8e534x3xCFd3OL7P/azQC1p2X43zAsXBZd2EC3vJjSIMcgAG7stnTlXYRWm 5ejRJ0D6s+x+sZ/8ZKoh99S40TQ2DmMfQbmRMpDypTwCeZWFao+6DuFCzqPdb6wwThes fBzw== 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 :message-id:date:subject:cc:to:from; bh=u5kk6vxj1qCOqN2yQ+ntIam7PBDCxmisc+WvKc4XgeA=; b=YpwSi09XepXrYE8DnaRBdRZ4u0lkxJ9w/HY5ZG79l/7gfFeVVpc/la5Bq8Ap1DP7my r+TbwrUO9WGIDul5GDrX1NZECp1vCTXMGY5/1LBV8BPxkjUHIn0a2U2JwW3xeJOzSejo 8i4AzmZ1zUYFG/j0enolmvWl9hvdv6UfW6GXz4M0EDqlN2wahsQA2UDWtQ0wMsgXmB/a yFKSbxXiZxywxxPhYZOWP3PVF+1u8r5xxDlArRZ9oA85WvZfrEtrSnWFLm9/YOl1ykbx P7iYo2EyNzLz5l5TKOVuW5k149zgl4yzC1fe0dx+iWKMZqvKKOHhar0XVQrfx/5zX83n IecA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=uniroma2.it Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w21-20020a056a0014d500b005106eb25aebsi6902795pfu.211.2022.06.08.03.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 03:23:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=uniroma2.it Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 375611BD8DB; Wed, 8 Jun 2022 02:52:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235316AbiFHJw3 (ORCPT + 99 others); Wed, 8 Jun 2022 05:52:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235545AbiFHJwO (ORCPT ); Wed, 8 Jun 2022 05:52:14 -0400 Received: from smtp.uniroma2.it (smtp.uniroma2.it [160.80.6.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5137B40FD2F; Wed, 8 Jun 2022 02:22:23 -0700 (PDT) Received: from localhost.localdomain ([160.80.103.126]) by smtp-2015.uniroma2.it (8.14.4/8.14.4/Debian-8) with ESMTP id 2589Jjp3001157 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 8 Jun 2022 11:19:45 +0200 From: Andrea Mayer To: "David S. Miller" , Hideaki YOSHIFUJI , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Stefano Salsano , Paolo Lungaroni , Ahmed Abdelsalam , Andrea Mayer , Anton Makarov Subject: [net] net: seg6: fix seg6_lookup_any_nexthop() to handle VRFs using flowi_l3mdev Date: Wed, 8 Jun 2022 11:19:17 +0200 Message-Id: <20220608091917.20345-1-andrea.mayer@uniroma2.it> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Virus-Scanned: clamav-milter 0.100.0 at smtp-2015 X-Virus-Status: Clean X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Commit 40867d74c374 ("net: Add l3mdev index to flow struct and avoid oif reset for port devices") adds a new entry (flowi_l3mdev) in the common flow struct used for indicating the l3mdev index for later rule and table matching. The l3mdev_update_flow() has been adapted to properly set the flowi_l3mdev based on the flowi_oif/flowi_iif. In fact, when a valid flowi_iif is supplied to the l3mdev_update_flow(), this function can update the flowi_l3mdev entry only if it has not yet been set (i.e., the flowi_l3mdev entry is equal to 0). The SRv6 End.DT6 behavior in VRF mode leverages a VRF device in order to force the routing lookup into the associated routing table. This routing operation is performed by seg6_lookup_any_nextop() preparing a flowi6 data structure used by ip6_route_input_lookup() which, in turn, (indirectly) invokes l3mdev_update_flow(). However, seg6_lookup_any_nexthop() does not initialize the new flowi_l3mdev entry which is filled with random garbage data. This prevents l3mdev_update_flow() from properly updating the flowi_l3mdev with the VRF index, and thus SRv6 End.DT6 (VRF mode)/DT46 behaviors are broken. This patch correctly initializes the flowi6 instance allocated and used by seg6_lookup_any_nexhtop(). Specifically, the entire flowi6 instance is wiped out: in case new entries are added to flowi/flowi6 (as happened with the flowi_l3mdev entry), we should no longer have incorrectly initialized values. As a result of this operation, the value of flowi_l3mdev is also set to 0. The proposed fix can be tested easily. Starting from the commit referenced in the Fixes, selftests [1],[2] indicate that the SRv6 End.DT6 (VRF mode)/DT46 behaviors no longer work correctly. By applying this patch, those behaviors are back to work properly again. [1] - tools/testing/selftests/net/srv6_end_dt46_l3vpn_test.sh [2] - tools/testing/selftests/net/srv6_end_dt6_l3vpn_test.sh Fixes: 40867d74c374 ("net: Add l3mdev index to flow struct and avoid oif reset for port devices") Reported-by: Anton Makarov Signed-off-by: Andrea Mayer --- net/ipv6/seg6_local.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c index 9fbe243a0e81..98a34287439c 100644 --- a/net/ipv6/seg6_local.c +++ b/net/ipv6/seg6_local.c @@ -218,6 +218,7 @@ seg6_lookup_any_nexthop(struct sk_buff *skb, struct in6_addr *nhaddr, struct flowi6 fl6; int dev_flags = 0; + memset(&fl6, 0, sizeof(fl6)); fl6.flowi6_iif = skb->dev->ifindex; fl6.daddr = nhaddr ? *nhaddr : hdr->daddr; fl6.saddr = hdr->saddr; -- 2.20.1