Mark Johnston bd4a39cc93 socket: Properly interlock when transitioning to a listening socket
Currently, most protocols implement pru_listen with something like the
following:

	SOCK_LOCK(so);
	error = solisten_proto_check(so);
	if (error) {
		SOCK_UNLOCK(so);
		return (error);
	}
	solisten_proto(so);
	SOCK_UNLOCK(so);

solisten_proto_check() fails if the socket is connected or connecting.
However, the socket lock is not used during I/O, so this pattern is
racy.

The change modifies solisten_proto_check() to additionally acquire
socket buffer locks, and the calling thread holds them until
solisten_proto() or solisten_proto_abort() is called.  Now that the
socket buffer locks are preserved across a listen(2), this change allows
socket I/O paths to properly interlock with listen(2).

This fixes a large number of syzbot reports, only one is listed below
and the rest will be dup'ed to it.

Reported by:	syzbot+9fece8a63c0e27273821@syzkaller.appspotmail.com
Reviewed by:	tuexen, gallatin
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31659
2021-09-07 17:11:43 -04:00
..
2021-08-05 23:22:02 +08:00
2021-06-07 16:45:50 -04:00
2020-11-19 02:50:48 +00:00
2021-08-10 21:27:54 -04:00
2021-08-18 08:48:27 +02:00
2020-12-04 18:56:44 +00:00
2021-04-18 11:19:15 -06:00
2021-04-12 11:42:21 -03:00
2021-09-05 12:50:15 -07:00
2021-08-10 21:27:54 -04:00
2020-11-05 15:08:56 +00:00
2021-08-08 21:54:49 -04:00
2020-11-09 00:34:23 +00:00
2021-09-03 23:13:42 -04:00
2020-08-13 20:48:14 +00:00
2021-04-02 15:41:51 +03:00
2021-07-28 22:00:29 -04:00
2021-08-18 08:51:26 +02:00
2020-01-12 23:52:16 +00:00
2021-08-05 23:22:02 +08:00
2021-08-05 23:22:02 +08:00
2021-04-18 11:14:17 -06:00
2020-08-27 05:11:15 +00:00
2021-09-03 22:18:51 -04:00
2021-07-24 12:52:32 -07:00