tcp: do not accept ACK of our ISS on active opens
Subsystems (5)
Eric Dumazet
maintainercover tcp: do not accept ACK of our ISS on active opens
Michael Tuexen asked on the tcpm list whether, after a completed handshake, a segment with SEG.ACK == ISS is a duplicate ACK or a ghost ACK [1]. Flavius-Romeo Mazilu noted that Linux gives a different answer on each side of the connection [2]: passive opens send a challenge ACK, active opens silently accept the segment.
The first patch makes active opens (including Fast Open and simultaneous opens) behave like passive ones, without changing the value of tcpi_bytes_acked seen by user space and BPF.
The second patch adds packetdrill tests for the four ways a socket can be established.
This closes one extra acceptable ACK value on active opens, so this is targeting net-next.
[1] https://mailarchive.ietf.org/arch/msg/tcpm/ZbjDTFQSHeKSVHAToyAnKBr3TpU/
[2] https://mailarchive.ietf.org/arch/msg/tcpm/ym6lb-UkrW2298LRnTLxCysoo0g/
Eric Dumazet (2):
tcp: do not accept ACK of our ISS on active opens selftests/net: packetdrill: add tests for ACK of ISS
.../networking/net_cachelines/tcp_sock.rst | 1 + include/linux/tcp.h | 3 +- net/ipv4/tcp.c | 1 + net/ipv4/tcp_input.c | 10 +++- .../tcp_rfc5961_ack-iss-client.pkt | 46 +++++++++++++++++++ .../tcp_rfc5961_ack-iss-fastopen-client.pkt | 40 ++++++++++++++++ .../tcp_rfc5961_ack-iss-server.pkt | 45 ++++++++++++++++++ .../tcp_rfc5961_ack-iss-simultaneous-open.pkt | 42 +++++++++++++++++ 8 files changed, 185 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rfc5961_ack-iss-client.pkt create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rfc5961_ack-iss-fastopen-client.pkt create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rfc5961_ack-iss-server.pkt create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rfc5961_ack-iss-simultaneous-open.pkt
base-commit: d6816d9a93b66a12bf01e10037e377f3333ad6cc
Signature · 1 line
2.53.0
Eric Dumazet
maintainerPATCH 1/2 tcp: do not accept ACK of our ISS on active opens
Michael Tuexen asked on the tcpm list [1] whether, after a completed handshake, a segment with SEG.ACK == ISS is a duplicate ACK or a ghost ACK. Flavius-Romeo Mazilu answered that Linux behaves differently depending on which side opened the connection:
- passive opens drop it and send a challenge ACK,
- active opens accept it as an old duplicate ACK.
This comes from commit 3d501dd326fb ("tcp: do not accept ACK of bytes we never sent"), which bounds the range of acceptable old ACKs by tp->bytes_acked.
On active opens (including Fast Open and simultaneous opens), tp->snd_una starts at ISS and the ACK of our SYN goes through tcp_snd_una_update(), so tp->bytes_acked counts the SYN. On passive opens, tp->snd_una starts at ISS + 1 and the SYN-ACK is not counted.
The SYN is not a payload byte, and no valid ACK ever carried ISS:
the lowest ACK a peer can send on a synchronized connection is ISS + 1.
Counting the SYN widens the acceptable range by one sequence number.
tp->bytes_acked is exported to user space (tcpi_bytes_acked, bpf_tcp_sock, bpf_sock_ops) and tools/testing/selftests/bpf expects the SYN to be counted, so leave it unchanged.
Instead, remember in a new bit that our SYN was counted, and subtract it in the tcp_ack() check.
Mazilu's observation was confirmed by code inspection and with packetdrill on an unmodified kernel: after an active open, a segment with SEG.ACK == ISS is silently accepted, where a passive open answers with a challenge ACK.
Tested with the packetdrill tests added in the following patch, which fail on the active side before this patch, and with the other tests in tools/testing/selftests/net/packetdrill.
[1] https://mailarchive.ietf.org/arch/msg/tcpm/ZbjDTFQSHeKSVHAToyAnKBr3TpU/
--- Documentation/networking/net_cachelines/tcp_sock.rst | 1 + include/linux/tcp.h | 3 ++- net/ipv4/tcp.c | 1 + net/ipv4/tcp_input.c | 10 ++++++++-- 4 files changed, 12 insertions(+), 3 deletions(-)
Documentation/networking/net_cachelines/tcp_sock.rst +1 -0
@@ -59,6 +59,7 @@ u8:2 fastopen_client_fail u8:4 nonagle read_write tcp_skb_entail,tcp_push_pending_frames u8:1 thin_lto u8:1 recvmsg_inq read_mostly tcp_recvmsg +u8:1 bytes_acked_syn read_mostly tcp_ack u8:1 repair read_mostly tcp_write_xmit u8:1 frto u8 repair_queue
include/linux/tcp.h +2 -1
@@ -235,7 +235,8 @@ struct tcp_sock { tcp_usec_ts : 1, /* TSval values in usec */ is_sack_reneg:1, /* in recovery from loss with SACK reneg? */ is_cwnd_limited:1,/* forward progress limited by snd_cwnd? */ - recvmsg_inq : 1;/* Indicate # of bytes in queue upon recvmsg */ + recvmsg_inq : 1,/* Indicate # of bytes in queue upon recvmsg */ + bytes_acked_syn:1;/* bytes_acked includes our SYN */#ifdef CONFIG_BPF u32 bpf_tcp_ops_flags;#define BPF_TCP_OPS_TEST_FLAG (TP ,ARG ) \
net/ipv4/tcp.c +1 -0
@@ -3472,6 +3472,7 @@ int tcp_disconnect(struct sock *sk, int flags) tp->segs_out =0 ; tp->bytes_sent =0 ; tp->bytes_acked =0 ; + tp->bytes_acked_syn =0 ; tp->bytes_received =0 ; tp->bytes_retrans =0 ; tp->data_segs_in =0 ;
net/ipv4/tcp_input.c +8 -2
@@ -3712,6 +3712,8 @@ static int tcp_clean_rtx_queue(struct sock *sk, const struct sk_buff *ack_skb, }else { flag |=FLAG_SYN_ACKED ; tp->retrans_stamp =0 ; +/* tcp_snd_una_update() counted our SYN. */ + tp->bytes_acked_syn =1 ; }if (!fully_acked)
@@ -4333,8 +4335,12 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)if (before (ack, prior_snd_una)) {u32 max_window; -/* do not accept ACK for bytes we never sent. */ - max_window =min_t (u64, tp->max_window, tp->bytes_acked); +/* Do not accept ACK for bytes we never sent. +* Our SYN, if counted in bytes_acked, is not one of them: +* no valid ACK ever carried ISS. +*/ + max_window =min_t (u64, tp->max_window, + tp->bytes_acked - tp->bytes_acked_syn);/* RFC 5961 5.2 [Blind Data Injection Attack].[Mitigation] */ if (before (ack, prior_snd_una - max_window)) {if (!(flag &FLAG_NO_CHALLENGE_ACK ))
Signature · 1 line
2.53.0
Eric Dumazet
maintainerPATCH 2/2 selftests/net: packetdrill: add tests for ACK of ISS
In reply to Eric DumazetOnce a connection is established, a segment with SEG.ACK == ISS acknowledges bytes we never sent. It must be dropped and a challenge ACK sent back (RFC 5961 Section 5.2), regardless of which side opened the connection.
Add four tests covering the ways a socket can be established:
- tcp_rfc5961_ack-iss-server.pkt: passive open
- tcp_rfc5961_ack-iss-client.pkt: active open
- tcp_rfc5961_ack-iss-fastopen-client.pkt: active open, data in SYN
- tcp_rfc5961_ack-iss-simultaneous-open.pkt: crossed SYNs
Each test also checks that SEG.ACK == ISS + 1 is still silently accepted as a genuine old ACK.
Only the passive open test passes without the previous patch.
--- .../tcp_rfc5961_ack-iss-client.pkt | 46 +++++++++++++++++++ .../tcp_rfc5961_ack-iss-fastopen-client.pkt | 40 ++++++++++++++++ .../tcp_rfc5961_ack-iss-server.pkt | 45 ++++++++++++++++++ .../tcp_rfc5961_ack-iss-simultaneous-open.pkt | 42 +++++++++++++++++ 4 files changed, 173 insertions(+) create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rfc5961_ack-iss-client.pkt create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rfc5961_ack-iss-fastopen-client.pkt create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rfc5961_ack-iss-server.pkt create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rfc5961_ack-iss-simultaneous-open.pkt
tools/testing/selftests/net/packetdrill/tcp_rfc5961_ack-iss-client.pkt new file +46 -0
@@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Active open: once the connection is established, SND.UNA is at least +// ISS + 1. A segment with SEG.ACK = ISS acknowledges nothing we ever +// sent past the SYN, and the SYN itself can not be acked "again" as a +// stale duplicate: no ACK carrying ISS was ever valid on this +// connection. It must be treated like any other ACK for bytes we never +// sent (RFC 5961 Section 5.2): dropped, and a challenge ACK sent back. +// +// The SYN consumes one sequence number but is not a payload byte, so it +// must not widen the range of acceptable old ACKs. + +`./defaults.sh +sysctl -q net.ipv4.tcp_invalid_ratelimit=0 +` + + 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 + +0 fcntl(3, F_GETFL) = 0x2 (flags O_RDWR) + +0 fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0 + +0 connect(3, ..., ...) = -1 EINPROGRESS (Operation now in progress) + +0 > S 0:0(0) <...> ++.01 < S. 0:0(0) ack 1 win 10000 <mss 1000,nop,nop,sackOK,nop,wscale 0> + +0 > . 1:1(0) ack 1 + +// SND.UNA = SND.NXT = ISS + 1, no payload acked yet. +// SEG.ACK = ISS must trigger a challenge ACK. ++.01 < . 1:1(0) ack 0 win 10000 + +0 > . 1:1(0) ack 1 + +// Get 1000 bytes of payload acked. + +0 write(3, ..., 1000) = 1000 + +0 > P. 1:1001(1000) ack 1 ++.01 < . 1:1(0) ack 1001 win 10000 + +// SND.UNA = ISS + 1001. Old ACKs in [ISS + 1, ISS + 1001] are valid +// duplicates, but SEG.ACK = ISS is still below anything the peer could +// have legitimately sent. ++.01 < . 1:1(0) ack 0 win 10000 + +0 > . 1001:1001(0) ack 1 + +// SEG.ACK = ISS + 1 is a genuine old ACK: silently accepted, no +// challenge ACK. The next packet on the wire must be our new data. ++.01 < . 1:1(0) ack 1 win 10000 ++.01 write(3, ..., 1000) = 1000 + +0 > P. 1001:2001(1000) ack 1 ++.01 < . 1:1(0) ack 2001 win 10000
tools/testing/selftests/net/packetdrill/tcp_rfc5961_ack-iss-fastopen-client.pkt new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Fast Open variant of tcp_rfc5961_ack-iss-client.pkt. +// +// The SYN carries data, and the SYN-ACK acks both the SYN and its +// payload. SEG.ACK = ISS must still trigger a challenge ACK, while +// SEG.ACK = ISS + 1 (SYN acked, payload not yet) is a valid old ACK. + +`./defaults.sh + ./set_sysctls.py /proc/sys/net/ipv4/tcp_timestamps=0 \ + /proc/sys/net/ipv4/tcp_invalid_ratelimit=0` + +// Cache warmup: send a Fast Open cookie request + 0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 3 + +0 sendto(3, ..., 0, MSG_FASTOPEN, ..., ...) = -1 EINPROGRESS (Operation is now in progress) + +0 > S 0:0(0) <mss 1460,nop,nop,sackOK,nop,wscale 8,FO,nop,nop> + +0 < S. 123:123(0) ack 1 win 14600 <mss 1460,nop,nop,sackOK,nop,wscale 6,FO abcd1234,nop,nop> + +0 > . 1:1(0) ack 1 + +0 close(3) = 0 + +0 > F. 1:1(0) ack 1 + +0 < F. 1:1(0) ack 2 win 92 + +0 > . 2:2(0) ack 2 + +// SYN + 500 bytes of payload, all acked by the SYN-ACK. + +0 socket(..., SOCK_STREAM|SOCK_NONBLOCK, IPPROTO_TCP) = 4 + +0 sendto(4, ..., 500, MSG_FASTOPEN, ..., ...) = 500 + +0 > S 0:500(500) <mss 1460,nop,nop,sackOK,nop,wscale 8,FO abcd1234,nop,nop> + +.01 < S. 0:0(0) ack 501 win 14600 <mss 1460,nop,nop,sackOK,nop,wscale 6> + +0 > . 501:501(0) ack 1 + +// SND.UNA = ISS + 501. SEG.ACK = ISS must trigger a challenge ACK. + +.01 < . 1:1(0) ack 0 win 1000 + +0 > . 501:501(0) ack 1 + +// SEG.ACK = ISS + 1 is a genuine old ACK: silently accepted, no +// challenge ACK. The next packet on the wire must be our new data. + +.01 < . 1:1(0) ack 1 win 1000 + +.01 write(4, ..., 100) = 100 + +0 > P. 501:601(100) ack 1 + +.01 < . 1:1(0) ack 601 win 1000
tools/testing/selftests/net/packetdrill/tcp_rfc5961_ack-iss-server.pkt new file +45 -0
45 lines not on this page · raw message
tools/testing/selftests/net/packetdrill/tcp_rfc5961_ack-iss-simultaneous-open.pkt new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.53.0
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Wed, 18 Nov 2026 18:26:52 +0100 you wrote:
Michael Tuexen asked on the tcpm list whether, after a completed handshake, a segment with SEG.ACK == ISS is a duplicate ACK or a ghost ACK [1]. Flavius-Romeo Mazilu noted that Linux gives a different answer on each side of the connection [2]: passive opens send a challenge ACK, active opens silently accept the segment.
The first patch makes active opens (including Fast Open and simultaneous opens) behave like passive ones, without changing the value of
tcpi_bytes_ackedseen by user space and BPF.[...]
Here is the summary with links:
- [net-next,1/2] tcp: do not accept ACK of our ISS on active opens
https://git.kernel.org/netdev/net-next/c/a25df726c715 - [net-next,2/2] selftests/net: packetdrill: add tests for ACK of ISS https://git.kernel.org/netdev/net-next/c/5fa71aea9d59
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html