Skip to contentSkip to conversation

netfilter: nft_synproxy: enforce strict TCP flag matching

RFC PATCH syzbot 1 participant 1 message Nov 24

Subsystems (2)
lore
Share & tools
lore

syzbot

author syzbot
#0 lore raw

In nft_synproxy_eval_v4() and nft_synproxy_eval_v6(), TCP control flags are checked only with if (tcp->syn) and else if (tcp->ack) without excluding other flags, unlike the xtables SYNPROXY targets (synproxy_tg4() and synproxy_tg6()). As a result, a SYN+ACK (or SYN+FIN / SYN+RST) packet reaching nft_synproxy is misidentified as an initial client SYN and causes synproxy_send_client_synack() or synproxy_send_client_synack_ipv6() to reply with another SYN+ACK. Likewise, FIN+ACK and RST+ACK packets enter the client ACK branch and can be dropped with NF_DROP instead of continuing through the ruleset.

When an nftables rule evaluates nft_synproxy (either via the inline expression or a stateful NFT_OBJECT_SYNPROXY object) on NF_INET_LOCAL_IN, a local TCP SYN over loopback triggers nft_synproxy_eval_v4() to send a SYN+ACK with swapped addresses and ports and a fresh TTL via synproxy_send_client_synack(). When process_backlog() in NET_RX_SOFTIRQ delivers that SYN+ACK back to NF_INET_LOCAL_IN, if (tcp->syn) matches again, creating an infinite SYN+ACK loop in softirq context. This saturates the CPUs, starves tasks holding or waiting on rtnl_mutex, and triggers hung task warnings:

INFO: task kworker/R-ipv6_:60 blocked for more than 144 seconds.
Workqueue: ipv6_addrconf addrconf_dad_work
Call Trace:
 __mutex_lock+0x7c4/0x15a0 kernel/locking/mutex.c:821
 rtnl_net_lock include/linux/rtnetlink.h:134 [inline]
 addrconf_dad_work+0x116/0x15c0 net/ipv6/addrconf.c:4256

NMI backtrace for cpu 1

 __kfree_skb+0x5d/0x210 net/core/skbuff.c:1203
 nft_synproxy_eval_v4+0x36a/0x4e0 net/netfilter/nft_synproxy.c:-1
 nft_synproxy_do_eval+0x389/0x5d0 net/netfilter/nft_synproxy.c:142
 expr_call_ops_eval net/netfilter/nf_tables_core.c:237 [inline]
 nft_do_chain+0x48d/0x1b10 net/netfilter/nf_tables_core.c:285
 nft_do_chain_ipv4+0x195/0x290 net/netfilter/nft_chain_filter.c:24
 process_backlog+0xa6b/0x18b0 net/core/dev.c:6915

Fix this by enforcing the same strict TCP flag checks as ipt_SYNPROXY and ip6t_SYNPROXY in both nft_synproxy_eval_v4() and nft_synproxy_eval_v6(): require tcp->syn && !(tcp->ack || tcp->fin || tcp->rst) for the initial SYN branch and tcp->ack && !(tcp->fin || tcp->rst || tcp->syn) for the client ACK branch. Excluding tcp->syn from the ACK branch ensures SYN+ACK packets are not passed to synproxy_recv_client_ack() or synproxy_recv_client_ack_ipv6() and dropped, while unrelated control packets fall through with regs->verdict.code left as NFT_CONTINUE.

Fixes ad49d86e07a4 ("netfilter: nf_tables: Add synproxy support")
Assisted-by Gemini:gemini-4-hydrogen Gemini:gemini-4-carbon syzbot
Reported-by [email protected]

To: <[email protected]>
To: "David S. Miller" <[email protected]>
To: "Eric Dumazet" <[email protected]>
To: "Florian Westphal" <[email protected]>
To: "Jakub Kicinski" <[email protected]>
To: <[email protected]>
To: <[email protected]>
To: "Paolo Abeni" <[email protected]>
To: "Pablo Neira Ayuso" <[email protected]>
To: "Fernando Fernandez Mancera" <[email protected]>
Cc: "Simon Horman" <[email protected]>
Cc: "Phil Sutter" <[email protected]>

---

net/netfilter/nft_synproxy.c +4 -4
index 554a96a00..ad43faf1d 100644
@@ -53,13 +53,13 @@ static void nft_synproxy_eval_v4(const struct nft_synproxy *priv,
 	struct synproxy_net *snet = synproxy_pernet(net);
 	struct sk_buff *skb = pkt->skb;
 
-	if (tcp->syn) {
+	if (tcp->syn && !(tcp->ack || tcp->fin || tcp->rst)) {
 		/* Initial SYN from client */
 		nft_synproxy_tcp_options(opts, tcp, snet, &info);
 		synproxy_send_client_synack(net, skb, tcp, opts);
 		consume_skb(skb);
 		regs->verdict.code = NF_STOLEN;
-	} else if (tcp->ack) {
+	} else if (tcp->ack && !(tcp->fin || tcp->rst || tcp->syn)) {
 		/* ACK from client */
 		if (synproxy_recv_client_ack(net, skb, tcp, opts,
 					     ntohl(tcp->seq))) {
@@ -84,13 +84,13 @@ static void nft_synproxy_eval_v6(const struct nft_synproxy *priv,
 	struct synproxy_net *snet = synproxy_pernet(net);
 	struct sk_buff *skb = pkt->skb;
 
-	if (tcp->syn) {
+	if (tcp->syn && !(tcp->ack || tcp->fin || tcp->rst)) {
 		/* Initial SYN from client */
 		nft_synproxy_tcp_options(opts, tcp, snet, &info);
 		synproxy_send_client_synack_ipv6(net, skb, tcp, opts);
 		consume_skb(skb);
 		regs->verdict.code = NF_STOLEN;
-	} else if (tcp->ack) {
+	} else if (tcp->ack && !(tcp->fin || tcp->rst || tcp->syn)) {
 		/* ACK from client */
 		if (synproxy_recv_client_ack_ipv6(net, skb, tcp, opts,
 						  ntohl(tcp->seq))) {

base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f

Signature · 9 lines
This is an AI-generated patch subject to moderation.
Reply with '#syz upstream' to Sign-off the patch as a human author
and send it to the upstream kernel mailing lists.
Reply with '#syz reject' to reject it ('#syz unreject' to undo).

See https://goo.gle/syzbot-ai-patches for information about AI-generated patches.
You can comment on the patch as usual, syzbot will try to address
the comments and send a new version of the patch if necessary.
syzbot engineers can be reached at [email protected].