freebsd-dev/sys/netinet
Robert Watson 81158452be Push acquisition of the accept mutex out of sofree() into the caller
(sorele()/sotryfree()):

- This permits the caller to acquire the accept mutex before the socket
  mutex, avoiding sofree() having to drop the socket mutex and re-order,
  which could lead to races permitting more than one thread to enter
  sofree() after a socket is ready to be free'd.

- This also covers clearing of the so_pcb weak socket reference from
  the protocol to the socket, preventing races in clearing and
  evaluation of the reference such that sofree() might be called more
  than once on the same socket.

This appears to close a race I was able to easily trigger by repeatedly
opening and resetting TCP connections to a host, in which the
tcp_close() code called as a result of the RST raced with the close()
of the accepted socket in the user process resulting in simultaneous
attempts to de-allocate the same socket.  The new locking increases
the overhead for operations that may potentially free the socket, so we
will want to revise the synchronization strategy here as we normalize
the reference counting model for sockets.  The use of the accept mutex
in freeing of sockets that are not listen sockets is primarily
motivated by the potential need to remove the socket from the
incomplete connection queue on its parent (listen) socket, so cleaning
up the reference model here may allow us to substantially weaken the
synchronization requirements.

RELENG_5_3 candidate.

MFC after:	3 days
Reviewed by:	dwhite
Discussed with:	gnn, dwhite, green
Reported by:	Marc UBM Bocklet <ubm at u-boot-man dot de>
Reported by:	Vlad <marchenko at gmail dot com>
2004-10-18 22:19:43 +00:00
..
libalias Fix outgoing ICMP on global instance. 2004-08-14 14:21:09 +00:00
accf_data.c
accf_http.c
icmp6.h
icmp_var.h White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
if_atm.c White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
if_atm.h White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
if_ether.c Modify the thrilling "%D is using my IP address %s!" message so that 2004-10-12 17:10:40 +00:00
if_ether.h
igmp_var.h
igmp.c
igmp.h White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
in_cksum.c
in_gif.c
in_gif.h
in_pcb.c Push acquisition of the accept mutex out of sofree() into the caller 2004-10-18 22:19:43 +00:00
in_pcb.h White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
in_proto.c White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
in_rmx.c
in_systm.h
in_var.h White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
in.c White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
in.h White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
ip6.h
ip_divert.c Add support to IPFW for classification based on "diverted" status 2004-10-03 00:26:35 +00:00
ip_divert.h
ip_dummynet.c Allocate memory when dumping pipes with M_WAITOK flag. 2004-08-25 09:31:30 +00:00
ip_dummynet.h Convert ipfw to use PFIL_HOOKS. This is change is transparent to userland 2004-08-17 22:05:54 +00:00
ip_ecn.c
ip_ecn.h
ip_encap.c
ip_encap.h
ip_fastfwd.c Add an additional struct inpcb * argument to pfil(9) in order to enable 2004-09-29 04:54:33 +00:00
ip_fw2.c Add support to IPFW for matching by TCP data length. 2004-10-03 00:47:15 +00:00
ip_fw_pfil.c Add an additional struct inpcb * argument to pfil(9) in order to enable 2004-09-29 04:54:33 +00:00
ip_fw.h Add support to IPFW for matching by TCP data length. 2004-10-03 00:47:15 +00:00
ip_gre.c White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
ip_gre.h
ip_icmp.c Remove the last two global variables that are used to store packet state while 2004-09-15 20:13:26 +00:00
ip_icmp.h
ip_id.c White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
ip_input.c Add an additional struct inpcb * argument to pfil(9) in order to enable 2004-09-29 04:54:33 +00:00
ip_mroute.c When running with debug.mpsafenet=0, initialize IP multicast routing 2004-10-07 14:13:35 +00:00
ip_mroute.h White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
ip_output.c Add an additional struct inpcb * argument to pfil(9) in order to enable 2004-09-29 04:54:33 +00:00
ip_var.h Remove the last two global variables that are used to store packet state while 2004-09-15 20:13:26 +00:00
ip.h
ipprotosw.h
pim_var.h
pim.h
raw_ip.c When the access control on creating raw sockets was modified so that 2004-10-12 16:47:25 +00:00
tcp_debug.c
tcp_debug.h White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
tcp_fsm.h
tcp_hostcache.c White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
tcp_input.c - Estimate the amount of data in flight in sack recovery and use it 2004-10-05 18:36:24 +00:00
tcp_output.c Acquire the send socket buffer lock around tcp_output() activities 2004-10-09 16:48:51 +00:00
tcp_reass.c - Estimate the amount of data in flight in sack recovery and use it 2004-10-05 18:36:24 +00:00
tcp_sack.c - Estimate the amount of data in flight in sack recovery and use it 2004-10-05 18:36:24 +00:00
tcp_seq.h
tcp_subr.c Push acquisition of the accept mutex out of sofree() into the caller 2004-10-18 22:19:43 +00:00
tcp_syncache.c Remove the last two global variables that are used to store packet state while 2004-09-15 20:13:26 +00:00
tcp_timer.c White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
tcp_timer.h White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
tcp_timewait.c Push acquisition of the accept mutex out of sofree() into the caller 2004-10-18 22:19:43 +00:00
tcp_usrreq.c White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
tcp_var.h - Estimate the amount of data in flight in sack recovery and use it 2004-10-05 18:36:24 +00:00
tcp.h White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
tcpip.h White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
udp_usrreq.c Don't release the udbinfo lock until after the last use of UDP inpcb 2004-10-12 20:03:56 +00:00
udp_var.h White space cleanup for netinet before branch: 2004-08-16 18:32:07 +00:00
udp.h