Skip to contentSkip to conversation

Netfilter fixes for net

PATCH Applied Pablo Neira Ayuso 2 participants 8 messages Feb 10, 2022 – Feb 11, 2022

Subsystems (4)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

cover Netfilter fixes for net

Hi,

The following patchset contains Netfilter fixes for net:

1) Add selftest for nft_synproxy, from Florian Westphal.

2) xt_socket destroy path incorrectly disables IPv4 defrag for IPv6 traffic (typo), from Eric Dumazet.

3) Fix exit value selftest nft_concat_range.sh, from Hangbin Liu.

4) nft_synproxy disables the IPv4 hooks if the IPv6 hooks fail to be registered.

5) disable rp_filter on router in selftest nft_fib.sh, also from Hangbin Liu.

Please, pull these changes from:

git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git

Thanks.

----------------------------------------------------------------

The following changes since commit 7db788ad627aabff2b74d4f1a3b68516d0fee0d7:

nfp: flower: fix ida_idx not being released (2022-02-08 21:06:35 -0800)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git HEAD

for you to fetch changes up to bbe4c0896d25009a7c86285d2ab024eed4374eea:

selftests: netfilter: disable rp_filter on router (2022-02-11 00:01:04 +0100)

----------------------------------------------------------------
Eric Dumazet (1):
netfilter: xt_socket: fix a typo in socket_mt_destroy()

Florian Westphal (1):
selftests: netfilter: add synproxy test

Hangbin Liu (2):
selftests: netfilter: fix exit value for nft_concat_range
selftests: netfilter: disable rp_filter on router

Pablo Neira Ayuso (2):
netfilter: nft_synproxy: unregister hooks on init error path
selftests: netfilter: synproxy test requires nf_conntrack

 net/netfilter/nft_synproxy.c                       |   4 +-
 net/netfilter/xt_socket.c                          |   2 +-
 tools/testing/selftests/netfilter/Makefile         |   2 +-
 .../selftests/netfilter/nft_concat_range.sh        |   2 +-
 tools/testing/selftests/netfilter/nft_fib.sh       |   1 +
 tools/testing/selftests/netfilter/nft_synproxy.sh  | 117 +++++++++++++++++++++
 6 files changed, 124 insertions(+), 4 deletions(-)
 create mode 100755 tools/testing/selftests/netfilter/nft_synproxy.sh
author maintainer
#1 lore raw

PATCH 1/6 selftests: netfilter: add synproxy test

From: Florian Westphal <[email protected]>

Simple test for synproxy feature, iperf3 should be intercepted by synproxy netns, but connection should still succeed.

---
 tools/testing/selftests/netfilter/Makefile    |   2 +-
 .../selftests/netfilter/nft_synproxy.sh       | 115 ++++++++++++++++++
 2 files changed, 116 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/netfilter/nft_synproxy.sh
tools/testing/selftests/netfilter/Makefile +1 -1
index ffca314897c4..e4f845dd942b 100644
@@ -6,7 +6,7 @@ TEST_PROGS := nft_trans_stress.sh nft_fib.sh nft_nat.sh bridge_brouter.sh \
 	nft_concat_range.sh nft_conntrack_helper.sh \
 	nft_queue.sh nft_meta.sh nf_nat_edemux.sh \
 	ipip-conntrack-mtu.sh conntrack_tcp_unreplied.sh \
-	conntrack_vrf.sh
+	conntrack_vrf.sh nft_synproxy.sh
 
 LDLIBS = -lmnl
 TEST_GEN_FILES =  nf-queue
tools/testing/selftests/netfilter/nft_synproxy.sh new file +115 -0

115 lines not on this page · raw message

Signature · 1 line
2.30.2
#2 lore raw

Re: [PATCH net 1/6] selftests: netfilter: add synproxy test

This series was applied to netdev/net.git (master) by Pablo Neira Ayuso <[email protected]>:

Hello:

This series was applied to netdev/net.git (master) by Pablo Neira Ayuso <[email protected]>:

Quoted 9 lines · On Fri, 11 Feb 2022 00:10:16 +0100 you wrote:

From: Florian Westphal <[email protected]>

Simple test for synproxy feature, iperf3 should be intercepted by synproxy netns, but connection should still succeed.

[...]

Here is the summary with links:
- [net,1/6] selftests: netfilter: add synproxy test

    https://git.kernel.org/netdev/net/c/7152303cbec4
  - [net,2/6] netfilter: xt_socket: fix a typo in socket_mt_destroy()
    https://git.kernel.org/netdev/net/c/75063c9294fb
  - [net,3/6] selftests: netfilter: fix exit value for nft_concat_range
    https://git.kernel.org/netdev/net/c/2e71ec1a725a
  - [net,4/6] netfilter: nft_synproxy: unregister hooks on init error path
    https://git.kernel.org/netdev/net/c/2b4e5fb4d377
  - [net,5/6] selftests: netfilter: synproxy test requires nf_conntrack
    https://git.kernel.org/netdev/net/c/249749c88906
  - [net,6/6] selftests: netfilter: disable rp_filter on router
    https://git.kernel.org/netdev/net/c/bbe4c0896d25

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
author maintainer
#3 lore raw

PATCH 2/6 netfilter: xt_socket: fix a typo in socket_mt_destroy()

In reply to Pablo Neira Ayuso

From: Eric Dumazet <[email protected]>

Calling nf_defrag_ipv4_disable() instead of nf_defrag_ipv6_disable() was probably not the intent.

I found this by code inspection, while chasing a possible issue in TPROXY.

Fixes de8c12110a13 ("netfilter: disable defrag once its no longer needed")
---
 net/netfilter/xt_socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_socket.c +1 -1
