summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* Bump version to 1.3.3HEADsocket_wrapper-1.3.3masterAndreas Schneider2021-03-172-3/+9
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* cmake: Define a library version for the noop libAndreas Schneider2021-03-152-2/+8
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* cmake: Export cmake config for socket_wrapper_noopAndreas Schneider2021-03-151-0/+4
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* cmake: Set public include dir for socket_wrapper_noop targetAndreas Schneider2021-03-151-1/+4
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* cmake: Set PRIVATE for linking librariesAndreas Schneider2021-03-151-2/+4
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: wrap __close_nocancel() if availableStefan Metzmacher2021-03-154-1/+54
| | | | | | | | | | | While it's no possible to inject swrap__close_nocancel() into libc.so.6 directly, because it's no weak symbol, it seems to be possible to inject it to other glibc libraries like libpthread.so.0, which is better than nothing. 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>
* swrap: export a public socket_wrapper_indicate_no_inet_fd() helper functionStefan Metzmacher2021-03-156-0/+178
| | | | | | 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>
* swrap: introduce a socket_wrapper_noop.so and socket_wrapper.h to provide ↵Stefan Metzmacher2021-03-1510-18/+310
| | | | | | | | | | | | noop stubs Applications with the need to call socket_wrapper_enabled() should link against -lsocket_wrapper_noop in order to resolve the symbol at link time. 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>
* swrap: split out swrap_remove_wrapper() to handle swrap_close() and ↵Stefan Metzmacher2021-03-151-45/+24
| | | | | | | | | | | swrap_remove_stale() Except of closing the fd, both should do the same, even indicating a TCP close in the pcap file. 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>
* swrap: remember the libc_close() errno in swrap_close()Stefan Metzmacher2021-03-151-0/+5
| | | | | | 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>
* swrap: call libc_write() directly for internal fdsStefan Metzmacher2021-03-151-3/+3
| | | | | | | | | | | | | | | | | | | | 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>
* swrap: warn about unreachable addressesStefan Metzmacher2021-03-151-0/+14
| | | | | | 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>
* Bump version to 1.3.2socket_wrapper-1.3.2Andreas Schneider2021-02-102-2/+5
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: don't read the callers msg_control buffer in swrap_recvmsg_before_unix()Stefan Metzmacher2021-02-101-1/+0
| | | | | | | | | For recvmsg() msg_control is a write only buffer, that is filled by the kernel, but the kernel won't read from that buffer. So we shouldn't read from (copy) it either. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: don't touch msg_tmp in swrap_recvmsg_after_unix() on errorStefan Metzmacher2021-02-091-0/+10
| | | | Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: fix possible memory leak between swrap_recvmsg_{before,after}_unix()Stefan Metzmacher2021-02-091-6/+20
| | | | Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* Bump version to 1.3.1socket_wrapper-1.3.1Andreas Schneider2021-02-092-2/+8
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* test_echo_tcp_sendmsg_recvmsg_fd: add test_tcp_sendmsg_recvmsg_fd_mixed() testsStefan Metzmacher2021-02-081-0/+165
| | | | | | Here we mix sockets and other valid file descriptors. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* test_echo_tcp_sendmsg_recvmsg_fd: add ↵Stefan Metzmacher2021-02-081-0/+82
| | | | | | test_tcp_sendmsg_recvmsg_fd_different() tests Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* test_echo_tcp_sendmsg_recvmsg_fd: also test passing the same socket up to 6 ↵Stefan Metzmacher2021-02-081-1/+46
| | | | | | | | | | | times Note SWRAP_MAX_PASSED_FDS is currently 6. This test demonstrates that even 64-bit systems required commit: "swrap: fix fd-passing without 4 padding bytes" Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* test_echo_tcp_sendmsg_recvmsg_fd: split out test_tcp_sendmsg_recvmsg_fd_same()Stefan Metzmacher2021-02-081-4/+16
| | | | Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* test_echo_tcp_sendmsg_recvmsg_fd: split out test_tcp_sendmsg_recvmsg_fd_array()Stefan Metzmacher2021-02-081-53/+145
| | | | | | | This will allow us to test more combinations in order to get better coverage. For now we just test a single fd. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* tests/echo_srv: allow more than once tcp connection at a timeStefan Metzmacher2021-02-081-1/+1
| | | | | | | We should not wait for the last connection to disconnect, there would not be any reason to use fork at all. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: fix fd-passing without 4 padding bytesStefan Metzmacher2021-02-081-6/+63
| | | | | | | | | We noticed the problem on 32 bit platforms and sending a single application fd, the hidden pipe-fd doesn't fit into the padding bytes. This can also happen on 64 bit platforms and an even number of application fds. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: fix invalid read in swrap_sendmsg_unix_scm_rights()Stefan Metzmacher2021-02-081-1/+1
| | | | | | | | | Here the fds_out array is larger than the fds_in array, so we can only copy the fds_in array using size_fds_in, leaving the last slot of fds_out untouched, which is filled by fds_out[num_fds_in] = pipefd[0] later. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: fix copy on write leak of ~38M for every fork.Stefan Metzmacher2021-02-051-28/+31
| | | | | | | | | | | | | | | | | commit 0f8e90dd7e59c473be615dee08d445dca98fdab9 (src/socket_wrapper.c: fix mutex fork handling) let us touch the whole sockets array on every fork, because each element in the array has it's own mutex. max_sockets=65535 * sizeof(struct socket_info_container)=592 = 38796720 This was designed for the use of robust shared mutexes when moving the sockets array into a shared memory file. Until we really move to shared memory, we can use a single global mutex in order to avoid the copy on write leaking. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: abort on mutex errorsStefan Metzmacher2021-02-051-0/+2
| | | | | | There's no way to continue in a reliable way... Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: fallback to libc_getpeername() when we get an empty sun_path from ↵Stefan Metzmacher2021-02-051-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | accept() This hopefully hides the strange behaviour of FreeBSD (at least 12.1) for already disconnected AF_UNIX sockets. The race is triggered when the following detects the usage of 'getpeername': truss -o ./truss.out -f -H -a -e -D -s 160 ctest -V -R test_thread_echo_tcp_connect; grep getpeername truss.out In a simplified log the following is happening: ECHO_SRV(parent): socket(PF_LOCAL,SOCK_STREAM,0) = 4 (0x4) ECHO_SRV(parent): unlink("/tmp/w_E37bkf/T0A0007") ERR#2 'No such file or directory' ECHO_SRV(parent): bind(4,{ AF_UNIX "/tmp/w_E37bkf/T0A0007" },106) = 0 (0x0) ECHO_SRV(parent): listen(4,16) = 0 (0x0) ... ECHO_SRV(parent): write(2,"SWRAP_ERROR[echo_srv (9792)] - swrap_accept: before accept(sa_socklen=106)\n",75) = 75 (0x4b) ECHO_SRV(parent): accept4(0x4,0x7ffffffde158,0x7ffffffde150,0x0) = 5 (0x5) ECHO_SRV(parent): write(2,"SWRAP_ERROR[echo_srv (9792)] - swrap_accept: after accept(sa_socklen=106, family=1)\n",84) = 84 (0x54) ECHO_SRV(parent): getsockname(5,{ AF_UNIX "/tmp/w_E37bkf/T0A0007" },0x7ffffffde0c0) = 0 (0x0) ECHO_SRV(parent): swrap_accept() returned a valid connection and a per connection child (pid=9793) handles it TEST_THREAD: socket(PF_LOCAL,SOCK_STREAM,0) = 7 (0x7) TEST_THREAD: bind(7,{ AF_UNIX "/tmp/w_E37bkf/T014D4F" },106) = 0 (0x0) TEST_THREAD: connect(7,{ AF_UNIX "/tmp/w_E37bkf/T0A0007" },106) = 0 (0x0) TEST_THREAD: close(7) = 0 (0x0) ECHO_SRV(parent): wait4(-1,0x0,0x0,0x0) = 9793 (0x2641) ECHO_SRV(parent): close(5) = 0 (0x0) ECHO_SRV(parent): write(2,"SWRAP_ERROR[echo_srv (9792)] - swrap_accept: before accept(sa_socklen=106)\n",75) = 75 (0x4b) ECHO_SRV(parent): accept4(0x4,0x7ffffffde158,0x7ffffffde150,0x0) = 5 (0x5) TEST_THREAD: unlink("/tmp/w_E37bkf/T014D4F") = 0 (0x0) ECHO_SRV(parent): write(2,"SWRAP_ERROR[echo_srv (9792)] - swrap_accept: after accept(sa_socklen=16, family=1)\n",83) = 83 (0x53) ECHO_SRV(parent): getpeername(5,0x7ffffffde158,0x7ffffffde150) ERR#57 'Socket is not connected' ECHO_SRV(parent): getsockname(5,{ AF_UNIX "/tmp/w_E37bkf/T0A0007" },0x7ffffffde0c0) = 0 (0x0) ECHO_SRV(parent): getpeername(5,0x7ffffffde158,0x7ffffffde150) ERR#57 'Socket is not connected' Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: make swrap_accept() more resilient against races related to already ↵Stefan Metzmacher2021-02-051-9/+24
| | | | | | | | | | | | | | | disconnected sockets Callers of accept() expect to get ECONNABORTED instead of a disconnected socket. Even on Linux we have a potential race calling libc_getsockname() after accept(), so we map ENOTCONN to ECONNABORTED. We should do all syscalls in order to have peer and sockname, before doing in memory things like calling sockaddr_convert_from_un(). Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: add better logging to convert_un_in()Stefan Metzmacher2021-02-051-5/+20
| | | | Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* tests/echo_srv: make the main server logic resilient to ECONNABORTED from ↵Stefan Metzmacher2021-02-051-0/+3
| | | | | | | | | | | | | accept() That should fix a race where the connect() directly followed by close() in test_thread_echo_tcp_connect will cause the echo_srv to terminate early, which results in connect() returning ECONNREFUSED in for other threads. This mainly happens on FreeBSD, but it can also happen on Linux. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* Bump version to 1.3.0socket_wrapper-1.3.0Andreas Schneider2021-02-022-3/+8
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* doc: Add website to manpageAndreas Schneider2021-02-022-119/+152
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* doc: Define doctype for manpageAndreas Schneider2021-02-022-1/+6
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* doc: Rename socket_wrapper.1.txt to socket_wrapper.1.adocAndreas Schneider2021-02-022-1/+1
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: add basic support for fd-passing via SCM_RIGHTSStefan Metzmacher2021-02-024-11/+772
| | | | | | | | | | | | | | | | | | | | | | We only allow passing up to 6 fds in a single sendmsg call, in order to keep the logic simple. That's more than enough for Samba's use of fd-passing, there we only pass a single fd and the fd will be closed in the sender on success. It means it's ok to keep the socket_info.io.pck_{snd,rcv} fields per process and the PCAP generation will still work as expected. If these constraints turn out to be a problem for other applications, we need to change to a more complex design and move the socket_info array into a shared memory file and use shared robust mutexes. But for now we just want to support multi-channel testing in Samba. BUG: https://bugzilla.samba.org/show_bug.cgi?id=11899 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Anoop C S <anoopcs@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* tests: Add test for socket_wrapper fd-passing supportAnoop C S2021-02-022-1/+193
| | | | | Signed-off-by: Anoop C S <anoopcs@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: always check new fd's against socket_fds_max and use libc_close() for ↵Stefan Metzmacher2021-02-021-7/+46
| | | | | | | cleanup Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Anoop C S <anoopcs@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: add const to swrap_add_socket_info()Stefan Metzmacher2021-02-021-1/+1
| | | | | Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Anoop C S <anoopcs@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: let swrap_sendmsg_before_unix() create a copy of msg_tmp.msg_controlStefan Metzmacher2021-02-021-0/+43
| | | | | | | With fd-passing we'll have to modify the content of it. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Anoop C S <anoopcs@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: add stubs for swrap_{sendmsg,recvmsg}_{before,after}_unix()Stefan Metzmacher2021-02-021-2/+40
| | | | | | | | In order to implement fd-passing of socket_wrapper simulated sockets we need to modify the msghdr structures from the callers. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Anoop C S <anoopcs@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: filter out SCM_{RIGHTS,CREDENTIALS} on inet socketStefan Metzmacher2021-02-021-9/+47
| | | | | | | | These are only valid on unix domain sockets and ignored otherwise (at least on Linux). Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Anoop C S <anoopcs@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: add error checking/cleanup to swrap_sendmsg_filter_cmsghdr()Stefan Metzmacher2021-02-021-0/+7
| | | | | Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Anoop C S <anoopcs@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Fix MSGHDR check in sendmsg()Anoop C S2021-02-021-38/+48
| | | | | | | | | Check for msg_controllen and msg_control data members from msghdr structure needs to be validated on the received omsg pointer rather than on newly created msghdr struture inside the wrapper. Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Anoop C S <anoopcs@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: print out SOCKET_WRAPPER_PACKAGE and SOCKET_WRAPPER_VERSION on first useStefan Metzmacher2021-02-023-4/+8
| | | | | Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Anoop C S <anoopcs@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* src/socket_wrapper.c: Improve checks and debug output of socket_wrapper_dir()Andreas Schneider2021-01-291-2/+3
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* src/socket_wrapper.c: fix mutex fork handlingStefan Metzmacher2021-01-292-75/+92
| | | | | | | | | | | | | | We need to use pthread_mutex_init in the child handler... See https://sourceware.org/bugzilla/show_bug.cgi?id=2745 Valgrind tools like helgrind and drd don't understand this (at least in 3.15.0), they require a pthread_mutex_unlock() in the child in order work. Pair-Programmed-With: Andreas Schneider <asn@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org> Signed-off-by: Andreas Schneider <asn@samba.org>
* gitlab-ci: Add job for ThreadSanitizerAndreas Schneider2021-01-292-0/+30
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* cmake: Add ThreadSanitizer compile flagsAndreas Schneider2021-01-281-0/+12
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* src/socket_wrapper.c: always go through swrap_bind_symbol_all() protected by ↵Stefan Metzmacher2021-01-281-52/+55
| | | | | | pthread_once() Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>