Netdev List
 help / color / mirror / Atom feed
* [BUG] netfilter: synproxy: server ACK carries TSecr shifted twice, rejected by tcp_check_req() since v6.15
@ 2026-11-16 14:23 info
  2026-11-16 22:37 ` Florian Westphal
  0 siblings, 1 reply; 2+ messages in thread
From: info @ 2026-11-16 14:23 UTC (permalink / raw)
  To: netfilter-devel
  Cc: netdev, coreteam, Pablo Neira Ayuso, Florian Westphal,
	Phil Sutter, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
	David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman

(Resent as plain text, the list rejected the first copy as HTML.)

Hello,

with SYNPROXY --timestamp in front of a Linux backend, every
handshake ACK that SYNPROXY sends to the backend is dropped by the
backend's tcp_check_req() TSecr check added in 3ba075278c11 ("tcp: be
less liberal in TSEcr received while in SYN_RECV state", v6.15). The
connection then only completes with the client's first data segment.
If the backend's millisecond clock ticks between its SYN-ACK and its
reply to the rejected ACK, the client echoes the newer TSval, the data
segment is rejected too, and the connection stalls until the backend
retransmits its SYN-ACK after 1 s (about 1.6 s in total).

Cause, as far as we can read the code (mainline a9daf327f3ff,
net/netfilter/nf_synproxy_core.c, IPv4; the IPv6 path at lines
1149-1180 is the same, not measured):

- ipv4_synproxy_hook(), state TCP_CONNTRACK_SYN_RECV (line 719):
  synproxy->tsoff = opts.tsval - synproxy->its (line 727), then
  swap(opts.tsval, opts.tsecr) and synproxy_send_server_ack() (line
  736), so the ACK is built with TSecr already equal to the backend's
  TSval.
- synproxy_send_server_ack() sends it via synproxy_send_tcp() with no
  conntrack attached (line 573). Conntrack then associates it with the
  connection in the ORIGINAL direction and the same hook calls
  synproxy_tstamp_adjust() on it (line 750), which adds tsoff to TSecr
  a second time (lines 227-231).
- net/ipv4/tcp_minisocks.c, tcp_check_req() (line 687): tsecr_reject
  = !between(rcv_tsecr, snt_tsval_first, snt_tsval_last) (lines
  709-711), the segment is dropped and answered with an ACK (lines
  843-861, LINUX_MIB_TSECRREJECTED).

Before v6.15 the wrong TSecr was ignored in SYN_RECV, so the bug was
invisible.

Measurement (network-namespace lab, no hardware involved):
- kernel 7.1.13-200.fc44.x86_64, iptables v1.8.11 (nf_tables)
- host namespace with Docker-style DNAT of :443 to a backend in
  another namespace behind a bridge; client in a third namespace
  behind a veth
- rules:
    iptables -t raw -I PREROUTING -p tcp --syn -m multiport \
      --dports 443,80 ! -i br-+ -m addrtype --dst-type LOCAL \
      --limit-iface-in -j CT --notrack
    iptables -I INPUT -p tcp -m multiport --dports 443,80 ! -i br-+ \
      -m addrtype --dst-type LOCAL --limit-iface-in \
      -m conntrack --ctstate INVALID,UNTRACKED \
      -j SYNPROXY --sack-perm --timestamp --wscale 10 --mss 1460
    sysctl net.netfilter.nf_conntrack_tcp_loose=0
- client: 1000 sequential connections, each connect() followed
  immediately by a small HTTP request

Results:
- in the backend namespace, TcpExtTSEcrRejected grew by 1004 to 1024
  per 1000 connections (3056 for 3000 in a captured run), i.e. every
  handshake ACK from SYNPROXY was rejected
- 0 to 7 of 1000 connections took 1.6 to 1.7 s instead of under 1 ms;
  TcpExtTCPSynRetrans in the backend grew by exactly the number of
  slow connections (6 of 1000 in one run, 14 of 3000 in the capture)
- without SYNPROXY: 0 of 1000 slow
- capture of one connection: backend SYN-ACK "TS val 1224945131", the
  ACK from SYNPROXY to the backend "TS ecr 2263544124"; the difference
  1038598993 is exactly tsoff of that connection (1224945131 minus
  the cookie TSval 186346138 sent to the client)

Possible fix (untested): build the server ACK with TSecr =
synproxy->its, so that synproxy_tstamp_adjust() brings it to the
backend's TSval, or keep the generated ACK out of the adjustment.

We can run a patch through the same lab if that helps.

Thanks,
Dominik Shaim Ulrich

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [BUG] netfilter: synproxy: server ACK carries TSecr shifted twice, rejected by tcp_check_req() since v6.15
  2026-11-16 14:23 [BUG] netfilter: synproxy: server ACK carries TSecr shifted twice, rejected by tcp_check_req() since v6.15 info
@ 2026-11-16 22:37 ` Florian Westphal
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Westphal @ 2026-11-16 22:37 UTC (permalink / raw)
  To: info
  Cc: netfilter-devel, netdev, coreteam, Pablo Neira Ayuso, Phil Sutter,
	Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima, David S. Miller,
	Jakub Kicinski, Paolo Abeni, Simon Horman

