Skip to content

Fix TCP low-watermark receive-window underflow and header corruption - #435

Open
Sawii00 wants to merge 1 commit into
eclipse-threadx:devfrom
Sawii00:fix/tcp-low-watermark-rx-window
Open

Sawii00 wants to merge 1 commit into
eclipse-threadx:devfrom
Sawii00:fix/tcp-low-watermark-rx-window

Conversation

@Sawii00

@Sawii00 Sawii00 commented Sep 15, 2026

Copy link
Copy Markdown

Summary

Fixes #433.

When a segment fills a receive-queue hole under low-watermark pressure, the drop path can set the receive window using the advanced receive sequence and then subtract that advance again. The resulting wrap can corrupt the TCP flags, including setting RST. Reassembly can also acknowledge the tail before dropping it when pool pressure or a superset retransmission leaves a shorter queue.

This PR applies the four-file patch from the issue to dev:

  • Stop reassembly before the tail that will be released.
  • Skip the relative window decrement after the drop path has set the window absolutely.
  • Advertise zero for a wrapped internal window and saturate oversized advertised windows in the control-send, new-data-send, and retransmission header builders, with or without window scaling.

Regression coverage

Add netx_tcp_low_watermark_rx_window_test to the existing CMake regression suite. It uses real NetX sockets, packet allocation/release, TCP reassembly, send, and retransmission code. A sink IP driver inspects outgoing TCP headers; received segments are injected at the reassembly boundary to make the sequences deterministic.

Coverage includes:

  • Queue-limit hole fill, plus a superset retransmission that shrinks a full queue.
  • Pool-low-watermark drop with a short queue.
  • Pool-low-watermark superset retransmission where the incoming packet becomes the tail.
  • Receive sequence/window, ACK number, delivered payload bytes, queue cleanup, and packet-pool accounting.
  • Ordinary, wrapped, and oversized windows through all three header builders, checking the exact data offset and flags. The scaling-enabled test uses a nonzero receive scale of 2.

Enable NX_ENABLE_LOW_WATERMARK in the existing v4_build and v4_full_build profiles. This runs the regression, along with existing low-watermark tests, without and with NX_ENABLE_TCP_WINDOW_SCALING respectively.

Validation

Locally tested in Ubuntu 24.04, Linux x86 32-bit, GCC 14, with the repository-pinned ThreadX and FileX submodules:

  • 46 selected TCP/low-watermark CTests pass in each profile, including overlap, wrapping sequences, retransmission, dropped packets, data transfer, and window handling.
  • The new regression executes all scenarios successfully in both profiles; it is not N/A in either.
  • The new test also passes strict C99 warning checks, including -Werror -Wall -Wextra -pedantic -Wconversion -Wmissing-declarations.
  • Five local mutation checks fail as expected: restoring each of the four original source files individually, and removing only the new tail stop. Restoring the complete patch passes again.
  • Profile-wrapper validation and git diff --check pass.

The selected CTests were run with:

ctest --test-dir test/cmake/netxduo/build/<profile> \
  -R 'netx_(low_watermark|tcp_.*(window|overlapping|wrapping_sequence|retransmi|dropped_packet|data_transfer))' \
  -E ipv6 -j 8 --timeout 180 --output-on-failure

The full repository test matrix has not been run locally.

AI disclosure

The fix and regression coverage were developed with OpenAI Codex assistance. Edited files include AI disclosures, and the commit includes an Assisted-by: OpenAI Codex trailer. The Eclipse Contributor Agreement has been signed.

Stop reassembly before the tail that will be dropped and avoid subtracting
an RX sequence advance after the drop path sets the window absolutely.
Constrain advertised windows in all three TCP header builders so an
invalid internal window cannot overwrite the data offset or flags.

Add an in-tree regression using real sockets, packet pools and TCP code.
Cover queue-limit hole fills, short queues under pool pressure, superset
retransmissions, delivered bytes and all three header construction paths.
Enable low-watermark tests in v4_build and v4_full_build to exercise both
window-scaling configurations.

Fixes eclipse-threadx#433

Assisted-by: OpenAI Codex
@Sawii00
Sawii00 marked this pull request as ready for review September 15, 2026 07:47

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant