opnsense-src/sys/netgraph/bluetooth
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
..
common net: clean up empty lines in .c and .h files 2020-09-01 21:19:14 +00:00
drivers ng_ubt: Block attachment of uninitialized Intel Wireless 7265 2021-04-15 17:26:32 +03:00
hci Fix a use-after-free in an error case. 2021-05-26 18:23:33 +09:00
include pccard: Remove bt3c(4) driver 2021-01-07 20:40:41 -07:00
l2cap net: clean up empty lines in .c and .h files 2020-09-01 21:19:14 +00:00
socket socket: Properly interlock when transitioning to a listening socket 2021-09-07 17:11:43 -04:00