[SCM] Socket Wrapper Repository - branch master updated

Andreas Schneider asn at samba.org
Thu Mar 19 15:59:10 UTC 2020


The branch, master has been updated
       via  c212bf0 swrap: provide _{socket,close,connect,...} symbols on FreeBSD
       via  7a9f807 swrap: detect stale fd for socket(PF_UNIX) and accept()
       via  d23452b swrap: trace the SOCKET_WRAPPER_PCAP_FILE location
      from  344801f swrap: Do not leak buf in swrap_sendmsg()

https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit c212bf0d976bcb70426a506c3e7d250644598b38
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Mar 18 08:55:23 2020 +0100

    swrap: provide _{socket,close,connect,...} symbols on FreeBSD
    
    Maybe that's not FreeBSD only, but at least this fixes the interaction
    of resolv_wrapper and socket_wrapper on FreeBSD 12.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 7a9f807302e0ddb1579b5db2c3772bb23f44b04e
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Feb 27 16:47:35 2020 +0000

    swrap: detect stale fd for socket(PF_UNIX) and accept()
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit d23452ba4ec64c5be89864a8bd31d6ee2053be46
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Mar 11 17:10:05 2020 +0100

    swrap: trace the SOCKET_WRAPPER_PCAP_FILE location
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 ConfigureChecks.cmake |  4 +--
 config.h.cmake        |  2 ++
 src/socket_wrapper.c  | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 78 insertions(+), 3 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 81aaa1c..4d5adc4 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -70,9 +70,9 @@ check_function_exists(open64 HAVE_OPEN64)
 check_function_exists(fopen64 HAVE_FOPEN64)
 check_function_exists(getprogname HAVE_GETPROGNAME)
 check_function_exists(getexecname HAVE_GETEXECNAME)
-
 check_function_exists(pledge HAVE_PLEDGE)
-
+check_function_exists(_socket HAVE__SOCKET)
+check_function_exists(_close HAVE__CLOSE)
 
 if (UNIX)
     find_library(DLFCN_LIBRARY dl)
diff --git a/config.h.cmake b/config.h.cmake
index 3c0cf01..36050b5 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -44,6 +44,8 @@
 #cmakedefine HAVE_GETPROGNAME 1
 #cmakedefine HAVE_GETEXECNAME 1
 #cmakedefine HAVE_PLEDGE 1
+#cmakedefine HAVE__SOCKET 1
+#cmakedefine HAVE__CLOSE 1
 
 #cmakedefine HAVE_ACCEPT_PSOCKLEN_T 1
 #cmakedefine HAVE_IOCTL_INT 1
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index a9e2a75..bd15793 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -1536,6 +1536,9 @@ static unsigned int socket_wrapper_default_iface(void)
 
 static void set_socket_info_index(int fd, int idx)
 {
+	SWRAP_LOG(SWRAP_LOG_TRACE,
+		  "fd=%d idx=%d\n",
+		  fd, idx);
 	socket_fds_idx[fd] = idx;
 	/* This builtin issues a full memory barrier. */
 	__sync_synchronize();
@@ -1543,6 +1546,9 @@ static void set_socket_info_index(int fd, int idx)
 
 static void reset_socket_info_index(int fd)
 {
+	SWRAP_LOG(SWRAP_LOG_TRACE,
+		  "fd=%d idx=%d\n",
+		  fd, -1);
 	set_socket_info_index(fd, -1);
 }
 
@@ -2455,6 +2461,7 @@ static const char *swrap_pcap_init_file(void)
 	if (strncmp(s, "./", 2) == 0) {
 		s += 2;
 	}
+	SWRAP_LOG(SWRAP_LOG_TRACE, "SOCKET_WRAPPER_PCAP_FILE: %s", s);
 	return s;
 }
 
@@ -3140,7 +3147,15 @@ static int swrap_socket(int family, int type, int protocol)
 	case AF_PACKET:
 #endif /* AF_PACKET */
 	case AF_UNIX:
-		return libc_socket(family, type, protocol);
+		fd = libc_socket(family, type, protocol);
+		if (fd != -1) {
+			/* Check if we have a stale fd and remove it */
+			swrap_remove_stale(fd);
+			SWRAP_LOG(SWRAP_LOG_TRACE,
+				  "Unix socket fd=%d",
+				  fd);
+		}
+		return fd;
 	default:
 		errno = EAFNOSUPPORT;
 		return -1;
