Skip to content

Commit efb056e

Browse files
Phil Sutterummakynes
authored andcommitted
netfilter: ip6t_rpfilter: Fix regression with VRF interfaces
When calling ip6_route_lookup() for the packet arriving on the VRF interface, the result is always the real (slave) interface. Expect this when validating the result. Fixes: acc641a ("netfilter: rpfilter/fib: Populate flowic_l3mdev field") Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent e6d57e9 commit efb056e

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

net/ipv6/netfilter/ip6t_rpfilter.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ static bool rpfilter_lookup_reverse6(struct net *net, const struct sk_buff *skb,
7272
goto out;
7373
}
7474

75-
if (rt->rt6i_idev->dev == dev || (flags & XT_RPFILTER_LOOSE))
75+
if (rt->rt6i_idev->dev == dev ||
76+
l3mdev_master_ifindex_rcu(rt->rt6i_idev->dev) == dev->ifindex ||
77+
(flags & XT_RPFILTER_LOOSE))
7678
ret = true;
7779
out:
7880
ip6_rt_put(rt);

tools/testing/selftests/netfilter/rpath.sh

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,16 @@ ip -net "$ns1" a a fec0:42::2/64 dev v0 nodad
6262
ip -net "$ns2" a a fec0:42::1/64 dev d0 nodad
6363

6464
# firewall matches to test
65-
[ -n "$iptables" ] && ip netns exec "$ns2" \
66-
"$iptables" -t raw -A PREROUTING -s 192.168.0.0/16 -m rpfilter
67-
[ -n "$ip6tables" ] && ip netns exec "$ns2" \
68-
"$ip6tables" -t raw -A PREROUTING -s fec0::/16 -m rpfilter
65+
[ -n "$iptables" ] && {
66+
common='-t raw -A PREROUTING -s 192.168.0.0/16'
67+
ip netns exec "$ns2" "$iptables" $common -m rpfilter
68+
ip netns exec "$ns2" "$iptables" $common -m rpfilter --invert
69+
}
70+
[ -n "$ip6tables" ] && {
71+
common='-t raw -A PREROUTING -s fec0::/16'
72+
ip netns exec "$ns2" "$ip6tables" $common -m rpfilter
73+
ip netns exec "$ns2" "$ip6tables" $common -m rpfilter --invert
74+
}
6975
[ -n "$nft" ] && ip netns exec "$ns2" $nft -f - <<EOF
7076
table inet t {
7177
chain c {
@@ -89,6 +95,11 @@ ipt_zero_rule() { # (command)
8995
[ -n "$1" ] || return 0
9096
ip netns exec "$ns2" "$1" -t raw -vS | grep -q -- "-m rpfilter -c 0 0"
9197
}
98+
ipt_zero_reverse_rule() { # (command)
99+
[ -n "$1" ] || return 0
100+
ip netns exec "$ns2" "$1" -t raw -vS | \
101+
grep -q -- "-m rpfilter --invert -c 0 0"
102+
}
92103
nft_zero_rule() { # (family)
93104
[ -n "$nft" ] || return 0
94105
ip netns exec "$ns2" "$nft" list chain inet t c | \
@@ -101,8 +112,7 @@ netns_ping() { # (netns, args...)
101112
ip netns exec "$netns" ping -q -c 1 -W 1 "$@" >/dev/null
102113
}
103114

104-
testrun() {
105-
# clear counters first
115+
clear_counters() {
106116
[ -n "$iptables" ] && ip netns exec "$ns2" "$iptables" -t raw -Z
107117
[ -n "$ip6tables" ] && ip netns exec "$ns2" "$ip6tables" -t raw -Z
108118
if [ -n "$nft" ]; then
@@ -111,6 +121,10 @@ testrun() {
111121
ip netns exec "$ns2" $nft -s list table inet t;
112122
) | ip netns exec "$ns2" $nft -f -
113123
fi
124+
}
125+
126+
testrun() {
127+
clear_counters
114128

115129
# test 1: martian traffic should fail rpfilter matches
116130
netns_ping "$ns1" -I v0 192.168.42.1 && \
@@ -120,9 +134,13 @@ testrun() {
120134

121135
ipt_zero_rule "$iptables" || die "iptables matched martian"
122136
ipt_zero_rule "$ip6tables" || die "ip6tables matched martian"
137+
ipt_zero_reverse_rule "$iptables" && die "iptables not matched martian"
138+
ipt_zero_reverse_rule "$ip6tables" && die "ip6tables not matched martian"
123139
nft_zero_rule ip || die "nft IPv4 matched martian"
124140
nft_zero_rule ip6 || die "nft IPv6 matched martian"
125141

142+
clear_counters
143+
126144
# test 2: rpfilter match should pass for regular traffic
127145
netns_ping "$ns1" 192.168.23.1 || \
128146
die "regular ping 192.168.23.1 failed"
@@ -131,6 +149,8 @@ testrun() {
131149

132150
ipt_zero_rule "$iptables" && die "iptables match not effective"
133151
ipt_zero_rule "$ip6tables" && die "ip6tables match not effective"
152+
ipt_zero_reverse_rule "$iptables" || die "iptables match over-effective"
153+
ipt_zero_reverse_rule "$ip6tables" || die "ip6tables match over-effective"
134154
nft_zero_rule ip && die "nft IPv4 match not effective"
135155
nft_zero_rule ip6 && die "nft IPv6 match not effective"
136156

0 commit comments

Comments
 (0)