info@openservis.cz <info@openservis.cz> wrote:
> Possible fix (untested): build the server ACK with TSecr =
> synproxy->its, so that synproxy_tstamp_adjust() brings it to the
> backend's TSval, or keep the generated ACK out of the adjustment.
> 
> We can run a patch through the same lab if that helps.

Please try this patch:

netfilter: synproxy: fix double tsoff application in server ACK TSecr

diff --git a/net/netfilter/nf_synproxy_core.c b/net/netfilter/nf_synproxy_core.c
--- a/net/netfilter/nf_synproxy_core.c
+++ b/net/netfilter/nf_synproxy_core.c
@@ -651,6 +651,7 @@ ipv4_synproxy_hook(void *priv, struct sk_buff *skb,
 	const struct ip_ct_tcp *state;
 	struct tcphdr *th, _th;
 	unsigned int thoff;
+	u32 tsval, tsecr;
 
 	ct = nf_ct_get(skb, &ctinfo);
 	if (!ct)
@@ -732,13 +733,18 @@ ipv4_synproxy_hook(void *priv, struct sk_buff *skb,
 				  NF_SYNPROXY_OPT_WSCALE |
 				  NF_SYNPROXY_OPT_SACK_PERM);
 
-		swap(opts.tsval, opts.tsecr);
+		tsval = opts.tsval;
+		tsecr = opts.tsecr;
+
+		opts.tsval = tsecr;
+		opts.tsecr = tsval - synproxy->tsoff;
 		synproxy_send_server_ack(net, state, skb, th, &opts);
 
 		nf_ct_seqadj_init(ct, ctinfo, synproxy->isn - ntohl(th->seq));
 		nf_conntrack_event_cache(IPCT_SEQADJ, ct);
 
-		swap(opts.tsval, opts.tsecr);
+		opts.tsecr = tsecr;
+		opts.tsval = tsval;
 		synproxy_send_client_ack(net, skb, th, &opts);
 
 		consume_skb(skb);
@@ -1074,6 +1080,7 @@ ipv6_synproxy_hook(void *priv, struct sk_buff *skb,
 	struct synproxy_options opts = {};
 	const struct ip_ct_tcp *state;
 	struct tcphdr *th, _th;
+	u32 tsval, tsecr;
 	__be16 frag_off;
 	u8 nexthdr;
 	int thoff;
@@ -1162,13 +1169,18 @@ ipv6_synproxy_hook(void *priv, struct sk_buff *skb,
 				  NF_SYNPROXY_OPT_WSCALE |
 				  NF_SYNPROXY_OPT_SACK_PERM);
 
-		swap(opts.tsval, opts.tsecr);
+		tsval = opts.tsval;
+		tsecr = opts.tsecr;
+
+		opts.tsval = tsecr;
+		opts.tsecr = tsval - synproxy->tsoff;
 		synproxy_send_server_ack_ipv6(net, state, skb, th, &opts);
 
 		nf_ct_seqadj_init(ct, ctinfo, synproxy->isn - ntohl(th->seq));
 		nf_conntrack_event_cache(IPCT_SEQADJ, ct);
 
-		swap(opts.tsval, opts.tsecr);
+		opts.tsecr = tsecr;
+		opts.tsval = tsval;
 		synproxy_send_client_ack_ipv6(net, skb, th, &opts);
 
 		consume_skb(skb);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-16 22:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 14:23 [BUG] netfilter: synproxy: server ACK carries TSecr shifted twice, rejected by tcp_check_req() since v6.15 info
2026-11-16 22:37 ` Florian Westphal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox