From: Florian Westphal <f…@strlen.de>
When SYNPROXY is active with timestamp options enabled, the handshake ACK
sent to the backend carries a TSecr that is off by synproxy->tsoff.
The code swaps tsval and tsecr before calling synproxy_send_server_ack().
The ACK is built with the correct TSecr (the server's TSval), but it
re-enters ipv4_synproxy_hook() on its way out, where
synproxy_tstamp_adjust() adds tsoff to TSecr a second time.
Since commit 3ba075278c11 ("tcp: be less liberal in TSEcr received while in
SYN_RECV state") Linux TCP performs stricter validation and such backends
will drops the ACK. This will delay connection establishment until the
server SYN-ACK retransmit, which may take a few seconds.
Replace the swap() by explicit initialisation of tsval/tsecr for both
the server and client ACKs. Build the server ACK with TSecr
pre-compensated (server TSval - tsoff), so that the adjustment on
re-entry yields the server's actual TSval.
Fixes: 48b1de4c110a ("netfilter: add SYNPROXY core/target")
Reported-and-tested-by: Dominik Shaim Ulrich <in…@openservis.cz>
Closes: https://lore.kernel.org/netfilter-devel/CAFvzkdAXBNAWcHFNo6akAo63Wd8B_jvhkt=AEmu…@mail.gmail.com/
Signed-off-by: Florian Westphal <f…@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pab…@netfilter.org>
---
net/netfilter/nf_synproxy_core.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/net/netfilter/nf_synproxy_core.c b/net/netfilter/nf_synproxy_core.c
index 9dd681596c70..559db2c972f8 100644
--- a/net/netfilter/nf_synproxy_core.c
+++ b/net/netfilter/nf_synproxy_core.c
@@ -661,6 +661,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)
@@ -742,13 +743,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);
@@ -1093,6 +1099,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;
@@ -1181,13 +1188,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);
--
2.47.3