Page MenuHomeFreeBSD

tcp: Disallow re-connection of a connected socket
ClosedPublic

Authored by markj on Feb 11 2023, 4:28 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jan 31, 3:21 AM
Unknown Object (File)
Dec 12 2025, 1:58 AM
Unknown Object (File)
Dec 1 2025, 4:48 PM
Unknown Object (File)
Nov 29 2025, 12:31 PM
Unknown Object (File)
Nov 27 2025, 12:29 PM
Unknown Object (File)
Nov 24 2025, 3:34 AM
Unknown Object (File)
Nov 20 2025, 3:09 AM
Unknown Object (File)
Nov 17 2025, 7:37 AM
Subscribers

Details

Summary

soconnectat() tries to ensure that one cannot connect a connected
socket. However, the check is racy and does not really prevent two
threads from attempting to connect the same TCP socket.

Modify tcp_connect() and tcp6_connect() to perform the check again, this
time synchronized by the inpcb lock, under which we call
soisconnecting().

Reported by: syzkaller

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 49689
Build 46579: arc lint + arc unit

Event Timeline

markj requested review of this revision.Feb 11 2023, 4:28 PM
  • Undo the modification to tcp6_usr_connect().

May I ask two additions to the existing patch?

  1. Your discovery of the racyness of soconnectat() is very important and it deserves a comment in the function code with reference to the fact that TCP solves the problem for itself.
  2. I'd suggest to brace the new check info __predict_false().
  • Add a comment to soconnectat().
  • Add __predict_false annotations.

May I ask two additions to the existing patch?

  1. Your discovery of the racyness of soconnectat() is very important and it deserves a comment in the function code with reference to the fact that TCP solves the problem for itself.
  2. I'd suggest to brace the new check info __predict_false().

BTW, this is already checked implicitly by UDP when it checks inp->inp_faddr.

This revision was not accepted when it landed; it landed in state Needs Review.Feb 14 2023, 3:14 PM
This revision was automatically updated to reflect the committed changes.