HomeFreeBSD

tcp: address a wire level race with 2 ACKs at the end of TCP handshake

Description

tcp: address a wire level race with 2 ACKs at the end of TCP handshake

Imagine we are in SYN-RCVD state and two ACKs arrive at the same time,
both valid, e.g. coming from the same host and with valid sequence.

First packet would locate the listening socket in the inpcb database,
write-lock it and start expanding the syncache entry into a socket.
Meanwhile second packet would wait on the write lock of the listening
socket. First packet will create a new ESTABLISHED socket, free the
syncache entry and unlock the listening socket. Second packet would
call into syncache_expand(), but this time it will fail as there
is no syncache entry. Second packet would generate RST, effectively
resetting the remote connection.

It seems to me, that it is impossible to solve this problem with
just rearranging locks, as the race happens at a wire level.

To solve the problem, for an ACK packet arrived on a listening socket,
that failed syncache lookup, perform a second non-wildcard lookup right
away. That lookup may find the new born socket. Otherwise, we indeed
send RST.

Tested by: kp
Reviewed by: tuexen, rrs
PR: 265154
Differential revision: https://reviews.freebsd.org/D36066

Details

Provenance
glebiusAuthored on Aug 10 2022, 2:32 PM
Reviewer
tuexen
Differential Revision
D36066: tcp: address a wire level race with 2 ACKs at the end of TCP handshake
Parents
rGf998535a66b9: netinet6: allow ND entries creation for all directly-reachable
Branches
Unknown
Tags
Unknown