swrap: call libc_write() directly for internal fds
authorStefan Metzmacher <metze@samba.org>
Wed, 17 Feb 2021 10:00:53 +0000 (11:00 +0100)
committerAndreas Schneider <asn@samba.org>
Mon, 15 Mar 2021 07:04:58 +0000 (08:04 +0100)
commit167009f6ac1186aeeabffc29368bd5b375d9861f
tree4b6e67093b5fa6af7245583b578f6f89bf4d6627
parent2cf4c543d614e3263fa261e4584716d5b7771f09
swrap: call libc_write() directly for internal fds

Otherwise we may deadlock with a backtrace like this:

swrap_accept():
 ...
 SWRAP_LOCK_SI(si);
 swrap_pcap_dump_packet() ->
   write() ->
     swrap_write() ->
       SWRAP_LOCK_SI(si) -> abort()

This can happen if libc_open() called from swrap_pcap_get_fd()
return a stale fd. This may happen if glibc calls socket()
and closes it with __close_nocancel() instead of close().

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14640

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
src/socket_wrapper.c