]> git.baikalelectronics.ru Git - kernel.git/commitdiff
netfilter: nft_fib: Fix for rpath check with VRF devices
authorPhil Sutter <phil@nwl.cc>
Wed, 21 Sep 2022 11:07:31 +0000 (13:07 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Oct 2022 11:22:25 +0000 (13:22 +0200)
[ Upstream commit 447714c7b36ff1079380e5f5f2f71346fb58ebb4 ]

Analogous to commit c5dfc36d390e7 ("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: 5b1de3fa6d053 ("netfilter: nf_tables: add fib expression")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/ipv4/netfilter/nft_fib_ipv4.c
net/ipv6/netfilter/nft_fib_ipv6.c

index ce294113dbcd2362fa965741eeb23b3d01ccb41f..85eac5aa52045c479e0d929a8c0c1f931f8d1b18 100644 (file)
@@ -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));
index 7ece86afd079c46aa1490412c35db8b6f5fbd771..03dbd16f9ad5317c10d6428f97f4556b2f18239f 100644 (file)
@@ -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);