Skip to contentSkip to conversation

tcp: symmetric challenge ACK for SEG.ACK > SND.NXT

PATCH Superseded Jiayuan Chen 3 participants 7 messages Apr 20

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover tcp: symmetric challenge ACK for SEG.ACK > SND.NXT

Commit 354e4aa391ed ("tcp: RFC 5961 5.2 Blind Data Injection Attack Mitigation") quotes RFC 5961 Section 5.2 in full, which requires that any incoming segment whose ACK value falls outside [SND.UNA - MAX.SND.WND, SND.NXT] MUST be discarded and an ACK sent back. Linux currently sends that challenge ACK only on the lower edge (SEG.ACK < SND.UNA - MAX.SND.WND); on the symmetric upper edge (SEG.ACK > SND.NXT) the segment is silently dropped with SKB_DROP_REASON_TCP_ACK_UNSENT_DATA.

Patch 1 completes the mitigation by emitting a rate-limited challenge ACK on that branch, reusing tcp_send_challenge_ack() and honouring FLAG_NO_CHALLENGE_ACK for consistency with the lower-edge case.

Patch 2 adds a packetdrill selftest under tools/testing/selftests/net/packetdrill/ that verifies the new behaviour.

Jiayuan Chen (2):
tcp: send a challenge ACK on SEG.ACK > SND.NXT selftests/net: packetdrill: cover challenge ACK on SEG.ACK > SND.NXT

 net/ipv4/tcp_input.c                          | 10 ++++--
 .../tcp_rfc5961_ack-beyond-snd-nxt.pkt        | 31 +++++++++++++++++++
 2 files changed, 38 insertions(+), 3 deletions(-)
 create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rfc5961_ack-beyond-snd-nxt.pkt
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 tcp: send a challenge ACK on SEG.ACK > SND.NXT

RFC 5961 Section 5.2 validates an incoming segment's ACK value against the range [SND.UNA - MAX.SND.WND, SND.NXT] and states:

"All incoming segments whose ACK value doesn't satisfy the above
condition MUST be discarded and an ACK sent back."

Commit 354e4aa391ed ("tcp: RFC 5961 5.2 Blind Data Injection Attack Mitigation") opted Linux into this mitigation and implements the challenge ACK on the lower side (SEG.ACK < SND.UNA - MAX.SND.WND), but the symmetric upper side (SEG.ACK > SND.NXT) still takes the pre-RFC-5961 path and silently returns SKB_DROP_REASON_TCP_ACK_UNSENT_DATA, even though RFC 793 Section 3.9 (now RFC 9293 Section 3.10.7.4) has always required:

"If the ACK acknowledges something not yet sent (SEG.ACK > SND.NXT)
then send an ACK, drop the segment, and return."

Complete the mitigation by sending a challenge ACK on that branch, reusing the existing tcp_send_challenge_ack() path which already enforces the per-socket RFC 5961 Section 7 rate limit via __tcp_oow_rate_limited(). FLAG_NO_CHALLENGE_ACK is honoured for symmetry with the lower-edge case.

Fixes 354e4aa391ed ("tcp: RFC 5961 5.2 Blind Data Injection Attack Mitigation")

---
I'm not sure if 'blamed commit' is appropriate, because I think it's due to missing parts of the implementation, or it might be directly targeted to net-next.

---
 net/ipv4/tcp_input.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
net/ipv4/tcp_input.c +7 -3
index 021f745747c5..c2b6f05acdfa 100644
@@ -4284,11 +4284,15 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
 		goto old_ack;
 	}
 
-	/* If the ack includes data we haven't sent yet, discard
-	 * this segment (RFC793 Section 3.9).
+	/* If the ack includes data we haven't sent yet, drop the
+	 * segment.  RFC 793 Section 3.9 and RFC 5961 Section 5.2
+	 * require us to send an ACK back in that case.
 	 */