index 5e6459e11605..662e5eb1cc39 100644
@@ -221,7 +221,7 @@ static void socket_mt_destroy(const struct xt_mtdtor_param *par)
 	if (par->family == NFPROTO_IPV4)
 		nf_defrag_ipv4_disable(par->net);
 	else if (par->family == NFPROTO_IPV6)
-		nf_defrag_ipv4_disable(par->net);
+		nf_defrag_ipv6_disable(par->net);
 }
 
 static struct xt_match socket_mt_reg[] __read_mostly = {
Signature · 1 line
2.30.2
author maintainer
#4 lore raw

PATCH 3/6 selftests: netfilter: fix exit value for nft_concat_range

In reply to Pablo Neira Ayuso

From: Hangbin Liu <[email protected]>

When the nft_concat_range test failed, it exit 1 in the code specifically.

But when part of, or all of the test passed, it will failed the [ ${passed} -eq 0 ] check and thus exit with 1, which is the same exit value with failure result. Fix it by exit 0 when passed is not 0.

Fixes 611973c1e06f ("selftests: netfilter: Introduce tests for sets with range concatenation")
---
 tools/testing/selftests/netfilter/nft_concat_range.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/netfilter/nft_concat_range.sh +1 -1
index df322e47a54f..b35010cc7f6a 100755
@@ -1601,4 +1601,4 @@ for name in ${TESTS}; do
 	done
 done
 
-[ ${passed} -eq 0 ] && exit ${KSELFTEST_SKIP}
+[ ${passed} -eq 0 ] && exit ${KSELFTEST_SKIP} || exit 0
Signature · 1 line
2.30.2
author maintainer
#5 lore raw

PATCH 4/6 netfilter: nft_synproxy: unregister hooks on init error path

In reply to Pablo Neira Ayuso

Disable the IPv4 hooks if the IPv6 hooks fail to be registered.

Fixes ad49d86e07a4 ("netfilter: nf_tables: Add synproxy support")
---
 net/netfilter/nft_synproxy.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/nft_synproxy.c +3 -1
index a0109fa1e92d..1133e06f3c40 100644
@@ -191,8 +191,10 @@ static int nft_synproxy_do_init(const struct nft_ctx *ctx,
 		if (err)
 			goto nf_ct_failure;
 		err = nf_synproxy_ipv6_init(snet, ctx->net);
-		if (err)
+		if (err) {
+			nf_synproxy_ipv4_fini(snet, ctx->net);
 			goto nf_ct_failure;
+		}
 		break;
 	}
 
Signature · 1 line
2.30.2
author maintainer
#6 lore raw

PATCH 5/6 selftests: netfilter: synproxy test requires nf_conntrack

In reply to Pablo Neira Ayuso

Otherwise, this test does not find the sysctl entry in place:

sysctl: cannot stat /proc/sys/net/netfilter/nf_conntrack_tcp_loose: No such file or directory
iperf3: error - unable to send control message: Bad file descriptor
FAIL: iperf3 returned an error

Fixes 7152303cbec4 ("selftests: netfilter: add synproxy test")
---
 tools/testing/selftests/netfilter/nft_synproxy.sh | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/netfilter/nft_synproxy.sh +2 -0
index 09bb95c87198..b62933b680d6 100755
@@ -23,6 +23,8 @@ checktool "ip -Version" "run test without ip tool"
 checktool "iperf3 --version" "run test without iperf3"
 checktool "ip netns add $nsr" "create net namespace"
 
+modprobe -q nf_conntrack
+
 ip netns add $ns1
 ip netns add $ns2
 
Signature · 1 line
2.30.2
author maintainer
#7 lore raw

PATCH 6/6 selftests: netfilter: disable rp_filter on router

In reply to Pablo Neira Ayuso

From: Hangbin Liu <[email protected]>

Some distros may enable rp_filter by default. After ns1 change addr to 10.0.2.99 and set default router to 10.0.2.1, while the connected router address is still 10.0.1.1. The router will not reply the arp request from ns1. Fix it by setting the router's veth0 rp_filter to 0.

Before the fix:

  # ./nft_fib.sh
  PASS: fib expression did not cause unwanted packet drops
  Netns nsrouter-HQkDORO2 fib counter doesn't match expected packet count of 1 for 1.1.1.1
  table inet filter {
          chain prerouting {
                  type filter hook prerouting priority filter; policy accept;
                  ip daddr 1.1.1.1 fib saddr . iif oif missing counter packets 0 bytes 0 drop
                  ip6 daddr 1c3::c01d fib saddr . iif oif missing counter packets 0 bytes 0 drop
          }
  }

After the fix:

  # ./nft_fib.sh
  PASS: fib expression did not cause unwanted packet drops
  PASS: fib expression did drop packets for 1.1.1.1
  PASS: fib expression did drop packets for 1c3::c01d
Fixes 82944421243e ("selftests: netfilter: add fib test case")
---
 tools/testing/selftests/netfilter/nft_fib.sh | 1 +
 1 file changed, 1 insertion(+)
tools/testing/selftests/netfilter/nft_fib.sh +1 -0
index 6caf6ac8c285..695a1958723f 100755
@@ -174,6 +174,7 @@ test_ping() {
 ip netns exec ${nsrouter} sysctl net.ipv6.conf.all.forwarding=1 > /dev/null
 ip netns exec ${nsrouter} sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null
 ip netns exec ${nsrouter} sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null
+ip netns exec ${nsrouter} sysctl net.ipv4.conf.veth0.rp_filter=0 > /dev/null
 
 sleep 3
 
Signature · 1 line
2.30.2