* [PATCH RFC net-next v2 1/5] tcp: implement RFC 7323 window retraction receiver requirements
2026-02-26 0:49 [PATCH RFC net-next v2 0/5] tcp: RFC 7323-compliant window retraction handling Simon Baatz via B4 Relay
@ 2026-02-26 0:49 ` Simon Baatz via B4 Relay
2026-02-26 0:49 ` [PATCH RFC net-next v2 2/5] tcp: increase LINUX_MIB_BEYOND_WINDOW for SKB_DROP_REASON_TCP_OVERWINDOW Simon Baatz via B4 Relay
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Simon Baatz via B4 Relay @ 2026-02-26 0:49 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima, David S. Miller,
Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet,
Shuah Khan, David Ahern, Stefano Brivio, Jon Maloy, Jason Xing,
mfreemon, Shuah Khan, Stefano Brivio
Cc: Christian Ebner, netdev, linux-doc, linux-kernel, linux-kselftest,
Simon Baatz
From: Simon Baatz <gmbnomis@gmail.com>
By default, the Linux TCP implementation does not shrink the
advertised window (RFC 7323 calls this "window retraction") with the
following exceptions:
- When an incoming segment cannot be added due to the receive buffer
running out of memory. Since commit 8c670bdfa58e ("tcp: correct
handling of extreme memory squeeze") a zero window will be
advertised in this case. It turns out that reaching the required
"memory pressure" is very easy when window scaling is in use. In the
simplest case, sending a sufficient number of segments smaller than
the scale factor to a receiver that does not read data is enough.
Since commit 1d2fbaad7cd8 ("tcp: stronger sk_rcvbuf checks") this
happens much earlier than before, leading to regressions (the test
suite of the Valkey project does not pass because of a TCP
connection that is no longer bi-directional).
- Commit b650d953cd39 ("tcp: enforce receive buffer memory limits by
allowing the tcp window to shrink") addressed the "eating memory"
problem by introducing a sysctl knob that allows shrinking the
window before running out of memory.
However, RFC 7323 does not only state that shrinking the window is
necessary in some cases, it also formulates requirements for TCP
implementations when doing so (Section 2.4).
This commit addresses the receiver-side requirements: After retracting
the window, the peer may have a snd_nxt that lies within a previously
advertised window but is now beyond the retracted window. This means
that all incoming segments (including pure ACKs) will be rejected
until the application happens to read enough data to let the peer's
snd_nxt be in window again (which may be never).
To comply with RFC 7323, the receiver MUST honor any segment that
would have been in window for any ACK sent by the receiver and, when
window scaling is in effect, SHOULD track the maximum window sequence
number it has advertised. This patch tracks that maximum window
sequence number throughout the connection and uses it in
tcp_sequence() when deciding whether a segment is acceptable.
The logic for handling received data in tcp_data_queue() is already
sufficient and does not need to be updated.
Fixes: 8c670bdfa58e ("tcp: correct handling of extreme memory squeeze")
Fixes: b650d953cd39 ("tcp: enforce receive buffer memory limits by allowing the tcp window to shrink")
Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
---
Documentation/networking/net_cachelines/tcp_sock.rst | 1 +
include/linux/tcp.h | 3 +++
include/net/tcp.h | 13 +++++++++++++
net/ipv4/tcp.c | 1 +
net/ipv4/tcp_fastopen.c | 1 +
net/ipv4/tcp_input.c | 6 ++++--
net/ipv4/tcp_minisocks.c | 1 +
net/ipv4/tcp_output.c | 12 ++++++++++++
.../selftests/net/packetdrill/tcp_rcv_big_endseq.pkt | 2 +-
9 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/Documentation/networking/net_cachelines/tcp_sock.rst b/Documentation/networking/net_cachelines/tcp_sock.rst
index 563daea10d6c5c074f004cb1b8574f5392157abb..fecf61166a54ee2f64bcef5312c81dcc4aa9a124 100644
--- a/Documentation/networking/net_cachelines/tcp_sock.rst
+++ b/Documentation/networking/net_cachelines/tcp_sock.rst
@@ -121,6 +121,7 @@ u64 delivered_mstamp read_write
u32 rate_delivered read_mostly tcp_rate_gen
u32 rate_interval_us read_mostly rate_delivered,rate_app_limited
u32 rcv_wnd read_write read_mostly tcp_select_window,tcp_receive_window,tcp_fast_path_check
+u32 rcv_mwnd_seq read_write tcp_select_window
u32 write_seq read_write tcp_rate_check_app_limited,tcp_write_queue_empty,tcp_skb_entail,forced_push,tcp_mark_push
u32 notsent_lowat read_mostly tcp_stream_memory_free
u32 pushed_seq read_write tcp_mark_push,forced_push
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index f72eef31fa23cc584f2f0cefacdc35cae43aa52d..73aa2e0ccd1d7a6314a00c27950b019b62a3851c 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -316,6 +316,9 @@ struct tcp_sock {
*/
u32 app_limited; /* limited until "delivered" reaches this val */
u32 rcv_wnd; /* Current receiver window */
+ u32 rcv_mwnd_seq; /* Maximum window sequence number (RFC 7323,
+ * section 2.4, receiver requirements)
+ */
u32 rcv_tstamp; /* timestamp of last received ACK (for keepalives) */
/*
* Options received (usually on last packet, some only on SYN packets).
diff --git a/include/net/tcp.h b/include/net/tcp.h
index eb8bf63fdafc3243469f293fd06aef0ce086c5a4..658552133d12edd9cef2aa97460a3e5bf129d74e 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -914,6 +914,19 @@ static inline u32 tcp_receive_window(const struct tcp_sock *tp)
return (u32) win;
}
+/* Compute the maximum receive window we ever advertised.
+ * Rcv_nxt can be after the window if our peer push more data
+ * than the offered window.
+ */
+static inline u32 tcp_max_receive_window(const struct tcp_sock *tp)
+{
+ s32 win = tp->rcv_mwnd_seq - tp->rcv_nxt;
+
+ if (win < 0)
+ win = 0;
+ return (u32) win;
+}
+
/* Choose a new window, without checks for shrinking, and without
* scaling applied to the result. The caller does these things
* if necessary. This is a "raw" window selection.
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 6ce03a9adb4a97f554bd6b6cf887f4ad9dbfe5c3..6fcde6494a4f400731556be119ae21cbfd86bb27 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3578,6 +3578,7 @@ static int tcp_repair_set_window(struct tcp_sock *tp, sockptr_t optbuf, int len)
tp->rcv_wnd = opt.rcv_wnd;
tp->rcv_wup = opt.rcv_wup;
+ tp->rcv_mwnd_seq = opt.rcv_wup + opt.rcv_wnd;
return 0;
}
diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c
index df803f088f454cf157e0efbba8e2ff3f6d205530..4566e2289ad3d85171a9994032ba7f7366545286 100644
--- a/net/ipv4/tcp_fastopen.c
+++ b/net/ipv4/tcp_fastopen.c
@@ -377,6 +377,7 @@ static struct sock *tcp_fastopen_create_child(struct sock *sk,
tcp_rsk(req)->rcv_nxt = tp->rcv_nxt;
tp->rcv_wup = tp->rcv_nxt;
+ tp->rcv_mwnd_seq = tp->rcv_wup + tp->rcv_wnd;
/* tcp_conn_request() is sending the SYNACK,
* and queues the child into listener accept queue.
*/
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index e7b41abb82aad33d8cab4fcfa989cc4771149b41..af9dd51256b01fd31d9e390d69dcb1d1700daf1b 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -4865,8 +4865,8 @@ static enum skb_drop_reason tcp_sequence(const struct sock *sk,
if (before(end_seq, tp->rcv_wup))
return SKB_DROP_REASON_TCP_OLD_SEQUENCE;
- if (after(end_seq, tp->rcv_nxt + tcp_receive_window(tp))) {
- if (after(seq, tp->rcv_nxt + tcp_receive_window(tp)))
+ if (after(end_seq, tp->rcv_nxt + tcp_max_receive_window(tp))) {
+ if (after(seq, tp->rcv_nxt + tcp_max_receive_window(tp)))
return SKB_DROP_REASON_TCP_INVALID_SEQUENCE;
/* Only accept this packet if receive queue is empty. */
@@ -6959,6 +6959,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
*/
WRITE_ONCE(tp->rcv_nxt, TCP_SKB_CB(skb)->seq + 1);
tp->rcv_wup = TCP_SKB_CB(skb)->seq + 1;
+ tp->rcv_mwnd_seq = tp->rcv_wup + tp->rcv_wnd;
/* RFC1323: The window in SYN & SYN/ACK segments is
* never scaled.
@@ -7071,6 +7072,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
WRITE_ONCE(tp->rcv_nxt, TCP_SKB_CB(skb)->seq + 1);
WRITE_ONCE(tp->copied_seq, tp->rcv_nxt);
tp->rcv_wup = TCP_SKB_CB(skb)->seq + 1;
+ tp->rcv_mwnd_seq = tp->rcv_wup + tp->rcv_wnd;
/* RFC1323: The window in SYN & SYN/ACK segments is
* never scaled.
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index d9c5a43bd2818c17d79d8433ac5dd2bdd199b812..35e115b7a9db3da906c0fc3ef7d318d9d946f52a 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -604,6 +604,7 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
newtp->window_clamp = req->rsk_window_clamp;
newtp->rcv_ssthresh = req->rsk_rcv_wnd;
newtp->rcv_wnd = req->rsk_rcv_wnd;
+ newtp->rcv_mwnd_seq = newtp->rcv_wup + req->rsk_rcv_wnd;
newtp->rx_opt.wscale_ok = ireq->wscale_ok;
if (newtp->rx_opt.wscale_ok) {
newtp->rx_opt.snd_wscale = ireq->snd_wscale;
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 326b58ff1118d02fc396753d56f210f9d3007c7f..50774443f6ae0ca83f360c7fc3239184a1523e1b 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -274,6 +274,15 @@ void tcp_select_initial_window(const struct sock *sk, int __space, __u32 mss,
}
EXPORT_IPV6_MOD(tcp_select_initial_window);
+/* Check if we need to update the maximum window sequence number */
+static inline void tcp_update_max_wnd_seq(struct tcp_sock *tp)
+{
+ u32 wre = tp->rcv_wup + tp->rcv_wnd;
+
+ if (after(wre, tp->rcv_mwnd_seq))
+ tp->rcv_mwnd_seq = wre;
+}
+
/* Chose a new window to advertise, update state in tcp_sock for the
* socket, and return result with RFC1323 scaling applied. The return
* value can be stuffed directly into th->window for an outgoing
@@ -293,6 +302,7 @@ static u16 tcp_select_window(struct sock *sk)
tp->pred_flags = 0;
tp->rcv_wnd = 0;
tp->rcv_wup = tp->rcv_nxt;
+ tcp_update_max_wnd_seq(tp);
return 0;
}
@@ -316,6 +326,7 @@ static u16 tcp_select_window(struct sock *sk)
tp->rcv_wnd = new_win;
tp->rcv_wup = tp->rcv_nxt;
+ tcp_update_max_wnd_seq(tp);
/* Make sure we do not exceed the maximum possible
* scaled window.
@@ -4169,6 +4180,7 @@ static void tcp_connect_init(struct sock *sk)
else
tp->rcv_tstamp = tcp_jiffies32;
tp->rcv_wup = tp->rcv_nxt;
+ tp->rcv_mwnd_seq = tp->rcv_nxt + tp->rcv_wnd;
WRITE_ONCE(tp->copied_seq, tp->rcv_nxt);
inet_csk(sk)->icsk_rto = tcp_timeout_init(sk);
diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_big_endseq.pkt b/tools/testing/selftests/net/packetdrill/tcp_rcv_big_endseq.pkt
index 3848b419e68c3fc895ad736d06373fc32f3691c1..1a86ee5093696deb316c532ca8f7de2bbf5cd8ea 100644
--- a/tools/testing/selftests/net/packetdrill/tcp_rcv_big_endseq.pkt
+++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_big_endseq.pkt
@@ -36,7 +36,7 @@
+0 read(4, ..., 100000) = 4000
-// If queue is empty, accept a packet even if its end_seq is above wup + rcv_wnd
+// If queue is empty, accept a packet even if its end_seq is above rcv_mwnd_seq
+0 < P. 4001:54001(50000) ack 1 win 257
+0 > . 1:1(0) ack 54001 win 0
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH RFC net-next v2 2/5] tcp: increase LINUX_MIB_BEYOND_WINDOW for SKB_DROP_REASON_TCP_OVERWINDOW
2026-02-26 0:49 [PATCH RFC net-next v2 0/5] tcp: RFC 7323-compliant window retraction handling Simon Baatz via B4 Relay
2026-02-26 0:49 ` [PATCH RFC net-next v2 1/5] tcp: implement RFC 7323 window retraction receiver requirements Simon Baatz via B4 Relay
@ 2026-02-26 0:49 ` Simon Baatz via B4 Relay
2026-02-26 0:49 ` [PATCH RFC net-next v2 3/5] selftests/net: packetdrill: add tcp_rcv_wnd_shrink_nomem.pkt Simon Baatz via B4 Relay
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Simon Baatz via B4 Relay @ 2026-02-26 0:49 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima, David S. Miller,
Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet,
Shuah Khan, David Ahern, Stefano Brivio, Jon Maloy, Jason Xing,
mfreemon, Shuah Khan, Stefano Brivio
Cc: Christian Ebner, netdev, linux-doc, linux-kernel, linux-kselftest,
Simon Baatz
From: Simon Baatz <gmbnomis@gmail.com>
Since commit 9ca48d616ed7 ("tcp: do not accept packets beyond
window"), the path leading to SKB_DROP_REASON_TCP_OVERWINDOW in
tcp_data_queue() is probably dead. However, it can be reached now when
tcp_max_receive_window() is larger than tcp_receive_window(). In that
case, increment LINUX_MIB_BEYOND_WINDOW as done in tcp_sequence().
Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
---
net/ipv4/tcp_input.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index af9dd51256b01fd31d9e390d69dcb1d1700daf1b..f0ee3a599755aff00a00236728b430c7883087ff 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -5739,6 +5739,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
if (!before(TCP_SKB_CB(skb)->seq,
tp->rcv_nxt + tcp_receive_window(tp))) {
reason = SKB_DROP_REASON_TCP_OVERWINDOW;
+ NET_INC_STATS(sock_net(sk), LINUX_MIB_BEYOND_WINDOW);
goto out_of_window;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH RFC net-next v2 3/5] selftests/net: packetdrill: add tcp_rcv_wnd_shrink_nomem.pkt
2026-02-26 0:49 [PATCH RFC net-next v2 0/5] tcp: RFC 7323-compliant window retraction handling Simon Baatz via B4 Relay
2026-02-26 0:49 ` [PATCH RFC net-next v2 1/5] tcp: implement RFC 7323 window retraction receiver requirements Simon Baatz via B4 Relay
2026-02-26 0:49 ` [PATCH RFC net-next v2 2/5] tcp: increase LINUX_MIB_BEYOND_WINDOW for SKB_DROP_REASON_TCP_OVERWINDOW Simon Baatz via B4 Relay
@ 2026-02-26 0:49 ` Simon Baatz via B4 Relay
2026-02-26 0:49 ` [PATCH RFC net-next v2 4/5] selftests/net: packetdrill: add tcp_rcv_wnd_shrink_allowed.pkt Simon Baatz via B4 Relay
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Simon Baatz via B4 Relay @ 2026-02-26 0:49 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima, David S. Miller,
Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet,
Shuah Khan, David Ahern, Stefano Brivio, Jon Maloy, Jason Xing,
mfreemon, Shuah Khan, Stefano Brivio
Cc: Christian Ebner, netdev, linux-doc, linux-kernel, linux-kselftest,
Simon Baatz
From: Simon Baatz <gmbnomis@gmail.com>
This test verifies
- the sequence number checks using the maximum advertised window
sequence number and
- the logic for handling received data in tcp_data_queue()
for the cases:
1. The window is reduced to zero because of memory
2. The window grows again but still does not reach the originally
advertised window
Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
---
.../net/packetdrill/tcp_rcv_wnd_shrink_nomem.pkt | 141 +++++++++++++++++++++
1 file changed, 141 insertions(+)
diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_shrink_nomem.pkt b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_shrink_nomem.pkt
new file mode 100644
index 0000000000000000000000000000000000000000..8c30e231d7c82705f522f0e7bcdaffb9fb825974
--- /dev/null
+++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_shrink_nomem.pkt
@@ -0,0 +1,141 @@
+// SPDX-License-Identifier: GPL-2.0
+// When tcp_receive_window() < tcp_max_receive_window(), tcp_sequence() accepts
+// packets that would be dropped under normal conditions (i.e. tcp_receive_window()
+// equal to tcp_max_receive_window()).
+// Test that such packets are handled as expected for RWIN == 0 and for RWIN > 0.
+
+--mss=1000
+
+`./defaults.sh`
+
+ 0 `nstat -n`
+
+// Establish a connection.
+ +0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 setsockopt(3, SOL_SOCKET, SO_RCVBUF, [1000000], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 1) = 0
+
+ +0 < S 0:0(0) win 32792 <mss 1000,nop,nop,sackOK,nop,wscale 7>
+ +0 > S. 0:0(0) ack 1 win 65535 <mss 1460,nop,nop,sackOK,nop,wscale 4>
+ +0 < . 1:1(0) ack 1 win 257
+
+ +0 accept(3, ..., ...) = 4
+
+// Put 1040000 bytes into the receive buffer
+ +0 < P. 1:65001(65000) ack 1 win 257
+ * > . 1:1(0) ack 65001
+ +0 < P. 65001:130001(65000) ack 1 win 257
+ * > . 1:1(0) ack 130001
+ +0 < P. 130001:195001(65000) ack 1 win 257
+ * > . 1:1(0) ack 195001
+ +0 < P. 195001:260001(65000) ack 1 win 257
+ * > . 1:1(0) ack 260001
+ +0 < P. 260001:325001(65000) ack 1 win 257
+ * > . 1:1(0) ack 325001
+ +0 < P. 325001:390001(65000) ack 1 win 257
+ * > . 1:1(0) ack 390001
+ +0 < P. 390001:455001(65000) ack 1 win 257
+ * > . 1:1(0) ack 455001
+ +0 < P. 455001:520001(65000) ack 1 win 257
+ * > . 1:1(0) ack 520001
+ +0 < P. 520001:585001(65000) ack 1 win 257
+ * > . 1:1(0) ack 585001
+ +0 < P. 585001:650001(65000) ack 1 win 257
+ * > . 1:1(0) ack 650001
+ +0 < P. 650001:715001(65000) ack 1 win 257
+ * > . 1:1(0) ack 715001
+ +0 < P. 715001:780001(65000) ack 1 win 257
+ * > . 1:1(0) ack 780001
+ +0 < P. 780001:845001(65000) ack 1 win 257
+ * > . 1:1(0) ack 845001
+ +0 < P. 845001:910001(65000) ack 1 win 257
+ * > . 1:1(0) ack 910001
+ +0 < P. 910001:975001(65000) ack 1 win 257
+ * > . 1:1(0) ack 975001
+ +0 < P. 975001:1040001(65000) ack 1 win 257
+ * > . 1:1(0) ack 1040001
+
+// Trigger an extreme memory squeeze by shrinking SO_RCVBUF
+ +0 setsockopt(4, SOL_SOCKET, SO_RCVBUF, [16000], 4) = 0
+
+ +0 < P. 1040001:1105001(65000) ack 1 win 257
+ * > . 1:1(0) ack 1040001 win 0
+// Check LINUX_MIB_TCPRCVQDROP has been incremented
+ +0 `nstat -s | grep TcpExtTCPRcvQDrop| grep -q " 1 "`
+
+// RWIN == 0: rcv_wup = 1040001, rcv_wnd = 0, rcv_mwnd_seq > 1105001 (significantly larger, typically ~1970000)
+
+// Accept pure ack with seq in max adv. window
+ +0 write(4, ..., 1000) = 1000
+ +0 > P. 1:1001(1000) ack 1040001 win 0
+ +0 < . 1105001:1105001(0) ack 1001 win 257
+
+// In order segment, in max adv. window -> drop (SKB_DROP_REASON_TCP_ZEROWINDOW)
+ +0 < P. 1040001:1041001(1000) ack 1001 win 257
+ +0 > . 1001:1001(0) ack 1040001 win 0
+// Ooo partial segment, in max adv. window -> drop (SKB_DROP_REASON_TCP_ZEROWINDOW)
+ +0 < P. 1039001:1041001(2000) ack 1001 win 257
+ +0 > . 1001:1001(0) ack 1040001 win 0 <nop,nop,sack 1039001:1040001>
+// Check LINUX_MIB_TCPZEROWINDOWDROP has been incremented twice
+ +0 `nstat -s | grep TcpExtTCPZeroWindowDrop| grep -q " 2 "`
+
+// Ooo segment, in max adv. window -> drop (SKB_DROP_REASON_TCP_OVERWINDOW)
+ +0 < P. 1105001:1106001(1000) ack 1001 win 257
+ +0 > . 1001:1001(0) ack 1040001 win 0
+// Ooo segment, beyond max adv. window -> drop (SKB_DROP_REASON_TCP_INVALID_SEQUENCE)
+ +0 < P. 2000001:2001001(1000) ack 1001 win 257
+ +0 > . 1001:1001(0) ack 1040001 win 0
+// Check LINUX_MIB_BEYOND_WINDOW has been incremented twice
+ +0 `nstat -s | grep TcpExtBeyondWindow | grep -q " 2 "`
+
+// Read all data
+ +0 read(4, ..., 2000000) = 1040000
+ * > . 1001:1001(0) ack 1040001
+
+// RWIN > 0: rcv_wup = 1040001, 0 < rcv_wnd < 32000, rcv_mwnd_seq > 1105001 (significantly larger, typically ~1970000)
+
+// Accept pure ack with seq in max adv. window, beyond adv. window
+ +0 write(4, ..., 1000) = 1000
+ +0 > P. 1001:2001(1000) ack 1040001
+ +0 < . 1105001:1105001(0) ack 2001 win 257
+
+// In order segment, in max adv. window, in adv. window -> accept
+// Note: This also ensures that we cannot hit the empty queue exception in tcp_sequence() in the following tests
+ +0 < P. 1040001:1041001(1000) ack 2001 win 257
+ * > . 2001:2001(0) ack 1041001
+
+// Ooo partial segment, in adv. window -> accept
+ +0 < P. 1040001:1042001(2000) ack 2001 win 257
+ +0 > . 2001:2001(0) ack 1042001 <nop,nop,sack 1040001:1041001>
+
+// Ooo segment, in max adv. window, beyond adv. window -> drop (SKB_DROP_REASON_TCP_OVERWINDOW)
+ +0 < P. 1105001:1106001(1000) ack 2001 win 257
+ +0 > . 2001:2001(0) ack 1042001
+// Ooo segment, beyond max adv. window, beyond adv. window -> drop (SKB_DROP_REASON_TCP_INVALID_SEQUENCE)
+ +0 < P. 2000001:2001001(1000) ack 2001 win 257
+ +0 > . 2001:2001(0) ack 1042001
+// Check LINUX_MIB_BEYOND_WINDOW has been incremented twice
+ +0 `nstat -s | grep TcpExtBeyondWindow | grep -q " 4 "`
+
+// Let's probe how much more data we can squeeze in, 2 * 10k should be ok
+ +0 < P. 1042001:1052001(10000) ack 2001 win 257
+ * > . 2001:2001(0) ack 1052001
+ +0 < P. 1052001:1062001(10000) ack 2001 win 257
+ * > . 2001:2001(0) ack 1062001
+
+// Ooo segment, in max adv. window, seq 152002 in adv. window, not enough buffer space -> drop, _no_ ack
+ +0 < P. 1062002:1072002(10000) ack 2001 win 257
+// Check LINUX_MIB_TCPOFODROP has been incremented
+ +.1 `nstat -s | grep TcpExtTCPOFODrop | grep -q " 1 "`
+
+// In order segment, in max adv. window, not enough buffer space -> drop
+ +0 < P. 1062001:1072001(10000) ack 2001 win 257
+ +0 > . 2001:2001(0) ack 1062001 win 0
+// Check LINUX_MIB_TCPRCVQDROP has been incremented again
+ +0 `nstat -s | grep TcpExtTCPRcvQDrop | grep -q " 2 "`
+
+// Verify that our other counters did not change
+ +0 `nstat -s | grep TcpExtTCPZeroWindowDrop | grep -q " 2 "`
+ +0 `nstat -s | grep TcpExtBeyondWindow | grep -q " 4 "`
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH RFC net-next v2 4/5] selftests/net: packetdrill: add tcp_rcv_wnd_shrink_allowed.pkt
2026-02-26 0:49 [PATCH RFC net-next v2 0/5] tcp: RFC 7323-compliant window retraction handling Simon Baatz via B4 Relay
` (2 preceding siblings ...)
2026-02-26 0:49 ` [PATCH RFC net-next v2 3/5] selftests/net: packetdrill: add tcp_rcv_wnd_shrink_nomem.pkt Simon Baatz via B4 Relay
@ 2026-02-26 0:49 ` Simon Baatz via B4 Relay
2026-02-26 0:49 ` [PATCH RFC net-next v2 5/5] selftests/net: packetdrill: add tcp_rcv_neg_window.pkt Simon Baatz via B4 Relay
2026-02-26 8:12 ` [PATCH RFC net-next v2 0/5] tcp: RFC 7323-compliant window retraction handling Matthieu Baerts
5 siblings, 0 replies; 8+ messages in thread
From: Simon Baatz via B4 Relay @ 2026-02-26 0:49 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima, David S. Miller,
Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet,
Shuah Khan, David Ahern, Stefano Brivio, Jon Maloy, Jason Xing,
mfreemon, Shuah Khan, Stefano Brivio
Cc: Christian Ebner, netdev, linux-doc, linux-kernel, linux-kselftest,
Simon Baatz
From: Simon Baatz <gmbnomis@gmail.com>
This test verifies the sequence number checks using the maximum
advertised window sequence number when net.ipv4.tcp_shrink_window
is enabled.
Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
---
.../net/packetdrill/tcp_rcv_wnd_shrink_allowed.pkt | 40 ++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_shrink_allowed.pkt b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_shrink_allowed.pkt
new file mode 100644
index 0000000000000000000000000000000000000000..e2c73e464954331f45c11b3152f2eddecc55f88b
--- /dev/null
+++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_shrink_allowed.pkt
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0
+
+--mss=1000
+
+`./defaults.sh
+sysctl -q net.ipv4.tcp_shrink_window=1
+sysctl -q net.ipv4.tcp_rmem="4096 32768 $((32*1024*1024))"`
+
+ 0 `nstat -n`
+
+// Establish a connection.
+ +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
+
+ +0 < S 0:0(0) win 32792 <mss 1000,nop,wscale 7>
+ +0 > S. 0:0(0) ack 1 <mss 1460,nop,wscale 10>
+ +0 < . 1:1(0) ack 1 win 257
+
+ +0 accept(3, ..., ...) = 4
+
+ +0 < P. 1:10001(10000) ack 1 win 257
+ * > . 1:1(0) ack 10001 win 15
+
+ +0 < P. 10001:11024(1023) ack 1 win 257
+ * > . 1:1(0) ack 11024 win 13
+
+// Max window seq advertised 10001 + 15*1024 = 25361, last advertised: 11024 + 13*1024 = 24336
+
+// Segment beyond the max window is dropped
+ +0 < P. 11024:25362(14338) ack 1 win 257
+ * > . 1:1(0) ack 11024 win 13
+
+// Segment using the max window is accepted
+ +0 < P. 11024:25361(14337) ack 1 win 257
+ * > . 1:1(0) ack 25361 win 0
+
+// Check LINUX_MIB_BEYOND_WINDOW has been incremented once
+ +0 `nstat | grep TcpExtBeyondWindow | grep -q " 1 "`
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH RFC net-next v2 5/5] selftests/net: packetdrill: add tcp_rcv_neg_window.pkt
2026-02-26 0:49 [PATCH RFC net-next v2 0/5] tcp: RFC 7323-compliant window retraction handling Simon Baatz via B4 Relay
` (3 preceding siblings ...)
2026-02-26 0:49 ` [PATCH RFC net-next v2 4/5] selftests/net: packetdrill: add tcp_rcv_wnd_shrink_allowed.pkt Simon Baatz via B4 Relay
@ 2026-02-26 0:49 ` Simon Baatz via B4 Relay
2026-02-26 8:12 ` [PATCH RFC net-next v2 0/5] tcp: RFC 7323-compliant window retraction handling Matthieu Baerts
5 siblings, 0 replies; 8+ messages in thread
From: Simon Baatz via B4 Relay @ 2026-02-26 0:49 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima, David S. Miller,
Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet,
Shuah Khan, David Ahern, Stefano Brivio, Jon Maloy, Jason Xing,
mfreemon, Shuah Khan, Stefano Brivio
Cc: Christian Ebner, netdev, linux-doc, linux-kernel, linux-kselftest,
Simon Baatz
From: Simon Baatz <gmbnomis@gmail.com>
The test ensures we correctly apply the maximum advertised window limit
when rcv_nxt advances past rcv_mwnd_seq, so that the "usable window"
is properly clamped to zero rather than becoming negative.
Signed-off-by: Simon Baatz <gmbnomis@gmail.com>
---
.../net/packetdrill/tcp_rcv_neg_window.pkt | 26 ++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcv_neg_window.pkt b/tools/testing/selftests/net/packetdrill/tcp_rcv_neg_window.pkt
new file mode 100644
index 0000000000000000000000000000000000000000..15a9b4938f16d175ac54f3fd192ed2b59b0a4399
--- /dev/null
+++ b/tools/testing/selftests/net/packetdrill/tcp_rcv_neg_window.pkt
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0
+
+--mss=1000
+
+`./defaults.sh`
+
+// Establish a connection.
+ +0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 setsockopt(3, SOL_SOCKET, SO_RCVBUF, [20000], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 1) = 0
+
+ +0 < S 0:0(0) win 32792 <mss 1000,nop,wscale 7>
+ +0 > S. 0:0(0) ack 1 win 18980 <mss 1460,nop,wscale 0>
+ +.1 < . 1:1(0) ack 1 win 257
+
+ +0 accept(3, ..., ...) = 4
+
+// A too big packet is accepted if the receive queue is empty
+ +0 < P. 1:20001(20000) ack 1 win 257
+// Send a RST immediately so that there is no rcv_wup/rcv_mwnd_seq update yet
+ +0 < R. 20001:20001(0) ack 1 win 257
+
+ +.1 %{ assert tcpi_state == TCP_CLOSE, tcpi_state }%
+
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH RFC net-next v2 0/5] tcp: RFC 7323-compliant window retraction handling
2026-02-26 0:49 [PATCH RFC net-next v2 0/5] tcp: RFC 7323-compliant window retraction handling Simon Baatz via B4 Relay
` (4 preceding siblings ...)
2026-02-26 0:49 ` [PATCH RFC net-next v2 5/5] selftests/net: packetdrill: add tcp_rcv_neg_window.pkt Simon Baatz via B4 Relay
@ 2026-02-26 8:12 ` Matthieu Baerts
2026-02-26 10:43 ` Simon Baatz
5 siblings, 1 reply; 8+ messages in thread
From: Matthieu Baerts @ 2026-02-26 8:12 UTC (permalink / raw)
To: gmbnomis, Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima,
David S. Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
Jonathan Corbet, Shuah Khan, David Ahern, Stefano Brivio,
Jon Maloy, Jason Xing, mfreemon, Shuah Khan
Cc: Christian Ebner, netdev, linux-doc, linux-kernel, linux-kselftest
Hi Simon,
On 26/02/2026 01:49, Simon Baatz via B4 Relay wrote:
> this series implements the receiver-side requirements for TCP window
> retraction as specified in RFC 7323 and adds packetdrill tests to
> cover the new behavior.
Thank you for looking at that.
> It addresses a regression with somewhat complex causes; see my message
> "Re: [regression] [PATCH net-next 7/8] tcp: stronger sk_rcvbuf checks"
> (https://lkml.kernel.org/netdev/aXaHEk_eRJyhYfyM@gandalf.schnuecks.de/).
>
> Please see the first patch for background and implementation details.
>
> This is an RFC because a few open questions remain:
(...)
> - MPTCP seems to modify tp->rcv_wnd of subflows. And the modifications
> look odd:
>
> 1. It is updated in the RX path. Since we never advertised that
> value, we shouldn't need to update rcv_mwnd_seq.
FYI, with MPTCP the received windows are shared between subflows. This
might be surprising, but maintaining per-subflow receive windows could
end up stalling some subflows while others would not use up their
window. For more details, please check this section of the RFC:
https://datatracker.ietf.org/doc/html/rfc8684#sec_rwin
> 2. In the TX path, there is:
>
> tp->rcv_wnd = min_t(u64, win, U32_MAX);
>
> To me, that looks very wrong and that code might need to be fixed
> first.
The capping is explained because the MPTCP-level ack seq is on 64-bit,
while the TCP level receive window is on 32-bit.
I hope this helps better understanding these modifications, and
hopefully not introducing regressions on the MPTCP side :)
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH RFC net-next v2 0/5] tcp: RFC 7323-compliant window retraction handling
2026-02-26 8:12 ` [PATCH RFC net-next v2 0/5] tcp: RFC 7323-compliant window retraction handling Matthieu Baerts
@ 2026-02-26 10:43 ` Simon Baatz
0 siblings, 0 replies; 8+ messages in thread
From: Simon Baatz @ 2026-02-26 10:43 UTC (permalink / raw)
To: Matthieu Baerts
Cc: Eric Dumazet, Neal Cardwell, Kuniyuki Iwashima, David S. Miller,
Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet,
Shuah Khan, David Ahern, Stefano Brivio, Jon Maloy, Jason Xing,
mfreemon, Shuah Khan, Christian Ebner, netdev, linux-doc,
linux-kernel, linux-kselftest
Hi Matt,
On Thu, Feb 26, 2026 at 09:12:07AM +0100, Matthieu Baerts wrote:
> Hi Simon,
>
> On 26/02/2026 01:49, Simon Baatz via B4 Relay wrote:
> > this series implements the receiver-side requirements for TCP window
> > retraction as specified in RFC 7323 and adds packetdrill tests to
> > cover the new behavior.
>
> Thank you for looking at that.
Thank you for chiming in; I know that my comments are somewhat
provocative. :)
> > It addresses a regression with somewhat complex causes; see my message
> > "Re: [regression] [PATCH net-next 7/8] tcp: stronger sk_rcvbuf checks"
> > (https://lkml.kernel.org/netdev/aXaHEk_eRJyhYfyM@gandalf.schnuecks.de/).
> >
> > Please see the first patch for background and implementation details.
> >
> > This is an RFC because a few open questions remain:
>
> (...)
>
> > - MPTCP seems to modify tp->rcv_wnd of subflows. And the modifications
> > look odd:
> >
> > 1. It is updated in the RX path. Since we never advertised that
> > value, we shouldn't need to update rcv_mwnd_seq.
>
> FYI, with MPTCP the received windows are shared between subflows. This
> might be surprising, but maintaining per-subflow receive windows could
> end up stalling some subflows while others would not use up their
> window. For more details, please check this section of the RFC:
>
> https://datatracker.ietf.org/doc/html/rfc8684#sec_rwin
RFC 8646 has several pointers to RFC 5961 and in section 3.3.5 it
says:
... Each of these
segments will be mapped onto subflows, as long as subflow sequence
numbers are in the allowed windows for those subflows. Note that
So, I assume that on sub-flow level we are still supposed to do
the standard TCP sequence acceptability checks with respect to
the advertised window for the subflow.
If so, my concern is that raising rcv_wnd in the RX path means that
we may accept sequence numbers that we never advertised in that
particular subflow.
>
> > 2. In the TX path, there is:
> >
> > tp->rcv_wnd = min_t(u64, win, U32_MAX);
> >
> > To me, that looks very wrong and that code might need to be fixed
> > first.
> The capping is explained because the MPTCP-level ack seq is on 64-bit,
> while the TCP level receive window is on 32-bit.
The issues I see here are:
1. When calculating the usable receive window in TCP, we use 32-bit
signed arithmetic.
2. The max. window size with window scaling is around 1GB
3. As said, rcv_wnd is used for acceptability checks. In standard
TCP we ensure that rcv_wnd is aligned to the window scaling
factor.
So, I had assumed to see the "reverse" of the current TX raise window
logic in MPTCP: First, calculate the advertised window to put into
the outgoing packet and then update rcv_wnd accordingly.
> I hope this helps better understanding these modifications, and
> hopefully not introducing regressions on the MPTCP side :)
Yes, thank you. Regarding regressions, I couldn't agree more.
- Simon
--
Simon Baatz <gmbnomis@gmail.com>
^ permalink raw reply [flat|nested] 8+ messages in thread