smoltcp-rs / smoltcp

a smol tcp/ip stack
BSD Zero Clause License
3.75k stars 421 forks source link

Listening TCP socket may accept RST destined for other socket #851

Open george-hopkins opened 11 months ago

george-hopkins commented 11 months ago

To start with, I'm not sure this is indeed a bug: Given two TCP sockets in listening state, each receives a SYN. Afterwards, the remote client sends a RST to each socket. After processing the first RST, one socket falls back to LISTEN. The second RST might be accepted by that socket as well, even if it is actually destined to the second socket. The second socket will be stuck in SynReceived and will be trying to send SYN+ACKs.

I was able to fix this behaviour by ignoring such packets in smoltcp::socket::tcp::Socket::accepts but this might not be the most elegant way.