Skip to content

Commit 33d12dc

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf
Pablo Neira Ayuso says: ==================== Netfilter fixes for net 1) Remove leftovers from flowtable modules, from Geert Uytterhoeven. 2) Missing refcount increment of conntrack template in nft_ct, from Florian Westphal. 3) Reduce nft_zone selftest time, also from Florian. 4) Add selftest to cover stateless NAT on fragments, from Florian Westphal. 5) Do not set net_device when for reject packets from the bridge path, from Phil Sutter. 6) Cancel register tracking info on nft_byteorder operations. 7) Extend nft_concat_range selftest to cover set reload with no elements, from Florian Westphal. 8) Remove useless update of pointer in chain blob builder, reported by kbuild test robot. * git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf: netfilter: nf_tables: remove assignment with no effect in chain blob builder selftests: nft_concat_range: add test for reload with no element add/del netfilter: nft_byteorder: track register operations netfilter: nft_reject_bridge: Fix for missing reply from prerouting selftests: netfilter: check stateless nat udp checksum fixup selftests: netfilter: reduce zone stress test running time netfilter: nft_ct: fix use after free when attaching zone template netfilter: Remove flowtable relics ==================== Link: https://lore.kernel.org/r/20220127235235.656931-1-pablo@netfilter.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 5aac910 + b07f413 commit 33d12dc

File tree

11 files changed

+249
-24
lines changed

11 files changed

+249
-24
lines changed

