diff options
| author | Jason Chu <jaschu@janestreet.com> | 2026-11-23 16:16:00 -0500 |
|---|---|---|
| committer | Stefano Brivio <sbrivio@redhat.com> | 2026-11-24 11:39:56 +0100 |
| commit | 0b9abe75043cfed0d92b14e4f34e42ade9ee4221 (patch) | |
| tree | b4b6b0a1bf0e7c016d4232e1ed7ffa4721df8f39 | |
| parent | 2b9de43e51ac789dce5872d5cfdba05376dad00c (diff) | |
| download | passt-0b9abe75043cfed0d92b14e4f34e42ade9ee4221.tar passt-0b9abe75043cfed0d92b14e4f34e42ade9ee4221.tar.gz passt-0b9abe75043cfed0d92b14e4f34e42ade9ee4221.tar.bz2 passt-0b9abe75043cfed0d92b14e4f34e42ade9ee4221.tar.lz passt-0b9abe75043cfed0d92b14e4f34e42ade9ee4221.tar.xz passt-0b9abe75043cfed0d92b14e4f34e42ade9ee4221.tar.zst passt-0b9abe75043cfed0d92b14e4f34e42ade9ee4221.zip | |
tcp: Keep window from tap below MAX_WINDOW
In tcp_internal.h, SEQ_GE(a, b) checks
(uint32_t)(a) - (uint32_t)(b) < MAX_WINDOW, so a sequence number
exactly MAX_WINDOW (16 MiB) ahead is treated as out of range.
tcp_tap_window_update() clamps the advertised window from tap to
MAX_WINDOW inclusive, and pasta sends up to that full window. If the
peer negotiates a window scale above MAX_WS (9 to 14) and advertises
at least 16 MiB, pasta can put exactly MAX_WINDOW bytes in flight.
When the peer acknowledges all of them in one ACK, tcp_data_from_tap()
fails SEQ_GE(ack_seq, conn->seq_ack_from_tap) and ignores the ACK.
pasta then rewinds on each ACK timeout and retransmits the same 16 MiB,
which the peer drops as duplicate data while repeating the same ACK,
so the connection stalls.
We hit this on Linux with a raised net.ipv4.tcp_rmem maximum (and it
also reproduces via SO_RCVBUF) when the receiver pauses while more
than 16 MiB arrives. In that case the kernel only sends a delayed ACK,
and pasta delivers all 16 MiB before the delayed ACK timer fires.
With a 6 MiB tcp_rmem maximum, the default on older kernels, the peer
uses a window scale of 7 and the window never reaches 16 MiB. Current
kernels default to up to 32 MiB, which we haven't tested.
Clamp the window in tcp_tap_window_update() to MAX_WINDOW - 1 instead.
For window scales 9 to 14, the right shift rounds the stored window
down by one scale unit, keeping every valid ACK within SEQ_GE() range.
Window scales up to MAX_WS cannot represent MAX_WINDOW anyway.
Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Jason Chu <jaschu@janestreet.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
| -rw-r--r-- | tcp.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -1494,7 +1494,10 @@ static bool tcp_tap_window_update(const struct ctx *c, struct tcp_tap_conn *conn, unsigned wnd, const struct timespec *now) { - wnd = MIN(MAX_WINDOW, wnd << conn->ws_from_tap); + /* SEQ_*() only handles sequence differences strictly less than + * MAX_WINDOW, so clamp to MAX_WINDOW - 1. + */ + wnd = MIN(MAX_WINDOW - 1, wnd << conn->ws_from_tap); /* Work-around for bug introduced in peer kernel code, commit * e2142825c120 ("net: tcp: send zero-window ACK when no memory"): don't |