@@ -3384,6 +3399,9 @@ static int swrap_accept(int s,
 
 	fd = ret;
 
+	/* Check if we have a stale fd and remove it */
+	swrap_remove_stale(fd);
+
 	SWRAP_LOCK_SI(parent_si);
 
 	ret = sockaddr_convert_from_un(parent_si,
@@ -3666,6 +3684,9 @@ static int swrap_connect(int s, const struct sockaddr *serv_addr,
 	}
 
 	if (si->family != serv_addr->sa_family) {
+		SWRAP_LOG(SWRAP_LOG_ERROR,
+			  "called for fd=%d (family=%d) called with invalid family=%d\n",
+			  s, si->family, serv_addr->sa_family);
 		errno = EINVAL;
 		ret = -1;
 		goto done;
@@ -6076,6 +6097,7 @@ static int swrap_close(int fd)
 		return libc_close(fd);
 	}
 
+	SWRAP_LOG(SWRAP_LOG_TRACE, "Close wrapper for fd=%d", fd);
 	reset_socket_info_index(fd);
 
 	si = swrap_get_socket_info(si_index);
@@ -6410,3 +6432,54 @@ void swrap_destructor(void)
 		dlclose(swrap.libc.socket_handle);
 	}
 }
+
+#if defined(HAVE__SOCKET) && defined(HAVE__CLOSE)
+/*
+ * On FreeBSD 12 (and maybe other platforms)
+ * system libraries like libresolv prefix there
+ * syscalls with '_' in order to always use
+ * the symbols from libc.
+ *
+ * In the interaction with resolv_wrapper,
+ * we need to inject socket wrapper into libresolv,
+ * which means we need to private all socket
+ * related syscalls also with the '_' prefix.
+ *
+ * This is tested in Samba's 'make test',
+ * there we noticed that providing '_read'
+ * and '_open' would cause errors, which
+ * means we skip '_read', '_write' and
+ * all non socket related calls without
+ * further analyzing the problem.
+ */
+#define SWRAP_SYMBOL_ALIAS(__sym, __aliassym) \
+	extern typeof(__sym) __aliassym __attribute__ ((alias(#__sym)))
+
+#ifdef HAVE_ACCEPT4
+SWRAP_SYMBOL_ALIAS(accept4, _accept4);
+#endif
+SWRAP_SYMBOL_ALIAS(accept, _accept);
+SWRAP_SYMBOL_ALIAS(bind, _bind);
+SWRAP_SYMBOL_ALIAS(close, _close);
+SWRAP_SYMBOL_ALIAS(connect, _connect);
+SWRAP_SYMBOL_ALIAS(dup, _dup);
+SWRAP_SYMBOL_ALIAS(dup2, _dup2);
+SWRAP_SYMBOL_ALIAS(fcntl, _fcntl);
+SWRAP_SYMBOL_ALIAS(getpeername, _getpeername);
+SWRAP_SYMBOL_ALIAS(getsockname, _getsockname);
+SWRAP_SYMBOL_ALIAS(getsockopt, _getsockopt);
+SWRAP_SYMBOL_ALIAS(ioctl, _ioctl);
+SWRAP_SYMBOL_ALIAS(listen, _listen);
+SWRAP_SYMBOL_ALIAS(readv, _readv);
+SWRAP_SYMBOL_ALIAS(recv, _recv);
+SWRAP_SYMBOL_ALIAS(recvfrom, _recvfrom);
+SWRAP_SYMBOL_ALIAS(recvmsg, _recvmsg);
+SWRAP_SYMBOL_ALIAS(send, _send);
+SWRAP_SYMBOL_ALIAS(sendmsg, _sendmsg);
+SWRAP_SYMBOL_ALIAS(sendto, _sendto);
+SWRAP_SYMBOL_ALIAS(setsockopt, _setsockopt);
+SWRAP_SYMBOL_ALIAS(socket, _socket);
+SWRAP_SYMBOL_ALIAS(socketpair, _socketpair);
+SWRAP_SYMBOL_ALIAS(writev, _writev);
+
+#endif /* SOCKET_WRAPPER_EXPORT_UNDERSCORE_SYMBOLS */


-- 
Socket Wrapper Repository



More information about the samba-cvs mailing list