Skip to contentSkip to conversation

netfilter: nft_synproxy: enforce strict TCP flag matching

RFC PATCH syzbot 2 participants 2 messages Nov 25 – Nov 26

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 generated SYN+ACK back through the same input rule on NF_INET_LOCAL_IN, if (tcp->syn) matches again and sustains an infinite SYN+ACK feedback loop in softirq context, saturating the CPUs, starving tasks holding or waiting on rtnl_mutex, and triggering hung task warnings.

Fix this by filtering out invalid TCP flag combinations in nft_synproxy_do_eval() before dispatching to nft_synproxy_eval_v4() or nft_synproxy_eval_v6(): return early when tcp->syn == tcp->ack || tcp->fin || tcp->rst. This rejects packets with FIN or RST set, packets with neither SYN nor ACK set, and SYN+ACK packets, ensuring only SYN-only or ACK-only control packets (without FIN/RST) reach the v4/v6 evaluation helpers 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 Gemini:gemini-3.8-flash 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]>

---
v2:
- Moved the strict TCP flag check from nft_synproxy_eval_v4() and nft_synproxy_eval_v6() into nft_synproxy_do_eval()
- Replaced the per-branch flag checks with if (tcp->syn == tcp->ack || tcp->fin || tcp->rst) return;
- Updated the commit message to match the new implementation and removed the quoted hung-task and NMI backtrace excerpt

v1:
https://lore.kernel.org/all/[email protected]/T/
---

net/netfilter/nft_synproxy.c +3 -0
index 554a96a00..aa8dea698 100644
@@ -137,6 +137,9 @@ static void nft_synproxy_do_eval(const struct nft_synproxy *priv,
 		return;
 	}
 
+	if (tcp->syn == tcp->ack || tcp->fin || tcp->rst)
+		return;
+
 	switch (skb->protocol) {
 	case htons(ETH_P_IP):
 		nft_synproxy_eval_v4(priv, regs, pkt, tcp, &_tcph, &opts);

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].
#1 lore raw
Quoted 73 lines · syzbot

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 generated SYN+ACK back through the same input rule on NF_INET_LOCAL_IN, if (tcp->syn) matches again and sustains an infinite SYN+ACK feedback loop in softirq context, saturating the CPUs, starving tasks holding or waiting on rtnl_mutex, and triggering hung task warnings.

Fix this by filtering out invalid TCP flag combinations in nft_synproxy_do_eval() before dispatching to nft_synproxy_eval_v4() or nft_synproxy_eval_v6(): return early when tcp->syn == tcp->ack || tcp->fin || tcp->rst. This rejects packets with FIN or RST set, packets with neither SYN nor ACK set, and SYN+ACK packets, ensuring only SYN-only or ACK-only control packets (without FIN/RST) reach the v4/v6 evaluation helpers 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 Gemini:gemini-3.8-flash 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]>

---
v2:
- Moved the strict TCP flag check from nft_synproxy_eval_v4() and nft_synproxy_eval_v6() into nft_synproxy_do_eval()
- Replaced the per-branch flag checks with if (tcp->syn == tcp->ack || tcp->fin || tcp->rst) return;
- Updated the commit message to match the new implementation and removed the quoted hung-task and NMI backtrace excerpt

v1:
https://lore.kernel.org/all/[email protected]/T/
---

net/netfilter/nft_synproxy.c +3 -0
index 554a96a00..aa8dea698 100644
@@ -137,6 +137,9 @@ static void nft_synproxy_do_eval(const struct nft_synproxy *priv,
 		return;
 	}
 
+	if (tcp->syn == tcp->ack || tcp->fin || tcp->rst)
+		return;
+
 	switch (skb->protocol) {
 	case htons(ETH_P_IP):
 		nft_synproxy_eval_v4(priv, regs, pkt, tcp, &_tcph, &opts);
Quoted 1 line

base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f

Please rewrite the commit message as plain kernel changelog text and keep the code change exactly as it is. The single check in nft_synproxy_do_eval() is correct and needs no further change.

The current description puts Markdown backticks around function names and code, which kernel changelogs do not use, and its second paragraph walks through the loop one function and hook at a time. Its last paragraph also calls SYN-ACK, FIN+ACK and RST+ACK "invalid TCP flag combinations" and says that the check "rejects" them. These are valid TCP segments that are only not part of the client handshake, and after the check they continue through the ruleset with the verdict unchanged, as the end of the same sentence says. A description along these lines would be enough:

netfilter: nft_synproxy: only handle a plain SYN or a plain ACK

The synproxy expression and object answer every TCP segment with SYN set with a SYN-ACK cookie and treat every other segment with ACK set as the ACK that completes the handshake. The iptables and ip6tables SYNPROXY targets act only on a SYN without ACK, FIN and RST, or an ACK without SYN, FIN and RST.

A SYN-ACK is what synproxy sends itself. When it reaches the same rule again, as it does over loopback for a connection to a local address, it is answered with another SYN-ACK, and so on forever in softirq context. Each retransmitted SYN starts one more such loop. syzbot hit this with a synproxy rule on the input hook that matched all TCP
segments: a CPU kept running the loop in net_rx_action() and tasks waiting for the RTNL mutex were reported as hung.

Return early from nft_synproxy_do_eval(), before the family specific code, for a segment that has FIN or RST set or that does not have exactly one of SYN and ACK. Such segments continue through the ruleset, as with the SYNPROXY targets.

Keep the Fixes tag of this version unchanged.

Signature · 1 line
Krystian Kaniewski