netfilter: disable support for queueing cloned conntrack entries
Subsystems (4)
Florian Westphal
maintainercover netfilter: disable support for queueing cloned conntrack entries
Conntrack assumes an unconfirmed entry (not yet committed to global hash table) has a refcount of 1 and is not visible to other cores.
With multicast forwarding this assumption breaks down because such skbs get cloned after being picked up, i.e. ct->use refcount is > 1.
Likewise, bridge netfilter will clone broad/mutlicast frames and all frames in case they need to be flood-forwarded during learning phase.
For ip multicast forwarding or plain bridge flood-forward this will "work" because packets don't leave softirq and are implicitly serialized.
With nfqueue this no longer holds true, the packets get queued and can be reinjected in arbitrary ways.
Disable this feature.
After this patch, nfqueue cannot queue packets except the last multicast/broadcast packet.
Alternatives:
- queue, but zap skb->nf_conn . Problem:
On reinject, packet would match INVALID state.
- same, but make them untracked. Slightly better, but not by much.
- check if NAT was applied or not.
If not, we could theoretically queue and then relookup the conntrack on reinject.
This would create a new entry in established, new or invalid state (userspace can munge the packet).
ATM I would prefer to go with the minimal solution which is to disable this feature.
Florian Westphal
maintainerPATCH 1/2 netfilter: nf_queue: drop packets with cloned unconfirmed conntracks
Conntrack assumes an unconfirmed entry (not yet committed to global hash table) has a refcount of 1 and is not visible to other cores.
With multicast forwarding this assumption breaks down because such skbs get cloned after being picked up, i.e. ct->use refcount is > 1.
Likewise, bridge netfilter will clone broad/mutlicast frames and all frames in case they need to be flood-forwarded during learning phase.
For ip multicast forwarding or plain bridge flood-forward this will "work" because packets don't leave softirq and are implicitly serialized.
With nfqueue this no longer holds true, the packets get queued and can be reinjected in arbitrary ways.
Disable this feature, I see no other solution.
After this patch, nfqueue cannot queue packets except the last multicast/broadcast packet.
--- net/bridge/br_netfilter_hooks.c | 6 +++++- net/netfilter/nfnetlink_queue.c | 35 +++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-)
net/bridge/br_netfilter_hooks.c +5 -1
@@ -622,8 +622,12 @@ static unsigned int br_nf_local_in(void *priv,if (likely (nf_ct_is_confirmed (ct)))return NF_ACCEPT ; +if (WARN_ON_ONCE (refcount_read (&nfct->use) !=1 )) { +nf_reset_ct (skb); +return NF_ACCEPT ; + } +WARN_ON_ONCE (skb_shared (skb)); -WARN_ON_ONCE (refcount_read (&nfct->use) !=1 );/* We can't call nf_confirm here, it would create a dependency * on nf_conntrack module.
net/netfilter/nfnetlink_queue.c +33 -2
@@ -820,10 +820,41 @@ static bool nf_ct_drop_unconfirmed(const struct nf_queue_entry *entry) {#if IS_ENABLED (CONFIG_NF_CONNTRACK )static const unsigned long flags =IPS_CONFIRMED |IPS_DYING ; -const struct nf_conn *ct = (void *)skb_nfct (entry->skb); +struct nf_conn *ct = (void *)skb_nfct (entry->skb); +unsigned long status; +unsigned int use; -if (ct && ((ct->status & flags) ==IPS_DYING )) +if (!ct) +return false; + + status =READ_ONCE (ct->status); +if ((status & flags) ==IPS_DYING )return true; + +if (status &IPS_CONFIRMED ) +return false; + +/* in some cases skb_clone() can occur after initial conntrack +* pickup, but conntrack assumes exclusive skb->_nfct ownership for +* unconfirmed entries. +* +* This happens for br_netfilter and with ip multicast routing. +* We can't be solved with serialization here because one clone could +* have been queued for local delivery. +*/ + use =refcount_read (&ct->ct_general.use); +if (likely (use ==1 )) +return false; + +/* Can't decrement further? Exclusive ownership. */ +if (!refcount_dec_not_one (&ct->ct_general.use)) +return false; + +skb_set_nfct (entry->skb,0 ); +/* No nf_ct_put(): we already decremented .use and it cannot +* drop down to 0. +*/ +return true;#endif return false; }
Signature · 1 line
2.44.2
Florian Westphal
maintainerPATCH 2/2 selftests: netfilter: add test for br_netfilter+conntrack+queue combination
In reply to Florian WestphalTrigger cloned skbs leaving softirq protection. This triggers splat without the preceeding change ("netfilter: nf_queue: drop packets with cloned unconfirmed
conntracks"):
WARNING: at net/netfilter/nf_conntrack_core.c:1198 __nf_conntrack_confirm..
because local delivery and forwarding will race for confirmation.
Based on a reproducer script from Yi Chen.
--- .../testing/selftests/net/netfilter/Makefile | 1 + .../net/netfilter/br_netfilter_queue.sh | 71 +++++++++++++++++++ tools/testing/selftests/net/netfilter/lib.sh | 16 +++++ .../selftests/net/netfilter/nft_queue.sh | 16 ----- 4 files changed, 88 insertions(+), 16 deletions(-) create mode 100755 tools/testing/selftests/net/netfilter/br_netfilter_queue.sh
tools/testing/selftests/net/netfilter/Makefile +1 -0
@@ -7,6 +7,7 @@ MNL_CFLAGS := $(shell $(HOSTPKG_CONFIG) --cflags libmnl 2>/dev/null) MNL_LDLIBS := $(shell $(HOSTPKG_CONFIG) --libs libmnl 2>/dev/null || echo -lmnl) TEST_PROGS := br_netfilter.sh bridge_brouter.sh +TEST_PROGS += br_netfilter_queue.sh TEST_PROGS += conntrack_icmp_related.sh TEST_PROGS += conntrack_ipip_mtu.sh TEST_PROGS += conntrack_tcp_unreplied.sh
tools/testing/selftests/net/netfilter/br_netfilter_queue.sh new file +71 -0
71 lines not on this page · raw message
tools/testing/selftests/net/netfilter/lib.sh +16 -0
@@ -8,3 +8,19 @@ checktool (){ exit $ksft_skip fi } + +nf_queue_wait() +{ + local procfile="/proc/self/net/netfilter/nfnetlink_queue" + local netns id + + netns="$1" + id="$2" + + # if this file doesn't exist, nfnetlink_module isn't loaded. + # rather than loading it ourselves, wait for kernel module autoload + # completion, nfnetlink should do so automatically because nf_queue + # helper program, spawned in the background, asked for this functionality. + test -f "$procfile" && + ip netns exec "$netns" cat "$procfile" | grep -q "^ *$id " +}
tools/testing/selftests/net/netfilter/nft_queue.sh +0 -16
@@ -190,22 +190,6 @@ EOF echo "PASS: $proto: statement with no listener results in packet drop" } -nf_queue_wait() -{ - local procfile="/proc/self/net/netfilter/nfnetlink_queue" - local netns id - - netns="$1" - id="$2" - - # if this file doesn't exist, nfnetlink_module isn't loaded. - # rather than loading it ourselves, wait for kernel module autoload - # completion, nfnetlink should do so automatically because nf_queue - # helper program, spawned in the background, asked for this functionality. - test -f "$procfile" && - ip netns exec "$netns" cat "$procfile" | grep -q "^ *$id " -} - test_queue() { local expected="$1"
Signature · 1 line
2.44.2
Florian Westphal
maintainerRe: [PATCH nf 2/2] selftests: netfilter: add test for br_netfilter+conntrack+queue combination
Quoted 7 lines · Florian Westphal
Trigger cloned skbs leaving softirq protection. This triggers splat without the preceeding change ("netfilter:
nf_queue: drop packets with cloned unconfirmed
conntracks"):WARNING: at net/netfilter/nf_conntrack_core.c:1198 __nf_conntrack_confirm..
Quoted 8 lines
because local delivery and forwarding will race for confirmation.
Based on a reproducer script from Yi Chen.
Signed-off-by Florian Westphal <[email protected]>--- tools/testing/selftests/net/netfilter/lib.sh | 16 +++++ .../selftests/net/netfilter/nft_queue.sh | 16 -----
Those two files should be unchanged. I'll send a v2 of the selftest script tomorrow.
Florian Westphal
maintainerPATCH v2 2/2 selftests: netfilter: add test for br_netfilter+conntrack+queue combination
In reply to Florian WestphalTrigger cloned skbs leaving softirq protection. This triggers splat without the preceeding change ("netfilter: nf_queue: drop packets with cloned unconfirmed
conntracks"):
WARNING: at net/netfilter/nf_conntrack_core.c:1198 __nf_conntrack_confirm..
because local delivery and forwarding will race for confirmation.
Based on a reproducer script from Yi Chen.
---
v2: remove unwanted change to lib.sh and remove
conntrack -F busyloop.
.../testing/selftests/net/netfilter/Makefile | 1 + .../net/netfilter/br_netfilter_queue.sh | 78 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100755 tools/testing/selftests/net/netfilter/br_netfilter_queue.sh
tools/testing/selftests/net/netfilter/Makefile +1 -0
@@ -7,6 +7,7 @@ MNL_CFLAGS := $(shell $(HOSTPKG_CONFIG) --cflags libmnl 2>/dev/null) MNL_LDLIBS := $(shell $(HOSTPKG_CONFIG) --libs libmnl 2>/dev/null || echo -lmnl) TEST_PROGS := br_netfilter.sh bridge_brouter.sh +TEST_PROGS += br_netfilter_queue.sh TEST_PROGS += conntrack_icmp_related.sh TEST_PROGS += conntrack_ipip_mtu.sh TEST_PROGS += conntrack_tcp_unreplied.sh
tools/testing/selftests/net/netfilter/br_netfilter_queue.sh new file +78 -0
78 lines not on this page · raw message
Signature · 1 line
2.44.2