Skip to content

tcp: Don't accept RST packets on listening sockets #1058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2025

Conversation

jnkr-ifx
Copy link
Contributor

@jnkr-ifx jnkr-ifx commented May 5, 2025

I ran into the following sequence of events:

  • Two TCP sockets are open to a remote host.
  • The remote host closes its end of both connections.
  • The application tries to write some data to socket 1.
    • The remote host replies with an RST.
    • Socket 1 closes.
    • The application places Socket 1 in listening mode so it can accept a new connection.
  • The application tries to write some data to socket 2.
    • The remote host replies with an RST.
    • Socket 1 accepts and discards the RST, because:
      • The packet's destination address and port matches.
      • Socket 1 is in listening mode, so it has no source address and port to compare.
      • The RST packet does not have the ACK flag set, because the remote host does not consider the data packets it recieved to be associated with an open connection.
    • Since socket 1 accepted the RST, it is not delivered to socket 2.
    • Socket 2 eventually retransmits its data packet, and the remote host replies with another RST which is again eaten by socket 1. This repeats indefinitely.

To fix this: a listening socket should not accept a RST packet that is just going to be ignored anyway. This allows the packet to be delivered to the correct socket, or discarded at the iface level if the RST packet does not match any active connection.

Copy link

codecov bot commented May 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.17%. Comparing base (242e02c) to head (e73621d).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1058      +/-   ##
==========================================
- Coverage   81.17%   81.17%   -0.01%     
==========================================
  Files          81       81              
  Lines       28956    28955       -1     
==========================================
- Hits        23505    23503       -2     
- Misses       5451     5452       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@Dirbaio Dirbaio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@Dirbaio Dirbaio added this pull request to the merge queue May 5, 2025
Merged via the queue into smoltcp-rs:main with commit e2b75e3 May 5, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants