Netfilter fixes for net
Subsystems (5)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi,
The following patchset contains Netfilter fixes for net:
Patch #1 and #2 handle an esoteric scenario: Given two tasks sending UDP packets to one another, two packets of the same flow in each direction handled by different CPUs that result in two conntrack objects in NEW state, where reply packet loses race. Then, patch #3 adds a testcase for this scenario. Series from Florian Westphal.
1) NAT engine can falsely detect a port collision if it happens to pick up a reply packet as NEW rather than ESTABLISHED. Add extra code to detect this and suppress port reallocation in this case.
2) To complete the clash resolution in the reply direction, extend conntrack logic to detect clashing conntrack in the reply direction to existing entry.
3) Adds a test case.
Then, an assorted list of fixes follow:
4) Add a selftest for tproxy, from Antonio Ojea.
5) Guard ctnetlink_*_size() functions under
#if defined(CONFIG_NETFILTER_NETLINK_GLUE_CT) || defined(CONFIG_NF_CONNTRACK_EVENTS) From Andy Shevchenko.
6) Use -m socket --transparent in iptables tproxy documentation. From XIE Zhibang.
7) Call kfree_rcu() when releasing flowtable hooks to address race with netlink dump path, from Phil Sutter.
8) Fix compilation warning in nf_reject with CONFIG_BRIDGE_NETFILTER=n. From Simon Horman.
9) Guard ctnetlink_label_size() under CONFIG_NF_CONNTRACK_EVENTS which is its only user, to address a compilation warning. From Simon Horman.
10) Use rcu-protected list iteration over basechain hooks from netlink dump path.
11) Fix memcg for nf_tables, use GFP_KERNEL_ACCOUNT is not complete.
12) Remove old nfqueue conntrack clash resolution. Instead trying to use same destination address consistently which requires double DNAT, use the existing clash resolution which allows clashing packets go through with different destination. Antonio Ojea originally reported an issue from the postrouting chain, I proposed a fix:
https://lore.kernel.org/netfilter-devel/ZuwSwAqKgCB2a51-@calendula/T/
which he reported it did not work for him.
13) Adds a selftest for patch 12.
14) Fixes ipvs.sh selftest.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-24-09-24
Thanks.
----------------------------------------------------------------
The following changes since commit 9410645520e9b820069761f3450ef6661418e279:
Merge tag 'net-next-6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next (2024-09-16 06:02:27 +0200)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git tags/nf-24-09-24
for you to fetch changes up to 69021d3bc01c72c3315ea541062351a623b72c8f:
selftests: netfilter: Avoid hanging ipvs.sh (2024-09-19 14:54:10 +0200)
----------------------------------------------------------------
netfilter pull request 24-09-24
----------------------------------------------------------------
Andy Shevchenko (1):
netfilter: ctnetlink: Guard possible unused functions
Antonio Ojea (1):
selftests: netfilter: nft_tproxy.sh: add tcp tests
Florian Westphal (5):
netfilter: nf_nat: don't try nat source port reallocation for reverse dir clash
netfilter: conntrack: add clash resolution for reverse collisions
selftests: netfilter: add reverse-clash resolution test case
netfilter: nfnetlink_queue: remove old clash resolution logic
kselftest: add test for nfqueue induced conntrack race
Pablo Neira Ayuso (2):
netfilter: nf_tables: use rcu chain hook list iterator from netlink dump path
netfilter: nf_tables: missing objects with no memcg accounting
Phil Sutter (2):
netfilter: nf_tables: Keep deleted flowtable hooks until after RCU
selftests: netfilter: Avoid hanging ipvs.sh
Simon Horman (2):
netfilter: nf_reject: Fix build warning when CONFIG_BRIDGE_NETFILTER=n
netfilter: ctnetlink: compile ctnetlink_label_size with CONFIG_NF_CONNTRACK_EVENTS
谢致邦 (XIE Zhibang) (1):
docs: tproxy: ignore non-transparent sockets in iptables
Documentation/networking/tproxy.rst | 2 +- include/linux/netfilter.h | 4 - net/ipv4/netfilter/nf_reject_ipv4.c | 10 +- net/ipv6/netfilter/nf_reject_ipv6.c | 5 +- net/netfilter/nf_conntrack_core.c | 141 +++----- net/netfilter/nf_conntrack_netlink.c | 9 +- net/netfilter/nf_nat_core.c | 121 ++++++- net/netfilter/nf_tables_api.c | 6 +- net/netfilter/nft_compat.c | 6 +- net/netfilter/nft_log.c | 2 +- net/netfilter/nft_meta.c | 2 +- net/netfilter/nft_numgen.c | 2 +- net/netfilter/nft_set_pipapo.c | 13 +- net/netfilter/nft_tunnel.c | 5 +- tools/testing/selftests/net/netfilter/Makefile | 4 + tools/testing/selftests/net/netfilter/config | 1 + .../net/netfilter/conntrack_reverse_clash.c | 125 +++++++ .../net/netfilter/conntrack_reverse_clash.sh | 51 +++ tools/testing/selftests/net/netfilter/ipvs.sh | 2 +- tools/testing/selftests/net/netfilter/nft_queue.sh | 92 +++++- .../selftests/net/netfilter/nft_tproxy_tcp.sh | 358 +++++++++++++++++++++ .../selftests/net/netfilter/nft_tproxy_udp.sh | 262 +++++++++++++++ 22 files changed, 1091 insertions(+), 132 deletions(-) create mode 100644 tools/testing/selftests/net/netfilter/conntrack_reverse_clash.c create mode 100755 tools/testing/selftests/net/netfilter/conntrack_reverse_clash.sh create mode 100755 tools/testing/selftests/net/netfilter/nft_tproxy_tcp.sh create mode 100755 tools/testing/selftests/net/netfilter/nft_tproxy_udp.sh
Pablo Neira Ayuso
maintainerPATCH 1/14 netfilter: nf_nat: don't try nat source port reallocation for reverse dir clash
From: Florian Westphal <[email protected]>
A conntrack entry can be inserted to the connection tracking table if there is no existing entry with an identical tuple in either direction.
Example:
INITIATOR -> NAT/PAT -> RESPONDER
Initiator passes through NAT/PAT ("us") and SNAT is done (saddr rewrite). Then, later, NAT/PAT machine itself also wants to connect to RESPONDER.
This will not work if the SNAT done earlier has same IP:PORT source pair.
Conntrack table has:
ORIGINAL: $IP_INITATOR:$SPORT -> $IP_RESPONDER:$DPORT REPLY: $IP_RESPONDER:$DPORT -> $IP_NAT:$SPORT
and new locally originating connection wants:
ORIGINAL: $IP_NAT:$SPORT -> $IP_RESPONDER:$DPORT REPLY: $IP_RESPONDER:$DPORT -> $IP_NAT:$SPORT
This is handled by the NAT engine which will do a source port reallocation for the locally originating connection that is colliding with an existing tuple by attempting a source port rewrite.
This is done even if this new connection attempt did not go through a masquerade/snat rule.
There is a rare race condition with connection-less protocols like UDP, where we do the port reallocation even though its not needed.
This happens when new packets from the same, pre-existing flow are received in both directions at the exact same time on different CPUs after the conntrack table was flushed (or conntrack becomes active for first time).
With strict ordering/single cpu, the first packet creates new ct entry and second packet is resolved as established reply packet.
With parallel processing, both packets are picked up as new and both get their own ct entry.
In this case, the 'reply' packet (picked up as ORIGINAL) can be mangled by NAT engine because a port collision is detected.
This change isn't enough to prevent a packet drop later during nf_conntrack_confirm(), the existing clash resolution strategy will not detect such reverse clash case. This is resolved by a followup patch.
--- net/netfilter/nf_nat_core.c | 120 +++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 2 deletions(-)
net/netfilter/nf_nat_core.c +118 -2
@@ -183,7 +183,35 @@ hash_by_src(const struct net *net,return reciprocal_scale (hash, nf_nat_htable_size); } -/* Is this tuple already taken? (not by us) */ +/** +* nf_nat_used_tuple - check if proposed nat tuple clashes with existing entry +* @tuple: proposed NAT binding +* @ignored_conntrack: our (unconfirmed) conntrack entry +* +* A conntrack entry can be inserted to the connection tracking table +* if there is no existing entry with an identical tuple in either direction. +* +* Example: +* INITIATOR -> NAT/PAT -> RESPONDER +* +* INITIATOR passes through NAT/PAT ("us") and SNAT is done (saddr rewrite). +* Then, later, NAT/PAT itself also connects to RESPONDER. +* +* This will not work if the SNAT done earlier has same IP:PORT source pair. +* +* Conntrack table has: +* ORIGINAL: $IP_INITIATOR:$SPORT -> $IP_RESPONDER:$DPORT +* REPLY: $IP_RESPONDER:$DPORT -> $IP_NAT:$SPORT +* +* and new locally originating connection wants: +* ORIGINAL: $IP_NAT:$SPORT -> $IP_RESPONDER:$DPORT +* REPLY: $IP_RESPONDER:$DPORT -> $IP_NAT:$SPORT +* +* ... which would mean incoming packets cannot be distinguished between +* the existing and the newly added entry (identical IP_CT_DIR_REPLY tuple). +* +* Returns true if the proposed NAT mapping collides with an existing entry. +*/ static int nf_nat_used_tuple (const struct nf_conntrack_tuple *tuple,const struct nf_conn *ignored_conntrack)
@@ -200,6 +228,94 @@ nf_nat_used_tuple(const struct nf_conntrack_tuple *tuple,return nf_conntrack_tuple_taken (&reply, ignored_conntrack); } +static bool nf_nat_allow_clash (const struct nf_conn *ct) +{ +return nf_ct_l4proto_find (nf_ct_protonum (ct))->allow_clash; +} + +/** +* nf_nat_used_tuple_new - check if to-be-inserted conntrack collides with existing entry +* @tuple: proposed NAT binding +* @ignored_ct: our (unconfirmed) conntrack entry +* +* Same as nf_nat_used_tuple, but also check for rare clash in reverse +* direction. Should be called only when @tuple has not been altered, i.e. +* @ignored_conntrack will not be subject to NAT. +* +* Returns true if the proposed NAT mapping collides with existing entry. +*/ +static noinline bool +nf_nat_used_tuple_new (const struct nf_conntrack_tuple *tuple, +const struct nf_conn *ignored_ct) +{ +static const unsigned long uses_nat =IPS_NAT_MASK |IPS_SEQ_ADJUST_BIT ; +const struct nf_conntrack_tuple_hash *thash; +const struct nf_conntrack_zone *zone; +struct nf_conn *ct; +bool taken = true; +struct net *net; + +if (!nf_nat_used_tuple (tuple, ignored_ct)) +return false; + +if (!nf_nat_allow_clash (ignored_ct)) +return true; + +/* Initial choice clashes with existing conntrack. +* Check for (rare) reverse collision. +* +* This can happen when new packets are received in both directions +* at the exact same time on different CPUs. +* +* Without SMP, first packet creates new conntrack entry and second +* packet is resolved as established reply packet. +* +* With parallel processing, both packets could be picked up as +* new and both get their own ct entry allocated. +* +* If ignored_conntrack and colliding ct are not subject to NAT then +* pretend the tuple is available and let later clash resolution +* handle this at insertion time. +* +* Without it, the 'reply' packet has its source port rewritten +* by nat engine. +*/ +if (READ_ONCE (ignored_ct->status) & uses_nat) +return true; + + net =nf_ct_net (ignored_ct); + zone =nf_ct_zone (ignored_ct); + + thash =nf_conntrack_find_get (net, zone, tuple); +if (unlikely (!thash))/* clashing entry went away */ +return false; + + ct =nf_ct_tuplehash_to_ctrack (thash); + +/* NB: IP_CT_DIR_ORIGINAL should be impossible because +* nf_nat_used_tuple() handles origin collisions. +* +* Handle remote chance other CPU confirmed its ct right after. +*/ +if (thash->tuple.dst.dir !=IP_CT_DIR_REPLY ) + goto out; + +/* clashing connection subject to NAT? Retry with new tuple. */ +if (READ_ONCE (ct->status) & uses_nat) + goto out; + +if (nf_ct_tuple_equal (&ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple, + &ignored_ct->tuplehash[IP_CT_DIR_REPLY ].tuple) && +nf_ct_tuple_equal (&ct->tuplehash[IP_CT_DIR_REPLY ].tuple, + &ignored_ct->tuplehash[IP_CT_DIR_ORIGINAL ].tuple)) { + taken = false; + goto out; + } +out: +nf_ct_put (ct); +return taken; +} +static bool nf_nat_may_kill (struct nf_conn *ct,unsigned long flags) { static const unsigned long flags_refuse = IPS_FIXED_TIMEOUT |
@@ -611,7 +727,7 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple, !(range->flags & NF_NAT_RANGE_PROTO_RANDOM_ALL)) {/* try the original tuple first */ if (nf_in_range (orig_tuple, range)) { -if (!nf_nat_used_tuple (orig_tuple, ct)) { +if (!nf_nat_used_tuple_new (orig_tuple, ct)) { *tuple = *orig_tuple;return ; }
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 2/14 netfilter: conntrack: add clash resolution for reverse collisions
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Given existing entry:
ORIGIN: a:b -> c:d REPLY: c:d -> a:b
And colliding entry:
ORIGIN: c:d -> a:b REPLY: a:b -> c:d
The colliding ct (and the associated skb) get dropped on insert. Permit this by checking if the colliding entry matches the reply direction.
Happens when both ends send packets at same time, both requests are picked up as NEW, rather than NEW for the 'first' and 'ESTABLISHED' for the second packet.
This is an esoteric condition, as ruleset must permit NEW connections in either direction and both peers must already have a bidirectional traffic flow at the time conntrack gets enabled.
Allow the 'reverse' skb to pass and assign the existing (clashing) entry.
While at it, also drop the extra 'dying' check, this is already tested earlier by the calling function.
--- net/netfilter/nf_conntrack_core.c | 56 ++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 5 deletions(-)
net/netfilter/nf_conntrack_core.c +51 -5
@@ -988,6 +988,56 @@ static void __nf_conntrack_insert_prepare(struct nf_conn *ct) tstamp->start =ktime_get_real_ns (); } +/** +* nf_ct_match_reverse - check if ct1 and ct2 refer to identical flow +* @ct1: conntrack in hash table to check against +* @ct2: merge candidate +* +* returns true if ct1 and ct2 happen to refer to the same flow, but +* in opposing directions, i.e. +* ct1: a:b -> c:d +* ct2: c:d -> a:b +* for both directions. If so, @ct2 should not have been created +* as the skb should have been picked up as ESTABLISHED flow. +* But ct1 was not yet committed to hash table before skb that created +* ct2 had arrived. +* +* Note we don't compare netns because ct entries in different net +* namespace cannot clash to begin with. +* +* Returns true if ct1 and ct2 are identical when swapping origin/reply. +*/ +static bool +nf_ct_match_reverse (const struct nf_conn *ct1,const struct nf_conn *ct2) +{ +u16 id1, id2; + +if (!nf_ct_tuple_equal (&ct1->tuplehash[IP_CT_DIR_ORIGINAL ].tuple, + &ct2->tuplehash[IP_CT_DIR_REPLY ].tuple)) +return false; + +if (!nf_ct_tuple_equal (&ct1->tuplehash[IP_CT_DIR_REPLY ].tuple, + &ct2->tuplehash[IP_CT_DIR_ORIGINAL ].tuple)) +return false; + + id1 =nf_ct_zone_id (nf_ct_zone (ct1),IP_CT_DIR_ORIGINAL ); + id2 =nf_ct_zone_id (nf_ct_zone (ct2),IP_CT_DIR_REPLY ); +if (id1 != id2) +return false; + + id1 =nf_ct_zone_id (nf_ct_zone (ct1),IP_CT_DIR_REPLY ); + id2 =nf_ct_zone_id (nf_ct_zone (ct2),IP_CT_DIR_ORIGINAL ); + +return id1 == id2; +} + +static int nf_ct_can_merge (const struct nf_conn *ct, +const struct nf_conn *loser_ct) +{ +return nf_ct_match (ct, loser_ct) || +nf_ct_match_reverse (ct, loser_ct); +} +/* caller must hold locks to prevent concurrent changes */ static int __nf_ct_resolve_clash (struct sk_buff *skb,struct nf_conntrack_tuple_hash *h)
@@ -999,11 +1049,7 @@ static int __nf_ct_resolve_clash(struct sk_buff *skb, loser_ct =nf_ct_get (skb, &ctinfo); -if (nf_ct_is_dying (ct)) -return NF_DROP ; - -if (((ct->status &IPS_NAT_DONE_MASK ) ==0 ) || -nf_ct_match (ct, loser_ct)) { +if (nf_ct_can_merge (ct, loser_ct)) {struct net *net =nf_ct_net (ct);nf_conntrack_get (&ct->ct_general);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 3/14 selftests: netfilter: add reverse-clash resolution test case
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Add test program that is sending UDP packets in both directions and check that packets arrive without source port modification.
--- .../testing/selftests/net/netfilter/Makefile | 2 + .../net/netfilter/conntrack_reverse_clash.c | 125 ++++++++++++++++++ .../net/netfilter/conntrack_reverse_clash.sh | 51 +++++++ 3 files changed, 178 insertions(+) create mode 100644 tools/testing/selftests/net/netfilter/conntrack_reverse_clash.c create mode 100755 tools/testing/selftests/net/netfilter/conntrack_reverse_clash.sh
tools/testing/selftests/net/netfilter/Makefile +2 -0
@@ -13,6 +13,7 @@ TEST_PROGS += conntrack_ipip_mtu.sh TEST_PROGS += conntrack_tcp_unreplied.sh TEST_PROGS += conntrack_sctp_collision.sh TEST_PROGS += conntrack_vrf.sh +TEST_PROGS += conntrack_reverse_clash.sh TEST_PROGS += ipvs.sh TEST_PROGS += nf_conntrack_packetdrill.sh TEST_PROGS += nf_nat_edemux.sh
@@ -36,6 +37,7 @@ TEST_GEN_PROGS = conntrack_dump_flush TEST_GEN_FILES = audit_logread TEST_GEN_FILES += connect_close nf_queue +TEST_GEN_FILES += conntrack_reverse_clash TEST_GEN_FILES += sctp_collision include ../../lib.mk
tools/testing/selftests/net/netfilter/conntrack_reverse_clash.c new file +125 -0
125 lines not on this page · raw message
tools/testing/selftests/net/netfilter/conntrack_reverse_clash.sh new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 4/14 selftests: netfilter: nft_tproxy.sh: add tcp tests
In reply to Pablo Neira AyusoFrom: Antonio Ojea <[email protected]>
The TPROXY functionality is widely used, however, there are only mptcp selftests covering this feature.
The selftests represent the most common scenarios and can also be used as selfdocumentation of the feature.
UDP and TCP testcases are split in different files because of the different nature of the protocols, specially due to the challenges that present to reliable test UDP due to the connectionless nature of the protocol. UDP only covers the scenarios involving the prerouting hook.
The UDP tests are signfinicantly slower than the TCP ones, hence they use a larger timeout, it takes 20 seconds to run the full UDP suite on a 48 vCPU Intel(R) Xeon(R) CPU @2.60GHz.
--- .../testing/selftests/net/netfilter/Makefile | 2 + tools/testing/selftests/net/netfilter/config | 1 + .../selftests/net/netfilter/nft_tproxy_tcp.sh | 358 ++++++++++++++++++ .../selftests/net/netfilter/nft_tproxy_udp.sh | 262 +++++++++++++ 4 files changed, 623 insertions(+) create mode 100755 tools/testing/selftests/net/netfilter/nft_tproxy_tcp.sh create mode 100755 tools/testing/selftests/net/netfilter/nft_tproxy_udp.sh
tools/testing/selftests/net/netfilter/Makefile +2 -0
@@ -27,6 +27,8 @@ TEST_PROGS += nft_nat.sh TEST_PROGS += nft_nat_zones.sh TEST_PROGS += nft_queue.sh TEST_PROGS += nft_synproxy.sh +TEST_PROGS += nft_tproxy_tcp.sh +TEST_PROGS += nft_tproxy_udp.sh TEST_PROGS += nft_zones_many.sh TEST_PROGS += rpath.sh TEST_PROGS += xt_string.sh
tools/testing/selftests/net/netfilter/config +1 -0
@@ -81,6 +81,7 @@ CONFIG_NFT_QUEUE=m CONFIG_NFT_QUOTA=m CONFIG_NFT_REDIR=m CONFIG_NFT_SYNPROXY=m +CONFIG_NFT_TPROXY=m CONFIG_VETH=m CONFIG_VLAN_8021Q=m CONFIG_XFRM_USER=m
tools/testing/selftests/net/netfilter/nft_tproxy_tcp.sh new file +358 -0
358 lines not on this page · raw message
tools/testing/selftests/net/netfilter/nft_tproxy_udp.sh new file +262 -0
262 lines not on this page · raw message
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 5/14 netfilter: ctnetlink: Guard possible unused functions
In reply to Pablo Neira AyusoFrom: Andy Shevchenko <[email protected]>
Some of the functions may be unused (CONFIG_NETFILTER_NETLINK_GLUE_CT=n and CONFIG_NF_CONNTRACK_EVENTS=n), it prevents kernel builds with clang, make W=1 and CONFIG_WERROR=y:
net/netfilter/nf_conntrack_netlink.c:657:22: error: unused function 'ctnetlink_acct_size' [-Werror,-Wunused-function]
657 | static inline size_t ctnetlink_acct_size(const struct nf_conn *ct)
| ^~~~~~~~~~~~~~~~~~~
net/netfilter/nf_conntrack_netlink.c:667:19: error: unused function 'ctnetlink_secctx_size' [-Werror,-Wunused-function]
667 | static inline int ctnetlink_secctx_size(const struct nf_conn *ct)
| ^~~~~~~~~~~~~~~~~~~~~
net/netfilter/nf_conntrack_netlink.c:683:22: error: unused function 'ctnetlink_timestamp_size' [-Werror,-Wunused-function]
683 | static inline size_t ctnetlink_timestamp_size(const struct nf_conn *ct)
| ^~~~~~~~~~~~~~~~~~~~~~~~Fix this by guarding possible unused functions with ifdeffery.
See also commit 6863f5643dd7 ("kbuild: allow Clang to find unused static inline functions for W=1 build").
--- net/netfilter/nf_conntrack_netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_netlink.c +1 -1
@@ -652,7 +652,6 @@ static size_t ctnetlink_proto_size(const struct nf_conn *ct)return len + len4; } -#endif static inline size_t ctnetlink_acct_size (const struct nf_conn *ct) {
@@ -690,6 +689,7 @@ static inline size_t ctnetlink_timestamp_size(const struct nf_conn *ct)return 0 ; #endif } +#endif #ifdef CONFIG_NF_CONNTRACK_EVENTS static size_t ctnetlink_nlmsg_size (const struct nf_conn *ct)
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 6/14 docs: tproxy: ignore non-transparent sockets in iptables
In reply to Pablo Neira AyusoFrom: 谢致邦 (XIE Zhibang) <[email protected]>
The iptables example was added in commit d2f26037a38a (netfilter: Add documentation for tproxy, 2008-10-08), but xt_socket 'transparent' option was added in commit a31e1ffd2231 (netfilter: xt_socket: added new revision of the 'socket' match supporting flags, 2009-06-09).
Now add the 'transparent' option to the iptables example to ignore non-transparent sockets, which is also consistent with the nft example.
--- Documentation/networking/tproxy.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/networking/tproxy.rst +1 -1
@@ -17,7 +17,7 @@ The idea is that you identify packets with destination address matching a local socket on your box, set the packet mark to a certain value:: # iptables -t mangle -N DIVERT - # iptables -t mangle -A PREROUTING -p tcp -m socket -j DIVERT + # iptables -t mangle -A PREROUTING -p tcp -m socket --transparent -j DIVERT # iptables -t mangle -A DIVERT -j MARK --set-mark 1 # iptables -t mangle -A DIVERT -j ACCEPT
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 7/14 netfilter: nf_tables: Keep deleted flowtable hooks until after RCU
In reply to Pablo Neira AyusoFrom: Phil Sutter <[email protected]>
Documentation of list_del_rcu() warns callers to not immediately free the deleted list item. While it seems not necessary to use the RCU-variant of list_del() here in the first place, doing so seems to require calling kfree_rcu() on the deleted item as well.
--- net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +1 -1
@@ -9207,7 +9207,7 @@ static void nf_tables_flowtable_destroy(struct nft_flowtable *flowtable) flowtable->data.type->setup (&flowtable->data, hook->ops.dev,FLOW_BLOCK_UNBIND );list_del_rcu (&hook->list); -kfree (hook); +kfree_rcu (hook, rcu); }kfree (flowtable->name);module_put (flowtable->data.type->owner);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 8/14 netfilter: nf_reject: Fix build warning when CONFIG_BRIDGE_NETFILTER=n
In reply to Pablo Neira AyusoFrom: Simon Horman <[email protected]>
If CONFIG_BRIDGE_NETFILTER is not enabled, which is the case for x86_64 defconfig, then building nf_reject_ipv4.c and nf_reject_ipv6.c with W=1 using gcc-14 results in the following warnings, which are treated as errors:
net/ipv4/netfilter/nf_reject_ipv4.c: In function 'nf_send_reset':net/ipv4/netfilter/nf_reject_ipv4.c:243:23: error: variable 'niph' set but not used [-Werror=unused-but-set-variable]
243 | struct iphdr *niph;
| ^~~~
cc1: all warnings being treated as errorsnet/ipv6/netfilter/nf_reject_ipv6.c: In function 'nf_send_reset6':net/ipv6/netfilter/nf_reject_ipv6.c:286:25: error: variable 'ip6h' set but not used [-Werror=unused-but-set-variable]
286 | struct ipv6hdr *ip6h;
| ^~~~
cc1: all warnings being treated as errors
Address this by reducing the scope of these local variables to where they are used, which is code only compiled when CONFIG_BRIDGE_NETFILTER enabled.
Compile tested and run through netfilter selftests.
--- net/ipv4/netfilter/nf_reject_ipv4.c | 10 ++++------ net/ipv6/netfilter/nf_reject_ipv6.c | 5 ++--- 2 files changed, 6 insertions(+), 9 deletions(-)
net/ipv4/netfilter/nf_reject_ipv4.c +4 -6
@@ -239,9 +239,8 @@ static int nf_reject_fill_skb_dst(struct sk_buff *skb_in)void nf_send_reset (struct net *net,struct sock *sk,struct sk_buff *oldskb,int hook) { -struct sk_buff *nskb; -struct iphdr *niph;const struct tcphdr *oth; +struct sk_buff *nskb;struct tcphdr _oth; oth =nf_reject_ip_tcphdr_get (oldskb, &_oth, hook);
@@ -266,14 +265,12 @@ void nf_send_reset(struct net *net, struct sock *sk, struct sk_buff *oldskb, nskb->mark =IP4_REPLY_MARK (net, oldskb->mark);skb_reserve (nskb,LL_MAX_HEADER ); - niph =nf_reject_iphdr_put (nskb, oldskb,IPPROTO_TCP , -ip4_dst_hoplimit (skb_dst (nskb))); +nf_reject_iphdr_put (nskb, oldskb,IPPROTO_TCP , +ip4_dst_hoplimit (skb_dst (nskb)));nf_reject_ip_tcphdr_put (nskb, oldskb, oth);if (ip_route_me_harder (net, sk, nskb,RTN_UNSPEC )) goto free_nskb; - niph =ip_hdr (nskb); -/* "Never happens" */ if (nskb->len >dst_mtu (skb_dst (nskb))) goto free_nskb;
@@ -290,6 +287,7 @@ void nf_send_reset(struct net *net, struct sock *sk, struct sk_buff *oldskb,*/ if (nf_bridge_info_exists (oldskb)) {struct ethhdr *oeth =eth_hdr (oldskb); +struct iphdr *niph =ip_hdr (nskb);struct net_device *br_indev; br_indev =nf_bridge_get_physindev (oldskb, net);
net/ipv6/netfilter/nf_reject_ipv6.c +2 -3
@@ -283,7 +283,6 @@ void nf_send_reset6(struct net *net, struct sock *sk, struct sk_buff *oldskb,const struct tcphdr *otcph;unsigned int otcplen, hh_len;const struct ipv6hdr *oip6h =ipv6_hdr (oldskb); -struct ipv6hdr *ip6h;struct dst_entry *dst =NULL ;struct flowi6 fl6;
@@ -339,8 +338,7 @@ void nf_send_reset6(struct net *net, struct sock *sk, struct sk_buff *oldskb, nskb->mark = fl6.flowi6_mark;skb_reserve (nskb, hh_len + dst->header_len); - ip6h =nf_reject_ip6hdr_put (nskb, oldskb,IPPROTO_TCP , -ip6_dst_hoplimit (dst)); +nf_reject_ip6hdr_put (nskb, oldskb,IPPROTO_TCP ,ip6_dst_hoplimit (dst));nf_reject_ip6_tcphdr_put (nskb, oldskb, otcph, otcplen);nf_ct_attach (nskb, oldskb);
@@ -355,6 +353,7 @@ void nf_send_reset6(struct net *net, struct sock *sk, struct sk_buff *oldskb,*/ if (nf_bridge_info_exists (oldskb)) {struct ethhdr *oeth =eth_hdr (oldskb); +struct ipv6hdr *ip6h =ipv6_hdr (nskb);struct net_device *br_indev; br_indev =nf_bridge_get_physindev (oldskb, net);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 9/14 netfilter: ctnetlink: compile ctnetlink_label_size with CONFIG_NF_CONNTRACK_EVENTS
In reply to Pablo Neira AyusoFrom: Simon Horman <[email protected]>
Only provide ctnetlink_label_size when it is used, which is when CONFIG_NF_CONNTRACK_EVENTS is configured.
Flagged by clang-18 W=1 builds as:
.../nf_conntrack_netlink.c:385:19: warning: unused function 'ctnetlink_label_size' [-Wunused-function]
385 | static inline int ctnetlink_label_size(const struct nf_conn *ct)
| ^~~~~~~~~~~~~~~~~~~~
The condition on CONFIG_NF_CONNTRACK_LABELS being removed by this patch guards compilation of non-trivial implementations of ctnetlink_dump_labels() and ctnetlink_label_size().
However, this is not necessary as each of these functions will always return 0 if CONFIG_NF_CONNTRACK_LABELS is not defined as each function starts with the equivalent of:
struct nf_conn_labels *labels = nf_ct_labels_find(ct); if (!labels) return 0;
And nf_ct_labels_find always returns NULL if CONFIG_NF_CONNTRACK_LABELS is not enabled. So I believe that the compiler optimises the code away in such cases anyway.
Found by inspection.
Compile tested only.
Originally splitted in two patches, Pablo Neira Ayuso collapsed them and added Fixes: tag.
--- net/netfilter/nf_conntrack_netlink.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
net/netfilter/nf_conntrack_netlink.c +2 -5
@@ -382,7 +382,7 @@ static int ctnetlink_dump_secctx(struct sk_buff *skb, const struct nf_conn *ct)#define ctnetlink_dump_secctx (a, b) (0)#endif -#ifdef CONFIG_NF_CONNTRACK_LABELS +#ifdef CONFIG_NF_CONNTRACK_EVENTS static inline int ctnetlink_label_size (const struct nf_conn *ct) {struct nf_conn_labels *labels =nf_ct_labels_find (ct);
@@ -391,6 +391,7 @@ static inline int ctnetlink_label_size(const struct nf_conn *ct)return 0 ; return nla_total_size(sizeof(labels->bits)); } +#endif static int ctnetlink_dump_labels (struct sk_buff *skb,const struct nf_conn *ct)
@@ -411,10 +412,6 @@ ctnetlink_dump_labels(struct sk_buff *skb, const struct nf_conn *ct)return 0 ; } -#else -#define ctnetlink_dump_labels (a, b) (0) -#define ctnetlink_label_size (a) (0) -#endif #define master_tuple (ct) &(ct->master->tuplehash[IP_CT_DIR_ORIGINAL].tuple)
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 10/14 netfilter: nf_tables: use rcu chain hook list iterator from netlink dump path
In reply to Pablo Neira AyusoLockless iteration over hook list is possible from netlink dump path, use rcu variant to iterate over the hook list as is done with flowtable hooks.
--- net/netfilter/nf_tables_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_tables_api.c +1 -1
@@ -1849,7 +1849,7 @@ static int nft_dump_basechain_hook(struct sk_buff *skb, int family,if (!hook_list) hook_list = &basechain->hook_list; -list_for_each_entry (hook, hook_list, list) { +list_for_each_entry_rcu (hook, hook_list, list) {if (!first) first = hook;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 11/14 netfilter: nf_tables: missing objects with no memcg accounting
In reply to Pablo Neira AyusoSeveral ruleset objects are still not using GFP_KERNEL_ACCOUNT for memory accounting, update them. This includes:
- catchall elements
- compat match large info area
- log prefix
- meta secctx
- numgen counters
- pipapo set backend datastructure
- tunnel private objects
--- net/netfilter/nf_tables_api.c | 2 +- net/netfilter/nft_compat.c | 6 +++--- net/netfilter/nft_log.c | 2 +- net/netfilter/nft_meta.c | 2 +- net/netfilter/nft_numgen.c | 2 +- net/netfilter/nft_set_pipapo.c | 13 +++++++------ net/netfilter/nft_tunnel.c | 5 +++-- 7 files changed, 17 insertions(+), 15 deletions(-)
net/netfilter/nf_tables_api.c +1 -1
@@ -6684,7 +6684,7 @@ static int nft_setelem_catchall_insert(const struct net *net, } } - catchall =kmalloc (sizeof (*catchall),GFP_KERNEL ); + catchall =kmalloc (sizeof (*catchall),GFP_KERNEL_ACCOUNT );if (!catchall)return -ENOMEM ;
net/netfilter/nft_compat.c +3 -3
@@ -535,7 +535,7 @@ nft_match_large_init(const struct nft_ctx *ctx, const struct nft_expr *expr,struct xt_match *m = expr->ops->data;int ret; - priv->info =kmalloc (XT_ALIGN (m->matchsize),GFP_KERNEL ); + priv->info =kmalloc (XT_ALIGN (m->matchsize),GFP_KERNEL_ACCOUNT );if (!priv->info)return -ENOMEM ;
@@ -808,7 +808,7 @@ nft_match_select_ops(const struct nft_ctx *ctx, goto err; } - ops =kzalloc (sizeof (struct nft_expr_ops ),GFP_KERNEL ); + ops =kzalloc (sizeof (struct nft_expr_ops ),GFP_KERNEL_ACCOUNT );if (!ops) { err = -ENOMEM ; goto err;
@@ -898,7 +898,7 @@ nft_target_select_ops(const struct nft_ctx *ctx, goto err; } - ops =kzalloc (sizeof (struct nft_expr_ops ),GFP_KERNEL ); + ops =kzalloc (sizeof (struct nft_expr_ops ),GFP_KERNEL_ACCOUNT );if (!ops) { err = -ENOMEM ; goto err;
net/netfilter/nft_log.c +1 -1
@@ -163,7 +163,7 @@ static int nft_log_init(const struct nft_ctx *ctx, nla = tb[NFTA_LOG_PREFIX ];if (nla !=NULL ) { - priv->prefix =kmalloc (nla_len (nla) +1 ,GFP_KERNEL ); + priv->prefix =kmalloc (nla_len (nla) +1 ,GFP_KERNEL_ACCOUNT );if (priv->prefix ==NULL )return -ENOMEM ;nla_strscpy (priv->prefix, nla,nla_len (nla) +1 );
net/netfilter/nft_meta.c +1 -1
@@ -952,7 +952,7 @@ static int nft_secmark_obj_init(const struct nft_ctx *ctx,if (tb[NFTA_SECMARK_CTX ] ==NULL )return -EINVAL ; - priv->ctx =nla_strdup (tb[NFTA_SECMARK_CTX ],GFP_KERNEL ); + priv->ctx =nla_strdup (tb[NFTA_SECMARK_CTX ],GFP_KERNEL_ACCOUNT );if (!priv->ctx)return -ENOMEM ;
net/netfilter/nft_numgen.c +1 -1
@@ -66,7 +66,7 @@ static int nft_ng_inc_init(const struct nft_ctx *ctx,if (priv->offset + priv->modulus -1 < priv->offset)return -EOVERFLOW ; - priv->counter =kmalloc (sizeof (*priv->counter),GFP_KERNEL ); + priv->counter =kmalloc (sizeof (*priv->counter),GFP_KERNEL_ACCOUNT );if (!priv->counter)return -ENOMEM ;
net/netfilter/nft_set_pipapo.c +7 -6
@@ -663,7 +663,7 @@ static int pipapo_realloc_mt(struct nft_pipapo_field *f, check_add_overflow(rules, extra, &rules_alloc))return -EOVERFLOW ; - new_mt =kvmalloc_array (rules_alloc,sizeof (*new_mt),GFP_KERNEL ); + new_mt =kvmalloc_array (rules_alloc,sizeof (*new_mt),GFP_KERNEL_ACCOUNT );if (!new_mt)return -ENOMEM ;
@@ -936,7 +936,7 @@ static void pipapo_lt_bits_adjust(struct nft_pipapo_field *f)return ; } - new_lt =kvzalloc (lt_size +NFT_PIPAPO_ALIGN_HEADROOM ,GFP_KERNEL ); + new_lt =kvzalloc (lt_size +NFT_PIPAPO_ALIGN_HEADROOM ,GFP_KERNEL_ACCOUNT );if (!new_lt)return ;
@@ -1212,7 +1212,7 @@ static int pipapo_realloc_scratch(struct nft_pipapo_match *clone, scratch =kzalloc_node (struct_size (scratch, map, bsize_max *2 ) +NFT_PIPAPO_ALIGN_HEADROOM , -GFP_KERNEL ,cpu_to_node (i)); +GFP_KERNEL_ACCOUNT ,cpu_to_node (i));if (!scratch) {/* On failure, there's no need to undo previous * allocations: this means that some scratch maps have
@@ -1427,7 +1427,7 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old)struct nft_pipapo_match *new;int i; - new =kmalloc (struct_size (new, f, old->field_count),GFP_KERNEL ); + new =kmalloc (struct_size (new, f, old->field_count),GFP_KERNEL_ACCOUNT );if (!new)return NULL ;
@@ -1457,7 +1457,7 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old) new_lt =kvzalloc (src->groups *NFT_PIPAPO_BUCKETS (src->bb) * src->bsize *sizeof (*dst->lt) +NFT_PIPAPO_ALIGN_HEADROOM , -GFP_KERNEL ); +GFP_KERNEL_ACCOUNT );if (!new_lt) goto out_lt;
@@ -1470,7 +1470,8 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old)if (src->rules >0 ) { dst->mt =kvmalloc_array (src->rules_alloc, -sizeof (*src->mt),GFP_KERNEL ); +sizeof (*src->mt), +GFP_KERNEL_ACCOUNT );if (!dst->mt) goto out_mt;
net/netfilter/nft_tunnel.c +3 -2
@@ -509,13 +509,14 @@ static int nft_tunnel_obj_init(const struct nft_ctx *ctx,return err; } - md =metadata_dst_alloc (priv->opts.len,METADATA_IP_TUNNEL ,GFP_KERNEL ); + md =metadata_dst_alloc (priv->opts.len,METADATA_IP_TUNNEL , +GFP_KERNEL_ACCOUNT );if (!md)return -ENOMEM ;memcpy (&md->u.tun_info, &info,sizeof (info));#ifdef CONFIG_DST_CACHE - err =dst_cache_init (&md->u.tun_info.dst_cache,GFP_KERNEL ); + err =dst_cache_init (&md->u.tun_info.dst_cache,GFP_KERNEL_ACCOUNT );if (err <0 ) {metadata_dst_free (md);return err;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 12/14 netfilter: nfnetlink_queue: remove old clash resolution logic
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
For historical reasons there are two clash resolution spots in netfilter, one in nfnetlink_queue and one in conntrack core.
nfnetlink_queue one was added first: If a colliding entry is found, NAT NAT transformation is reversed by calling nat engine again with altered tuple.
See commit 368982cd7d1b ("netfilter: nfnetlink_queue: resolve clash for unconfirmed conntracks") for details.
One problem is that nf_reroute() won't take an action if the queueing doesn't occur in the OUTPUT hook, i.e. when queueing in forward or postrouting, packet will be sent via the wrong path.
Another problem is that the scenario addressed (2nd UDP packet sent with identical addresses while first packet is still being processed) can also occur without any nfqueue involvement due to threaded resolvers doing A and AAAA requests back-to-back.
This lead us to add clash resolution logic to the conntrack core, see commit 6a757c07e51f ("netfilter: conntrack: allow insertion of clashing entries"). Instead of fixing the nfqueue based logic, lets remove it and let conntrack core handle this instead.
Retain the ->update hook for sake of nfqueue based conntrack helpers. We could axe this hook completely but we'd have to split confirm and helper logic again, see commit ee04805ff54a ("netfilter: conntrack: make conntrack userspace helpers work again").
This SHOULD NOT be backported to kernels earlier than v5.6; they lack adequate clash resolution handling.
Patch was originally written by Pablo Neira Ayuso.
--- include/linux/netfilter.h | 4 -- net/netfilter/nf_conntrack_core.c | 85 ------------------------------- net/netfilter/nf_nat_core.c | 1 - 3 files changed, 90 deletions(-)
include/linux/netfilter.h +0 -4
@@ -376,15 +376,11 @@ int nf_route(struct net *net, struct dst_entry **dst, struct flowi *fl,struct nf_conn ;enum nf_nat_manip_type ;struct nlattr ; -enum ip_conntrack_dir ;struct nf_nat_hook {int (*parse_nat_setup)(struct nf_conn *ct,enum nf_nat_manip_type manip,const struct nlattr *attr);void (*decode_session)(struct sk_buff *skb,struct flowi *fl); -unsigned int (*manip_pkt)(struct sk_buff *skb,struct nf_conn *ct, -enum nf_nat_manip_type mtype, -enum ip_conntrack_dir dir);void (*remove_nat_bysrc)(struct nf_conn *ct); };
net/netfilter/nf_conntrack_core.c +0 -85
97 lines not on this page · raw message
net/netfilter/nf_nat_core.c +0 -1
@@ -1324,7 +1324,6 @@ static const struct nf_nat_hook nat_hook = {#ifdef CONFIG_XFRM .decode_session = __nf_nat_decode_session, #endif - .manip_pkt = nf_nat_manip_pkt, .remove_nat_bysrc = nf_nat_cleanup_conntrack, };
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 13/14 kselftest: add test for nfqueue induced conntrack race
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
The netfilter race happens when two packets with the same tuple are DNATed and enqueued with nfqueue in the postrouting hook.
Once one of the packet is reinjected it may be DNATed again to a different destination, but the conntrack entry remains the same and the return packet was dropped.
Based on earlier patch from Antonio Ojea.
--- .../selftests/net/netfilter/nft_queue.sh | 92 ++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-)
tools/testing/selftests/net/netfilter/nft_queue.sh +91 -1
@@ -31,7 +31,7 @@ modprobe -q sctp trap cleanup EXIT -setup_ns ns1 ns2 nsrouter +setup_ns ns1 ns2 ns3 nsrouter TMPFILE0=$(mktemp) TMPFILE1=$(mktemp)
@@ -48,6 +48,7 @@ if ! ip link add veth0 netns "$nsrouter" type veth peer name eth0 netns "$ns1" > exit $ksft_skip fi ip link add veth1 netns "$nsrouter" type veth peer name eth0 netns "$ns2" +ip link add veth2 netns "$nsrouter" type veth peer name eth0 netns "$ns3" ip -net "$nsrouter" link set veth0 up ip -net "$nsrouter" addr add 10.0.1.1/24 dev veth0
@@ -57,8 +58,13 @@ ip -net "$nsrouter" link set veth1 up ip -net "$nsrouter" addr add 10.0.2.1/24 dev veth1 ip -net "$nsrouter" addr add dead:2::1/64 dev veth1 nodad +ip -net "$nsrouter" link set veth2 up +ip -net "$nsrouter" addr add 10.0.3.1/24 dev veth2 +ip -net "$nsrouter" addr add dead:3::1/64 dev veth2 nodad + ip -net "$ns1" link set eth0 up ip -net "$ns2" link set eth0 up +ip -net "$ns3" link set eth0 up ip -net "$ns1" addr add 10.0.1.99/24 dev eth0 ip -net "$ns1" addr add dead:1::99/64 dev eth0 nodad
@@ -70,6 +76,11 @@ ip -net "$ns2" addr add dead:2::99/64 dev eth0 nodad ip -net "$ns2" route add default via 10.0.2.1 ip -net "$ns2" route add default via dead:2::1 +ip -net "$ns3" addr add 10.0.3.99/24 dev eth0 +ip -net "$ns3" addr add dead:3::99/64 dev eth0 nodad +ip -net "$ns3" route add default via 10.0.3.1 +ip -net "$ns3" route add default via dead:3::1 + load_ruleset() { local name=$1 local prio=$2
@@ -473,6 +484,83 @@ EOF check_output_files "$TMPINPUT" "$TMPFILE1" "sctp output" } +udp_listener_ready() +{ + ss -S -N "$1" -uln -o "sport = :12345" | grep -q 12345 +} + +output_files_written() +{ + test -s "$1" && test -s "$2" +} + +test_udp_ct_race() +{ + ip netns exec "$nsrouter" nft -f /dev/stdin <<EOF +flush ruleset +table inet udpq { + chain prerouting { + type nat hook prerouting priority dstnat - 5; policy accept; + ip daddr 10.6.6.6 udp dport 12345 counter dnat to numgen inc mod 2 map { 0 : 10.0.2.99, 1 : 10.0.3.99 } + } + chain postrouting { + type filter hook postrouting priority srcnat - 5; policy accept; + udp dport 12345 counter queue num 12 + } +} +EOF + :> "$TMPFILE1" + :> "$TMPFILE2" + + timeout 10 ip netns exec "$ns2" socat UDP-LISTEN:12345,fork OPEN:"$TMPFILE1",trunc & + local rpid1=$! + + timeout 10 ip netns exec "$ns3" socat UDP-LISTEN:12345,fork OPEN:"$TMPFILE2",trunc & + local rpid2=$! + + ip netns exec "$nsrouter" ./nf_queue -q 12 -d 1000 & + local nfqpid=$! + + busywait "$BUSYWAIT_TIMEOUT" udp_listener_ready "$ns2" + busywait "$BUSYWAIT_TIMEOUT" udp_listener_ready "$ns3" + busywait "$BUSYWAIT_TIMEOUT" nf_queue_wait "$nsrouter" 12 + + # Send two packets, one should end up in ns1, other in ns2. + # This is because nfqueue will delay packet for long enough so that + # second packet will not find existing conntrack entry. + echo "Packet 1" | ip netns exec "$ns1" socat STDIN UDP-DATAGRAM:10.6.6.6:12345,bind=0.0.0.0:55221 + echo "Packet 2" | ip netns exec "$ns1" socat STDIN UDP-DATAGRAM:10.6.6.6:12345,bind=0.0.0.0:55221 + + busywait 10000 output_files_written "$TMPFILE1" "$TMPFILE2" + + kill "$nfqpid" + + if ! ip netns exec "$nsrouter" bash -c 'conntrack -L -p udp --dport 12345 2>/dev/null | wc -l | grep -q "^1"'; then + echo "FAIL: Expected One udp conntrack entry" + ip netns exec "$nsrouter" conntrack -L -p udp --dport 12345 + ret=1 + fi + + if ! ip netns exec "$nsrouter" nft delete table inet udpq; then + echo "FAIL: Could not delete udpq table" + ret=1 + return + fi + + NUMLINES1=$(wc -l < "$TMPFILE1") + NUMLINES2=$(wc -l < "$TMPFILE2") + + if [ "$NUMLINES1" -ne 1 ] || [ "$NUMLINES2" -ne 1 ]; then + ret=1 + echo "FAIL: uneven udp packet distribution: $NUMLINES1 $NUMLINES2" + echo -n "$TMPFILE1: ";cat "$TMPFILE1" + echo -n "$TMPFILE2: ";cat "$TMPFILE2" + return + fi + + echo "PASS: both udp receivers got one packet each" +} + test_queue_removal() { read tainted_then < /proc/sys/kernel/tainted
@@ -512,6 +600,7 @@ EOF 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.veth2.forwarding=1 > /dev/null load_ruleset "filter" 0
@@ -549,6 +638,7 @@ test_tcp_localhost_connectclose test_tcp_localhost_requeue test_sctp_forward test_sctp_output +test_udp_ct_race # should be last, adds vrf device in ns1 and changes routes test_icmp_vrf
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 14/14 selftests: netfilter: Avoid hanging ipvs.sh
In reply to Pablo Neira AyusoFrom: Phil Sutter <[email protected]>
If the client can't reach the server, the latter remains listening forever. Kill it after 5s of waiting.
--- tools/testing/selftests/net/netfilter/ipvs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/netfilter/ipvs.sh +1 -1
@@ -97,7 +97,7 @@ cleanup() { } server_listen() { - ip netns exec "$ns2" socat -u -4 TCP-LISTEN:8080,reuseaddr STDOUT > "${outfile}" & + ip netns exec "$ns2" timeout 5 socat -u -4 TCP-LISTEN:8080,reuseaddr STDOUT > "${outfile}" & server_pid=$! sleep 0.2 }
Signature · 1 line
2.30.2
Paolo Abeni
maintainerQuoted 7 lines · Pablo Neira Ayuso
The following patchset contains Netfilter fixes for net:
Patch #1 and #2 handle an esoteric scenario: Given two tasks sending UDP packets to one another, two packets of the same flow in each direction handled by different CPUs that result in two conntrack objects in NEW state, where reply packet loses race. Then, patch #3 adds a testcase for this scenario. Series from Florian Westphal.
Kdoc complains against the lack of documentation for the return value in the first 2 patches: 'Returns' should be '@Return'.
If you could repost a new revision soon, I could possibly still include it in today PR (delaying the latter a bit).
Thanks!
Paolo
Florian Westphal
maintainerQuoted 11 lines · Paolo Abeni
Quoted 7 lines · Pablo Neira Ayuso
The following patchset contains Netfilter fixes for net:
Patch #1 and #2 handle an esoteric scenario: Given two tasks sending UDP packets to one another, two packets of the same flow in each direction handled by different CPUs that result in two conntrack objects in NEW state, where reply packet loses race. Then, patch #3 adds a testcase for this scenario. Series from Florian Westphal.
Kdoc complains against the lack of documentation for the return value in the first 2 patches: 'Returns' should be '@Return'.
:-(
Apparently this is found via
scripts/kernel-doc -Wall -none <file>
I'll run this in the future, but, I have to say, its encouraging me to just not write such kdocs entries in first place, no risk of making a mistake.
Paolo, Pablo, what should I do now?
Pablo Neira Ayuso
maintainerQuoted 17 lines · Florian Westphal
Quoted 11 lines · Paolo Abeni
Quoted 7 lines · Pablo Neira Ayuso
The following patchset contains Netfilter fixes for net:
Patch #1 and #2 handle an esoteric scenario: Given two tasks sending UDP packets to one another, two packets of the same flow in each direction handled by different CPUs that result in two conntrack objects in NEW state, where reply packet loses race. Then, patch #3 adds a testcase for this scenario. Series from Florian Westphal.
Kdoc complains against the lack of documentation for the return value in the first 2 patches: 'Returns' should be '@Return'.
:-(
Apparently this is found via
Quoted 7 lines
scripts/kernel-doc-Wall -none <file>I'll run this in the future, but, I have to say, its encouraging me to just not write such kdocs entries in first place, no risk of making a mistake.
Paolo, Pablo, what should I do now?
I am going to fix it and resubmit PR.
Florian Westphal
maintainerQuoted 3 lines · Pablo Neira Ayuso
Quoted 1 line
Paolo, Pablo, what should I do now?
I am going to fix it and resubmit PR.
Thanks, and sorry about this. I was not aware of how to format this "properly".
Paolo Abeni
maintainerQuoted 17 lines · Florian Westphal
Quoted 11 lines · Paolo Abeni
Quoted 7 lines · Pablo Neira Ayuso
The following patchset contains Netfilter fixes for net:
Patch #1 and #2 handle an esoteric scenario: Given two tasks sending UDP packets to one another, two packets of the same flow in each direction handled by different CPUs that result in two conntrack objects in NEW state, where reply packet loses race. Then, patch #3 adds a testcase for this scenario. Series from Florian Westphal.
Kdoc complains against the lack of documentation for the return value in the first 2 patches: 'Returns' should be '@Return'.
:-(
Apparently this is found via
Quoted 7 lines
scripts/kernel-doc-Wall -none <file>I'll run this in the future, but, I have to say, its encouraging me to just not write such kdocs entries in first place, no risk of making a mistake.
Paolo, Pablo, what should I do now?
If an updated PR could be resent soon, say within ~1h, I can wait for the CI to run on it, merge and delay the net PR after that.
Otherwise, if the fixes in here are urgent, I can pull the series as-is, and you could follow-up on nf-next/net-next.
The last resort is just drop this from today's PR.
Please LMK your preference,
Paolo
Pablo Neira Ayuso
maintainerQuoted 29 lines · Paolo Abeni
Quoted 17 lines · Florian Westphal
Quoted 11 lines · Paolo Abeni
Quoted 7 lines · Pablo Neira Ayuso
The following patchset contains Netfilter fixes for net:
Patch #1 and #2 handle an esoteric scenario: Given two tasks sending UDP packets to one another, two packets of the same flow in each direction handled by different CPUs that result in two conntrack objects in NEW state, where reply packet loses race. Then, patch #3 adds a testcase for this scenario. Series from Florian Westphal.
Kdoc complains against the lack of documentation for the return value in the first 2 patches: 'Returns' should be '@Return'.
:-(
Apparently this is found via
Quoted 7 lines
scripts/kernel-doc-Wall -none <file>I'll run this in the future, but, I have to say, its encouraging me to just not write such kdocs entries in first place, no risk of making a mistake.
Paolo, Pablo, what should I do now?
If an updated PR could be resent soon, say within ~1h, I can wait for the CI to run on it, merge and delay the net PR after that.
Quoted 6 lines
Otherwise, if the fixes in here are urgent, I can pull the series as-is, and you could follow-up on nf-next/net-next.
The last resort is just drop this from today's PR.
Please LMK your preference,
I am working on this now.