From patchwork Mon Oct 24 11:29:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9752 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp549393wru; Mon, 24 Oct 2022 09:43:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4EEgAac/WmDm8qFdvsy5xvqBHfgb11CJ8kSA84Z1m2eZpRfyDUHHEX4Hx9dm4SRsiHlIWt X-Received: by 2002:a63:e22:0:b0:458:cfe7:958 with SMTP id d34-20020a630e22000000b00458cfe70958mr28591088pgl.449.1666629832558; Mon, 24 Oct 2022 09:43:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666629832; cv=none; d=google.com; s=arc-20160816; b=FZmF80hqR7UnnDDGlzz/pl1me2/HRHm9I9Wd5BmKhav9IbIqSXgIuuu9cnvdXRAr7b 1gEs5Vm6FIPmcFszR9e3lr7bVy7RN4f4Gz2qPVFTir+5lh1eS/zQQswj2oUUvidn7f9I 34DY2+IP4wiw7YNjbVRpOW6WVqHBjW8IdW+rl48MgY+4XIDcwl4wniluXoP4MtaBKan+ 6LmQBahoKX9sjY2YB9hdRHw8fs1dKy20VlqtB0T/7E53LhLkZDaCS0iCe+KWXCyDVWjz ddUYpyJMH9SGFJIwWhMslFHf+7FIwlMQrCNb3nZJcH9jkKWqHQvnbkBQtfh/C0mJ8UGE +8Sw== 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=/5kKdIgWL5fiNVZMR7dh48z7BxzZDC3JQLRhwicDEXE=; b=eZkXzMkZUgTeHohm2p5zMWLnG2QhFF4EmKm7nk2Le+1qY8G46zbqiwsuRjkdy1BHAV n5JoLHH66G0FBfnN3Cz6kaeC0BbMtiqX/8P4hnJMiwsuqV3gbbz005XwgoqPB2RH4te/ NdVXEbTgHxkW5ZT7KD6252PPvLBRdtpKyL/XDJYARGEJVZTArtSXwzuEgbyZcZH9zKlW EDyu+l+w5UuIgENdTui3FpSJTCp+DGBNT1+9O3C3tuuXAbZ9e5VKOMTAUUfK37dLIxuN n/uu3sUam6GBAdcxPl2JUqu+nOzdrmqPl3Sh6Hnyju1hkLPxdJ3/pI9jrKcAx+cu65it UExA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QBgRQyzU; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i12-20020aa78d8c000000b00536bbfa4994si77001pfr.345.2022.10.24.09.43.40; Mon, 24 Oct 2022 09:43:52 -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=QBgRQyzU; 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 S231211AbiJXQnK (ORCPT + 99 others); Mon, 24 Oct 2022 12:43:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234635AbiJXQmP (ORCPT ); Mon, 24 Oct 2022 12:42:15 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4E11814D2; Mon, 24 Oct 2022 08:29:18 -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 ams.source.kernel.org (Postfix) with ESMTPS id 6DCB7B811B2; Mon, 24 Oct 2022 12:08:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDE3FC433D6; Mon, 24 Oct 2022 12:08:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613282; bh=L3nu73DTIBY+iOWWvmkHwnjOgqxSoPaiZ7zV+CQG90w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QBgRQyzUjefCjRL85fqAXrbKxLI9lzjwQ7PJ61d2l+zgVFKsvKTx8Kt7T3ze4W6Rt OmuLMQ2q+GwYP1/OrsCjJes8e/ZNJxP4FyoP1blslKlYHcR5it/yShhiKeN5dPblWP wn2VEl6dTc3rcij6sYrwMYa1uXushT4dYfN0Manw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Phil Sutter , Florian Westphal , Sasha Levin Subject: [PATCH 5.4 077/255] netfilter: nft_fib: Fix for rpath check with VRF devices Date: Mon, 24 Oct 2022 13:29:47 +0200 Message-Id: <20221024113005.068677117@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747588043430508556?= X-GMAIL-MSGID: =?utf-8?q?1747588043430508556?= From: Phil Sutter [ Upstream commit 2a8a7c0eaa8747c16aa4a48d573aa920d5c00a5c ] Analogous to commit b575b24b8eee3 ("netfilter: Fix rpfilter dropping vrf packets by mistake") but for nftables fib expression: Add special treatment of VRF devices so that typical reverse path filtering via 'fib saddr . iif oif' expression works as expected. Fixes: f6d0cbcf09c50 ("netfilter: nf_tables: add fib expression") Signed-off-by: Phil Sutter Signed-off-by: Florian Westphal Signed-off-by: Sasha Levin --- net/ipv4/netfilter/nft_fib_ipv4.c | 3 +++ net/ipv6/netfilter/nft_fib_ipv6.c | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/net/ipv4/netfilter/nft_fib_ipv4.c b/net/ipv4/netfilter/nft_fib_ipv4.c index ce294113dbcd..85eac5aa5204 100644 --- a/net/ipv4/netfilter/nft_fib_ipv4.c +++ b/net/ipv4/netfilter/nft_fib_ipv4.c @@ -83,6 +83,9 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs, else oif = NULL; + if (priv->flags & NFTA_FIB_F_IIF) + fl4.flowi4_oif = l3mdev_master_ifindex_rcu(oif); + if (nft_hook(pkt) == NF_INET_PRE_ROUTING && nft_fib_is_loopback(pkt->skb, nft_in(pkt))) { nft_fib_store_result(dest, priv, nft_in(pkt)); diff --git a/net/ipv6/netfilter/nft_fib_ipv6.c b/net/ipv6/netfilter/nft_fib_ipv6.c index 7ece86afd079..03dbd16f9ad5 100644 --- a/net/ipv6/netfilter/nft_fib_ipv6.c +++ b/net/ipv6/netfilter/nft_fib_ipv6.c @@ -37,6 +37,9 @@ static int nft_fib6_flowi_init(struct flowi6 *fl6, const struct nft_fib *priv, if (ipv6_addr_type(&fl6->daddr) & IPV6_ADDR_LINKLOCAL) { lookup_flags |= RT6_LOOKUP_F_IFACE; fl6->flowi6_oif = get_ifindex(dev ? dev : pkt->skb->dev); + } else if ((priv->flags & NFTA_FIB_F_IIF) && + (netif_is_l3_master(dev) || netif_is_l3_slave(dev))) { + fl6->flowi6_oif = dev->ifindex; } if (ipv6_addr_type(&fl6->saddr) & IPV6_ADDR_UNICAST) @@ -179,7 +182,8 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs, if (rt->rt6i_flags & (RTF_REJECT | RTF_ANYCAST | RTF_LOCAL)) goto put_rt_err; - if (oif && oif != rt->rt6i_idev->dev) + if (oif && oif != rt->rt6i_idev->dev && + l3mdev_master_ifindex_rcu(rt->rt6i_idev->dev) != oif->ifindex) goto put_rt_err; nft_fib_store_result(dest, priv, rt->rt6i_idev->dev);