net/bridge/netfilter/nft_reject_bridge.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void nft_reject_br_send_v4_tcp_reset(struct net *net,
4949
{
5050
struct sk_buff *nskb;
5151

52-
nskb = nf_reject_skb_v4_tcp_reset(net, oldskb, dev, hook);
52+
nskb = nf_reject_skb_v4_tcp_reset(net, oldskb, NULL, hook);
5353
if (!nskb)
5454
return;
5555

@@ -65,7 +65,7 @@ static void nft_reject_br_send_v4_unreach(struct net *net,
6565
{
6666
struct sk_buff *nskb;
6767

68-
nskb = nf_reject_skb_v4_unreach(net, oldskb, dev, hook, code);
68+
nskb = nf_reject_skb_v4_unreach(net, oldskb, NULL, hook, code);
6969
if (!nskb)
7070
return;
7171

@@ -81,7 +81,7 @@ static void nft_reject_br_send_v6_tcp_reset(struct net *net,
8181
{
8282
struct sk_buff *nskb;
8383

84-
nskb = nf_reject_skb_v6_tcp_reset(net, oldskb, dev, hook);
84+
nskb = nf_reject_skb_v6_tcp_reset(net, oldskb, NULL, hook);
8585
if (!nskb)
8686
return;
8787

@@ -98,7 +98,7 @@ static void nft_reject_br_send_v6_unreach(struct net *net,
9898
{
9999
struct sk_buff *nskb;
100100

101-
nskb = nf_reject_skb_v6_unreach(net, oldskb, dev, hook, code);
101+
nskb = nf_reject_skb_v6_unreach(net, oldskb, NULL, hook, code);
102102
if (!nskb)
103103
return;
104104

net/ipv4/netfilter/Kconfig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ config NF_TABLES_ARP
5858

5959
endif # NF_TABLES
6060

61-
config NF_FLOW_TABLE_IPV4
62-
tristate
63-
select NF_FLOW_TABLE_INET
64-
6561
config NF_DUP_IPV4
6662
tristate "Netfilter IPv4 packet duplication to alternate destination"
6763
depends on !NF_CONNTRACK || NF_CONNTRACK

net/ipv6/netfilter/Kconfig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ config NFT_FIB_IPV6
4747
endif # NF_TABLES_IPV6
4848
endif # NF_TABLES
4949

50-
config NF_FLOW_TABLE_IPV6
51-
tristate
52-
select NF_FLOW_TABLE_INET
53-
5450
config NF_DUP_IPV6
5551
tristate "Netfilter IPv6 packet duplication to alternate destination"
5652
depends on !NF_CONNTRACK || NF_CONNTRACK

net/ipv6/netfilter/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ obj-$(CONFIG_NFT_REJECT_IPV6) += nft_reject_ipv6.o
2828
obj-$(CONFIG_NFT_DUP_IPV6) += nft_dup_ipv6.o
2929
obj-$(CONFIG_NFT_FIB_IPV6) += nft_fib_ipv6.o
3030

31-
# flow table support
32-
obj-$(CONFIG_NF_FLOW_TABLE_IPV6) += nf_flow_table_ipv6.o
33-
3431
# matches
3532
obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o
3633
obj-$(CONFIG_IP6_NF_MATCH_EUI64) += ip6t_eui64.o

net/ipv6/netfilter/nf_flow_table_ipv6.c

Whitespace-only changes.

net/netfilter/nf_tables_api.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,6 @@ static void nft_last_rule(struct nft_rule_blob *blob, const void *ptr)
20112011

20122012
prule = (struct nft_rule_dp *)ptr;
20132013
prule->is_last = 1;
2014-
ptr += offsetof(struct nft_rule_dp, data);
20152014
/* blob size does not include the trailer rule */
20162015
}
20172016

net/netfilter/nft_byteorder.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,24 @@ static int nft_byteorder_dump(struct sk_buff *skb, const struct nft_expr *expr)
167167
return -1;
168168
}
169169

170+
static bool nft_byteorder_reduce(struct nft_regs_track *track,
171+
const struct nft_expr *expr)
172+
{
173+
struct nft_byteorder *priv = nft_expr_priv(expr);
174+
175+
track->regs[priv->dreg].selector = NULL;
176+
track->regs[priv->dreg].bitwise = NULL;
177+
178+
return false;
179+
}
180+
170181
static const struct nft_expr_ops nft_byteorder_ops = {
171182
.type = &nft_byteorder_type,
172183
.size = NFT_EXPR_SIZE(sizeof(struct nft_byteorder)),
173184
.eval = nft_byteorder_eval,
174185
.init = nft_byteorder_init,
175186
.dump = nft_byteorder_dump,
187+
.reduce = nft_byteorder_reduce,
176188
};
177189

178190
struct nft_expr_type nft_byteorder_type __read_mostly = {

net/netfilter/nft_ct.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,12 @@ static void nft_ct_set_zone_eval(const struct nft_expr *expr,
260260
ct = this_cpu_read(nft_ct_pcpu_template);
261261

262262
if (likely(refcount_read(&ct->ct_general.use) == 1)) {
263+
refcount_inc(&ct->ct_general.use);
263264
nf_ct_zone_add(ct, &zone);
264265
} else {
265-
/* previous skb got queued to userspace */
266+
/* previous skb got queued to userspace, allocate temporary
267+
* one until percpu template can be reused.
268+
*/
266269
ct = nf_ct_tmpl_alloc(nft_net(pkt), &zone, GFP_ATOMIC);
267270
if (!ct) {
268271
regs->verdict.code = NF_DROP;

tools/testing/selftests/netfilter/nft_concat_range.sh

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ TYPES="net_port port_net net6_port port_proto net6_port_mac net6_port_mac_proto
2727
net6_port_net6_port net_port_mac_proto_net"
2828

2929
# Reported bugs, also described by TYPE_ variables below
30-
BUGS="flush_remove_add"
30+
BUGS="flush_remove_add reload"
3131

3232
# List of possible paths to pktgen script from kernel tree for performance tests
3333
PKTGEN_SCRIPT_PATHS="
@@ -354,6 +354,23 @@ TYPE_flush_remove_add="
354354
display Add two elements, flush, re-add
355355
"
356356

357+
TYPE_reload="
358+
display net,mac with reload
359+
type_spec ipv4_addr . ether_addr
360+
chain_spec ip daddr . ether saddr
361+
dst addr4
362+
src mac
363+
start 1
364+
count 1
365+
src_delta 2000
366+
tools sendip nc bash
367+
proto udp
368+
369+
race_repeat 0
370+
371+
perf_duration 0
372+
"
373+
357374
# Set template for all tests, types and rules are filled in depending on test
358375
set_template='
359376
flush ruleset
@@ -1473,6 +1490,59 @@ test_bug_flush_remove_add() {
14731490
nft flush ruleset
14741491
}
14751492

1493+
# - add ranged element, check that packets match it
1494+
# - reload the set, check packets still match
1495+
test_bug_reload() {
1496+
setup veth send_"${proto}" set || return ${KSELFTEST_SKIP}
1497+
rstart=${start}
1498+
1499+
range_size=1
1500+
for i in $(seq "${start}" $((start + count))); do
1501+
end=$((start + range_size))
1502+
1503+
# Avoid negative or zero-sized port ranges
1504+
if [ $((end / 65534)) -gt $((start / 65534)) ]; then
1505+
start=${end}
1506+
end=$((end + 1))
1507+
fi
1508+
srcstart=$((start + src_delta))
1509+
srcend=$((end + src_delta))
1510+
1511+
add "$(format)" || return 1
1512+
range_size=$((range_size + 1))
1513+
start=$((end + range_size))
1514+
done
1515+
1516+
# check kernel does allocate pcpu sctrach map
1517+
# for reload with no elemet add/delete
1518+
( echo flush set inet filter test ;
1519+
nft list set inet filter test ) | nft -f -
1520+
1521+
start=${rstart}
1522+
range_size=1
1523+
1524+
for i in $(seq "${start}" $((start + count))); do
1525+
end=$((start + range_size))
1526+
1527+
# Avoid negative or zero-sized port ranges
1528+
if [ $((end / 65534)) -gt $((start / 65534)) ]; then
1529+
start=${end}
1530+
end=$((end + 1))
1531+
fi
1532+
srcstart=$((start + src_delta))
1533+
srcend=$((end + src_delta))
1534+
1535+
for j in $(seq ${start} $((range_size / 2 + 1)) ${end}); do
1536+
send_match "${j}" $((j + src_delta)) || return 1
1537+
done
1538+
1539+
range_size=$((range_size + 1))
1540+
start=$((end + range_size))
1541+
done
1542+
1543+
nft flush ruleset
1544+
}
1545+
14761546
test_reported_issues() {
14771547
eval test_bug_"${subtest}"
14781548
}

tools/testing/selftests/netfilter/nft_nat.sh

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,144 @@ EOF
899899
ip netns exec "$ns0" nft delete table $family nat
900900
}
901901

902+
test_stateless_nat_ip()
903+
{
904+
local lret=0
905+
906+
ip netns exec "$ns0" sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null
907+
ip netns exec "$ns0" sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null
908+
909+
ip netns exec "$ns2" ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
910+
if [ $? -ne 0 ] ; then
911+
echo "ERROR: cannot ping $ns1 from $ns2 before loading stateless rules"
912+
return 1
913+
fi
914+
915+
ip netns exec "$ns0" nft -f /dev/stdin <<EOF
916+
table ip stateless {
917+
map xlate_in {
918+
typeof meta iifname . ip saddr . ip daddr : ip daddr
919+
elements = {
920+
"veth1" . 10.0.2.99 . 10.0.1.99 : 10.0.2.2,
921+
}
922+
}
923+
map xlate_out {
924+
typeof meta iifname . ip saddr . ip daddr : ip daddr
925+
elements = {
926+
"veth0" . 10.0.1.99 . 10.0.2.2 : 10.0.2.99
927+
}
928+
}
929+
930+
chain prerouting {
931+
type filter hook prerouting priority -400; policy accept;
932+
ip saddr set meta iifname . ip saddr . ip daddr map @xlate_in
933+
ip daddr set meta iifname . ip saddr . ip daddr map @xlate_out
934+
}
935+
}
936+
EOF
937+
if [ $? -ne 0 ]; then
938+
echo "SKIP: Could not add ip statless rules"
939+
return $ksft_skip
940+
fi
941+
942+
reset_counters
943+
944+
ip netns exec "$ns2" ping -q -c 1 10.0.1.99 > /dev/null # ping ns2->ns1
945+
if [ $? -ne 0 ] ; then
946+
echo "ERROR: cannot ping $ns1 from $ns2 with stateless rules"
947+
lret=1
948+
fi
949+
950+
# ns1 should have seen packets from .2.2, due to stateless rewrite.
951+
expect="packets 1 bytes 84"
952+
cnt=$(ip netns exec "$ns1" nft list counter inet filter ns0insl | grep -q "$expect")
953+
if [ $? -ne 0 ]; then
954+
bad_counter "$ns1" ns0insl "$expect" "test_stateless 1"
955+
lret=1
956+
fi
957+
958+
for dir in "in" "out" ; do
959+
cnt=$(ip netns exec "$ns2" nft list counter inet filter ns1${dir} | grep -q "$expect")
960+
if [ $? -ne 0 ]; then
961+
bad_counter "$ns2" ns1$dir "$expect" "test_stateless 2"
962+
lret=1
963+
fi
964+
done
965+
966+
# ns1 should not have seen packets from ns2, due to masquerade
967+
expect="packets 0 bytes 0"
968+
for dir in "in" "out" ; do
969+
cnt=$(ip netns exec "$ns1" nft list counter inet filter ns2${dir} | grep -q "$expect")
970+
if [ $? -ne 0 ]; then
971+
bad_counter "$ns1" ns0$dir "$expect" "test_stateless 3"
972+
lret=1
973+
fi
974+
975+
cnt=$(ip netns exec "$ns0" nft list counter inet filter ns1${dir} | grep -q "$expect")
976+
if [ $? -ne 0 ]; then
977+
bad_counter "$ns0" ns1$dir "$expect" "test_stateless 4"
978+
lret=1
979+
fi
980+
done
981+
982+
reset_counters
983+
984+
socat -h > /dev/null 2>&1
985+
if [ $? -ne 0 ];then
986+
echo "SKIP: Could not run stateless nat frag test without socat tool"
987+
if [ $lret -eq 0 ]; then
988+
return $ksft_skip
989+
fi
990+
991+
ip netns exec "$ns0" nft delete table ip stateless
992+
return $lret
993+
fi
994+
995+
local tmpfile=$(mktemp)
996+
dd if=/dev/urandom of=$tmpfile bs=4096 count=1 2>/dev/null
997+
998+
local outfile=$(mktemp)
999+
ip netns exec "$ns1" timeout 3 socat -u UDP4-RECV:4233 OPEN:$outfile < /dev/null &
1000+
sc_r=$!
1001+
1002+
sleep 1
1003+
# re-do with large ping -> ip fragmentation
1004+
ip netns exec "$ns2" timeout 3 socat - UDP4-SENDTO:"10.0.1.99:4233" < "$tmpfile" > /dev/null
1005+
if [ $? -ne 0 ] ; then
1006+
echo "ERROR: failed to test udp $ns1 to $ns2 with stateless ip nat" 1>&2
1007+
lret=1
1008+
fi
1009+
1010+
wait
1011+
1012+
cmp "$tmpfile" "$outfile"
1013+
if [ $? -ne 0 ]; then
1014+
ls -l "$tmpfile" "$outfile"
1015+
echo "ERROR: in and output file mismatch when checking udp with stateless nat" 1>&2
1016+
lret=1
1017+
fi
1018+
1019+
rm -f "$tmpfile" "$outfile"
1020+
1021+
# ns1 should have seen packets from 2.2, due to stateless rewrite.
1022+
expect="packets 3 bytes 4164"
1023+
cnt=$(ip netns exec "$ns1" nft list counter inet filter ns0insl | grep -q "$expect")
1024+
if [ $? -ne 0 ]; then
1025+
bad_counter "$ns1" ns0insl "$expect" "test_stateless 5"
1026+
lret=1
1027+
fi
1028+
1029+
ip netns exec "$ns0" nft delete table ip stateless
1030+
if [ $? -ne 0 ]; then
1031+
echo "ERROR: Could not delete table ip stateless" 1>&2
1032+
lret=1
1033+
fi
1034+
1035+
test $lret -eq 0 && echo "PASS: IP statless for $ns2"
1036+
1037+
return $lret
1038+
}
1039+
9021040
# ip netns exec "$ns0" ping -c 1 -q 10.0.$i.99
9031041
for i in 0 1 2; do
9041042
ip netns exec ns$i-$sfx nft -f /dev/stdin <<EOF
@@ -965,6 +1103,19 @@ table inet filter {
9651103
EOF
9661104
done
9671105

1106+
# special case for stateless nat check, counter needs to
1107+
# be done before (input) ip defragmentation
1108+
ip netns exec ns1-$sfx nft -f /dev/stdin <<EOF
1109+
table inet filter {
1110+
counter ns0insl {}
1111+
1112+
chain pre {
1113+
type filter hook prerouting priority -400; policy accept;
1114+
ip saddr 10.0.2.2 counter name "ns0insl"
1115+
}
1116+
}
1117+
EOF
1118+
9681119
sleep 3
9691120
# test basic connectivity
9701121
for i in 1 2; do
@@ -1019,6 +1170,7 @@ $test_inet_nat && test_redirect inet
10191170
$test_inet_nat && test_redirect6 inet
10201171

10211172
test_port_shadowing
1173+
test_stateless_nat_ip
10221174

10231175
if [ $ret -ne 0 ];then
10241176
echo -n "FAIL: "

0 commit comments

Comments
 (0)