]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
socket: Avoid clearing SS_ISCONNECTING if soconnect() fails
authorMark Johnston <markj@FreeBSD.org>
Tue, 7 Sep 2021 18:51:54 +0000 (14:51 -0400)
committerMark Johnston <markj@FreeBSD.org>
Tue, 7 Sep 2021 21:12:09 +0000 (17:12 -0400)
commita8aa6f1f784b91acb4ef9387a28c78311493eb66
tree747fbd0653871bbf83443d470d3a32c0f5926989
parentc4b44adcf0b631eb2d4187f285ed37cf4ce1caff
socket: Avoid clearing SS_ISCONNECTING if soconnect() fails

This behaviour appears to date from the 4.4 BSD import.  It has two
problems:

1. The update to so_state is not protected by the socket lock, so
   concurrent updates to so_state may be lost.
2. Suppose two threads race to call connect(2) on a socket, and one
   succeeds while the other fails.  Then the failing thread may
   incorrectly clear SS_ISCONNECTING, confusing the state machine.

Simply remove the update.  It does not appear to be necessary:
pru_connect implementations which call soisconnecting() only do so after
all failure modes have been handled.  For instance, tcp_connect() and
tcp6_connect() will never return an error after calling soisconnected().
However, we cannot correctly assert that SS_ISCONNECTED is not set after
an error from soconnect() since the socket lock is not held across the
pru_connect call, so a concurrent connect(2) may have set the flag.

MFC after: 1 month
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D31699
sys/kern/uipc_syscalls.c