]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
third_party: Update socket_wrapper to version 1.4.3
authorAndreas Schneider <asn@samba.org>
Thu, 13 Jun 2024 05:47:26 +0000 (07:47 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 9 Jul 2024 14:24:35 +0000 (14:24 +0000)
This fixes issues with bind compiled with jemalloc.

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

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Thu Jun 13 08:41:39 UTC 2024 on atb-devel-224

(cherry picked from commit 8ae180e1678fc8565b8074d4886f7d3676a0f950)

Autobuild-User(v4-19-test): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(v4-19-test): Tue Jul  9 14:24:35 UTC 2024 on atb-devel-224

buildtools/wafsamba/samba_third_party.py
third_party/socket_wrapper/socket_wrapper.c
third_party/socket_wrapper/wscript

index 8fa1756b03be037cdaa3a34902cd971667c231fd..a42bb2ddc901df74771aa12b37a863871ed7fd69 100644 (file)
@@ -24,7 +24,7 @@ Build.BuildContext.CHECK_CMOCKA = CHECK_CMOCKA
 
 @conf
 def CHECK_SOCKET_WRAPPER(conf):
-    return conf.CHECK_BUNDLED_SYSTEM_PKG('socket_wrapper', minversion='1.4.2')
+    return conf.CHECK_BUNDLED_SYSTEM_PKG('socket_wrapper', minversion='1.4.3')
 Build.BuildContext.CHECK_SOCKET_WRAPPER = CHECK_SOCKET_WRAPPER
 
 @conf
index c759d350fb1816bd1c7de26adac7fd034d01476e..37799c82419f60db19c65866490ba3752f40682a 100644 (file)
@@ -1388,6 +1388,9 @@ static ssize_t libc_writev(int fd, const struct iovec *iov, int iovcnt)
        return swrap.libc.symbols._libc_writev.f(fd, iov, iovcnt);
 }
 
+/* JEMALLOC: This tells socket_wrapper if it should handle syscall() */
+static bool swrap_handle_syscall;
+
 #ifdef HAVE_SYSCALL
 DO_NOT_SANITIZE_ADDRESS_ATTRIBUTE
 static long int libc_vsyscall(long int sysno, va_list va)
@@ -1396,7 +1399,27 @@ static long int libc_vsyscall(long int sysno, va_list va)
        long int rc;
        int i;
 
-       swrap_bind_symbol_all();
+       /*
+        * JEMALLOC:
+        *
+        * This is a workaround to prevent a deadlock in jemalloc calling
+        * malloc_init() twice. The first allocation call will trigger a
+        * malloc_init() of jemalloc. The functions calls syscall(SYS_open, ...)
+        * so it goes to socket or uid wrapper. In this code path we need to
+        * avoid any allocation calls. This will prevent the deadlock.
+        *
+        * We also need to avoid dlopen() as that would trigger the recursion
+        * into malloc_init(), so we use dlsym(RTLD_NEXT), until we reached
+        * swrap_constructor() or any real socket call at that time
+        * swrap_bind_symbol_all() will replace the function pointer again after
+        * dlopen of libc.
+        */
+       if (swrap_handle_syscall) {
+               swrap_bind_symbol_all();
+       } else if (swrap.libc.symbols._libc_syscall.obj == NULL) {
+               swrap.libc.symbols._libc_syscall.obj = dlsym(RTLD_NEXT,
+                                                            "syscall");
+       }
 
        for (i = 0; i < 8; i++) {
                args[i] = va_arg(va, long int);
@@ -1517,6 +1540,8 @@ static void __swrap_bind_symbol_all_once(void)
        swrap_bind_symbol_rtld_default_optional(uid_wrapper_syscall_valid);
        swrap_bind_symbol_rtld_default_optional(uid_wrapper_syscall_va);
 #endif
+
+       swrap_handle_syscall = true;
 }
 
 static void swrap_bind_symbol_all(void)
@@ -8744,6 +8769,21 @@ long int syscall(long int sysno, ...)
 
        va_start(va, sysno);
 
+       /*
+        * JEMALLOC:
+        *
+        * This is a workaround to prevent a deadlock in jemalloc calling
+        * malloc_init() twice. The first allocation call will trigger a
+        * malloc_init() of jemalloc. The functions calls syscall(SYS_open, ...)
+        * so it goes to socket or uid wrapper. In this code path we need to
+        * avoid any allocation calls. This will prevent the deadlock.
+        */
+       if (!swrap_handle_syscall) {
+               rc = libc_vsyscall(sysno, va);
+               va_end(va);
+               return rc;
+       }
+
        /*
         * We should only handle the syscall numbers
         * we care about...
@@ -8860,6 +8900,9 @@ void swrap_constructor(void)
        pthread_atfork(&swrap_thread_prepare,
                       &swrap_thread_parent,
                       &swrap_thread_child);
+
+       /* Let socket_wrapper handle syscall() */
+       swrap_handle_syscall = true;
 }
 
 /****************************
index fdd09f24ce980200409fd4b938ba73571333a21a..ef839cb93cfd353ad492ec59080b7e469190f4b2 100644 (file)
@@ -2,7 +2,7 @@
 
 import os
 
-VERSION = "1.4.2"
+VERSION = "1.4.3"
 
 
 def configure(conf):
@@ -10,6 +10,7 @@ def configure(conf):
         conf.DEFINE('USING_SYSTEM_SOCKET_WRAPPER', 1)
         libsocket_wrapper_so_path = 'libsocket_wrapper.so'
     else:
+        conf.CHECK_HEADERS('gnu/lib-names.h')
 
         if conf.CONFIG_SET("HAVE___THREAD"):
             conf.DEFINE("HAVE_GCC_THREAD_LOCAL_STORAGE", 1)