Skip to content

Commit 05ef705

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: fib: check correct rtable in vrf setups
We need to init l3mdev unconditionally, else main routing table is searched and incorrect result is returned unless strict (iif keyword) matching is requested. Next patch adds a selftest for this. Fixes: 2a8a7c0 ("netfilter: nft_fib: Fix for rpath check with VRF devices") Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1761 Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 0bfcb7b commit 05ef705

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

net/ipv4/netfilter/nft_fib_ipv4.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
6565
.flowi4_scope = RT_SCOPE_UNIVERSE,
6666
.flowi4_iif = LOOPBACK_IFINDEX,
6767
.flowi4_uid = sock_net_uid(nft_net(pkt), NULL),
68+
.flowi4_l3mdev = l3mdev_master_ifindex_rcu(nft_in(pkt)),
6869
};
6970
const struct net_device *oif;
7071
const struct net_device *found;
@@ -83,9 +84,6 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
8384
else
8485
oif = NULL;
8586

86-
if (priv->flags & NFTA_FIB_F_IIF)
87-
fl4.flowi4_l3mdev = l3mdev_master_ifindex_rcu(oif);
88-
8987
if (nft_hook(pkt) == NF_INET_PRE_ROUTING &&
9088
nft_fib_is_loopback(pkt->skb, nft_in(pkt))) {
9189
nft_fib_store_result(dest, priv, nft_in(pkt));

net/ipv6/netfilter/nft_fib_ipv6.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ static int nft_fib6_flowi_init(struct flowi6 *fl6, const struct nft_fib *priv,
4141
if (ipv6_addr_type(&fl6->daddr) & IPV6_ADDR_LINKLOCAL) {
4242
lookup_flags |= RT6_LOOKUP_F_IFACE;
4343
fl6->flowi6_oif = get_ifindex(dev ? dev : pkt->skb->dev);
44-
} else if (priv->flags & NFTA_FIB_F_IIF) {
45-
fl6->flowi6_l3mdev = l3mdev_master_ifindex_rcu(dev);
4644
}
4745

4846
if (ipv6_addr_type(&fl6->saddr) & IPV6_ADDR_UNICAST)
@@ -75,6 +73,8 @@ static u32 __nft_fib6_eval_type(const struct nft_fib *priv,
7573
else if (priv->flags & NFTA_FIB_F_OIF)
7674
dev = nft_out(pkt);
7775

76+
fl6.flowi6_l3mdev = l3mdev_master_ifindex_rcu(dev);
77+
7878
nft_fib6_flowi_init(&fl6, priv, pkt, dev, iph);
7979

8080
if (dev && nf_ipv6_chk_addr(nft_net(pkt), &fl6.daddr, dev, true))
@@ -165,6 +165,7 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs,
165165
.flowi6_iif = LOOPBACK_IFINDEX,
166166
.flowi6_proto = pkt->tprot,
167167
.flowi6_uid = sock_net_uid(nft_net(pkt), NULL),
168+
.flowi6_l3mdev = l3mdev_master_ifindex_rcu(nft_in(pkt)),
168169
};
169170
struct rt6_info *rt;
170171
int lookup_flags;

0 commit comments

Comments
 (0)