-	if (after(ack, tp->snd_nxt))
+	if (after(ack, tp->snd_nxt)) {
+		if (!(flag & FLAG_NO_CHALLENGE_ACK))
+			tcp_send_challenge_ack(sk, false);
 		return -SKB_DROP_REASON_TCP_ACK_UNSENT_DATA;
+	}
 
 	if (after(ack, prior_snd_una)) {
 		flag |= FLAG_SND_UNA_ADVANCED;
Signature · 1 line
2.43.0
#3 lore raw

PATCH 2/2 selftests/net: packetdrill: cover challenge ACK on SEG.ACK > SND.NXT

In reply to Jiayuan Chen

Exercise the RFC 5961 Section 5.2 / RFC 793 Section 3.9 requirement on the upper edge of the acceptable ACK range, mirroring the existing coverage of the SEG.ACK < SND.UNA - MAX.SND.WND case.

After the peer ACKs data the receiver has never sent, the receiver must respond with <SEQ = SND.NXT, ACK = RCV.NXT, CTL = ACK> and drop the offending segment. The script validates this exact response.

---
 .../tcp_rfc5961_ack-beyond-snd-nxt.pkt        | 31 +++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rfc5961_ack-beyond-snd-nxt.pkt
tools/testing/selftests/net/packetdrill/tcp_rfc5961_ack-beyond-snd-nxt.pkt new file +31 -0
new file mode 100644
index 000000000000..29d61a98d5ef
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// RFC 5961 Section 5.2 / RFC 793 Section 3.9: when a received
+// segment's SEG.ACK acknowledges data we have never sent
+// (SEG.ACK > SND.NXT), the receiver MUST discard the segment and
+// send a challenge ACK back.
+//
+// Complement the existing mitigation for the symmetric
+// (SEG.ACK < SND.UNA - MAX.SND.WND) case.
+
+`./defaults.sh`
+
+   // Open listener socket
+    0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+   +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+   +0 bind(3, ..., ...) = 0
+   +0 listen(3, 1) = 0
+
+   // Three-way handshake
+   +0 < S 0:0(0) win 32792 <mss 1000,sackOK,nop,nop,nop,wscale 7>
+   +0 > S. 0:0(0) ack 1 <...>
+ +.1 < . 1:1(0) ack 1 win 257
+   +0 accept(3, ..., ...) = 4
+
+   // Server has sent no data yet: SND.UNA = SND.NXT = 1, RCV.NXT = 1.
+   // Peer sends a pure ACK with SEG.ACK = 2, which is > SND.NXT.
+   +0 < . 1:1(0) ack 2 win 257
+
+   // Expect an immediate challenge ACK:
+   //   <SEQ = SND.NXT = 1, ACK = RCV.NXT = 1, CTL = ACK>
+   +0 > . 1:1(0) ack 1
Signature · 1 line
2.43.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH net 1/2] tcp: send a challenge ACK on SEG.ACK > SND.NXT

In reply to Jiayuan Chen
Quoted 24 lines · Jiayuan Chen

RFC 5961 Section 5.2 validates an incoming segment's ACK value against the range [SND.UNA - MAX.SND.WND, SND.NXT] and states:

"All incoming segments whose ACK value doesn't satisfy the above
condition MUST be discarded and an ACK sent back."

Commit 354e4aa391ed ("tcp: RFC 5961 5.2 Blind Data Injection Attack Mitigation") opted Linux into this mitigation and implements the challenge ACK on the lower side (SEG.ACK < SND.UNA - MAX.SND.WND), but the symmetric upper side (SEG.ACK > SND.NXT) still takes the pre-RFC-5961 path and silently returns SKB_DROP_REASON_TCP_ACK_UNSENT_DATA, even though RFC 793 Section 3.9 (now RFC 9293 Section 3.10.7.4) has always required:

"If the ACK acknowledges something not yet sent (SEG.ACK > SND.NXT)
then send an ACK, drop the segment, and return."

Complete the mitigation by sending a challenge ACK on that branch, reusing the existing tcp_send_challenge_ack() path which already enforces the per-socket RFC 5961 Section 7 rate limit via __tcp_oow_rate_limited(). FLAG_NO_CHALLENGE_ACK is honoured for symmetry with the lower-edge case.

Quoted 7 lines
Fixes 354e4aa391ed ("tcp: RFC 5961 5.2 Blind Data Injection Attack Mitigation")

---
I'm not sure if 'blamed commit' is appropriate, because I think it's due to missing parts of the implementation, or it might be directly targeted to net-next.

The Fixes: tag seems appropriate, and net tree LGTM.

Thanks!

Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH net 2/2] selftests/net: packetdrill: cover challenge ACK on SEG.ACK > SND.NXT

In reply to Jiayuan Chen
Quoted 10 lines · Jiayuan Chen

Exercise the RFC 5961 Section 5.2 / RFC 793 Section 3.9 requirement on the upper edge of the acceptable ACK range, mirroring the existing coverage of the SEG.ACK < SND.UNA - MAX.SND.WND case.

After the peer ACKs data the receiver has never sent, the receiver must respond with <SEQ = SND.NXT, ACK = RCV.NXT, CTL = ACK> and drop the offending segment. The script validates this exact response.

Thanks!

maintainer
#5 lore raw
In reply to Jiayuan Chen
Quoted 9 lines · On Mon, 20 Apr 2026 10:54:07 +0800 Jiayuan Chen wrote:

Commit 354e4aa391ed ("tcp: RFC 5961 5.2 Blind Data Injection Attack Mitigation") quotes RFC 5961 Section 5.2 in full, which requires that any incoming segment whose ACK value falls outside [SND.UNA - MAX.SND.WND, SND.NXT] MUST be discarded and an ACK sent back. Linux currently sends that challenge ACK only on the lower edge (SEG.ACK < SND.UNA - MAX.SND.WND); on the symmetric upper edge (SEG.ACK > SND.NXT) the segment is silently dropped with SKB_DROP_REASON_TCP_ACK_UNSENT_DATA.

Quoted 7 lines

Patch 1 completes the mitigation by emitting a rate-limited challenge ACK on that branch, reusing tcp_send_challenge_ack() and honouring FLAG_NO_CHALLENGE_ACK for consistency with the lower-edge case.

Patch 2 adds a packetdrill selftest under tools/testing/selftests/net/packetdrill/ that verifies the new behaviour.

AI says:

Your patch "tcp: send a challenge ACK on SEG.ACK > SND.NXT" breaks an existing packetdrill selftest:

selftests/net/packetdrill/tcp_ts_recent_invalid_ack.pkt

Test output:
tcp_ts_recent_invalid_ack.pkt:25: error handling packet:
live packet field tcp_ack_seq: expected: 1001 (0x3e9) vs actual: 1 (0x1) script packet: 0.200125 . 1:1(0) ack 1001 <nop,nop,TS val 200 ecr 201> actual packet: 0.200119 . 1:1(0) ack 1 win 65535 <nop,nop,TS val 200 ecr 200> not ok 1 ipv4
not ok 2 ipv6
not ok 3 ipv4-mapped-ipv6

Root cause:

The test tcp_ts_recent_invalid_ack.pkt sends a FIN+ACK with ACK=9999 (which exceeds SND.NXT=1) to verify that the kernel does not update ts_recent from an invalid packet. Before your patch, this packet was silently dropped. After your patch, the kernel now emits a challenge ACK (SEQ=1, ACK=1) in response to the ACK=9999 segment.

The test script does not expect this challenge ACK, so when it subsequently tries to match the expected "ack 1001" response to the following data segment, it instead sees the challenge ACK "ack 1", causing a mismatch on all three address families (ipv4, ipv6, ipv4-mapped-ipv6).

Fix: update tcp_ts_recent_invalid_ack.pkt to consume the new challenge ACK before checking the response to the subsequent data segment. For example, add after the bad FIN+ACK line:

+0 > . 1:1(0) ack 1

so that the challenge ACK is explicitly expected and the rest of the script proceeds as before.

#6 lore raw
Quoted 29 lines · Jakub Kicinski

AI says:

Your patch "tcp: send a challenge ACK on SEG.ACK > SND.NXT" breaks an existing packetdrill selftest:

selftests/net/packetdrill/tcp_ts_recent_invalid_ack.pkt

Test output:
tcp_ts_recent_invalid_ack.pkt:25: error handling packet:
live packet field tcp_ack_seq: expected: 1001 (0x3e9) vs actual: 1 (0x1) script packet: 0.200125 . 1:1(0) ack 1001 <nop,nop,TS val 200 ecr 201> actual packet: 0.200119 . 1:1(0) ack 1 win 65535 <nop,nop,TS val 200 ecr 200> not ok 1 ipv4
not ok 2 ipv6
not ok 3 ipv4-mapped-ipv6

Root cause:

The test tcp_ts_recent_invalid_ack.pkt sends a FIN+ACK with ACK=9999 (which exceeds SND.NXT=1) to verify that the kernel does not update ts_recent from an invalid packet. Before your patch, this packet was silently dropped. After your patch, the kernel now emits a challenge ACK (SEQ=1, ACK=1) in response to the ACK=9999 segment.

The test script does not expect this challenge ACK, so when it subsequently tries to match the expected "ack 1001" response to the following data segment, it instead sees the challenge ACK "ack 1", causing a mismatch on all three address families (ipv4, ipv6, ipv4-mapped-ipv6).

Quoted 8 lines

Fix: update tcp_ts_recent_invalid_ack.pkt to consume the new challenge ACK before checking the response to the subsequent data segment. For example, add after the bad FIN+ACK line:

   +0 > . 1:1(0) ack 1

so that the challenge ACK is explicitly expected and the rest of the script proceeds as before.

Thanks Jakub, you're right.

Will fold the tcp_ts_recent_invalid_ack.pkt update into the kernel fix in v2

to keep bisect clean and makes the backport self-contained.