The branch, master has been updated
       via  03cea2e swrap: Fix syscall() with jemalloc to prevent a deadlock
       via  9b141c0 tests: Sleep less so that the test runs only for 60sec
       via  9658fec tests: Always link to cmocka library
       via  e3c2432 gitlab-ci: Disable ASLR for TSAN
       via  87f2b5a gitlab-ci: Adapt config to gitlab changes
      from  7af4f26 tests: Fix fake uid_wrapper_syscall_valid().

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


- Log -----------------------------------------------------------------
commit 03cea2ed18bc53bd0e658bc24be6913373d5f97e
Author: Andreas Schneider <a...@samba.org>
Date:   Fri Jun 7 09:39:20 2024 +0200

    swrap: Fix syscall() with jemalloc to prevent a deadlock
    
    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 eadlock.
    
    Pair-Programmed-With: Stefan Metzmacher <me...@samba.org>
    Signed-off-by: Stefan Metzmacher <me...@samba.org>
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 9b141c06568bfba2b9fe63e7d43fb7d1cae12b55
Author: Andreas Schneider <a...@cryptomilk.org>
Date:   Tue Jun 11 08:05:09 2024 +0200

    tests: Sleep less so that the test runs only for 60sec
    
    Signed-off-by: Andreas Schneider <a...@cryptomilk.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 9658fec68b9d20d280c70714d99bc76f23ec7a9a
Author: Andreas Schneider <a...@cryptomilk.org>
Date:   Tue Jun 11 09:41:55 2024 +0200

    tests: Always link to cmocka library
    
    Signed-off-by: Andreas Schneider <a...@cryptomilk.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit e3c243237097750bbdf57bc2e4835ab5e89fcb0e
Author: Andreas Schneider <a...@cryptomilk.org>
Date:   Wed Jun 12 10:28:45 2024 +0200

    gitlab-ci: Disable ASLR for TSAN
    
    This works around a TSAN issue with newer Linux Kernels (6.x).
    
    See https://github.com/google/sanitizers/issues/1716
    
    Signed-off-by: Andreas Schneider <a...@cryptomilk.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 87f2b5ae1c4b88639f76578c0463efe6ae1b051d
Author: Andreas Schneider <a...@samba.org>
Date:   Fri Jun 7 09:52:48 2024 +0200

    gitlab-ci: Adapt config to gitlab changes
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

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

Summary of changes:
 .gitlab-ci.yml             | 33 ++++-----------------------------
 src/socket_wrapper.c       | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 tests/CMakeLists.txt       |  6 +++---
 tests/test_echo_tcp_poll.c |  2 +-
 4 files changed, 52 insertions(+), 34 deletions(-)


Changeset truncated at 500 lines:

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3643167..fdc11c3 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -22,8 +22,6 @@ centos7/x86_64:
       -DPICKY_DEVELOPER=ON
       -DUNIT_TESTING=ON .. &&
       make -j$(nproc) && ctest --output-on-failure
-  tags:
-    - shared
   except:
     - tags
   artifacts:
@@ -41,8 +39,6 @@ fedora/x86_64:
       -DPICKY_DEVELOPER=ON
       -DUNIT_TESTING=ON .. &&
       make -j$(nproc) && ctest --output-on-failure
-  tags:
-    - shared
   except:
     - tags
   artifacts:
@@ -60,8 +56,6 @@ fedora/address-sanitizer:
       -DPICKY_DEVELOPER=ON
       -DUNIT_TESTING=ON .. &&
       make -j$(nproc) && ctest --output-on-failure
-  tags:
-    - shared
   except:
     - tags
   artifacts:
@@ -78,8 +72,6 @@ fedora/undefined-sanitizer:
       -DCMAKE_BUILD_TYPE=UndefinedSanitizer
       -DUNIT_TESTING=ON ..
       && make -j$(nproc) && ctest --output-on-failure
-  tags:
-    - shared
   except:
     - tags
   artifacts:
@@ -95,13 +87,14 @@ tumbleweed/thread-sanitizer:
   stage: analysis
   image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD
   script:
+    # Workaround for TSAN with ASLR on newer kernel
+    # https://github.com/google/sanitizers/issues/1716
     - mkdir -p obj && cd obj && cmake
       -DCMAKE_BUILD_TYPE=ThreadSanitizer
       -DPICKY_DEVELOPER=ON
       -DUNIT_TESTING=ON .. &&
-      make -j$(nproc) && ctest --output-on-failure
-  tags:
-    - shared
+      make -j$(nproc) &&
+      setarch --addr-no-randomize -- ctest --output-on-failure
   except:
     - tags
   artifacts:
@@ -133,8 +126,6 @@ fedora/csbuild:
       --git-commit-range $CI_COMMIT_RANGE
       --color
       --print-current --print-fixed
-  tags:
-    - shared
   except:
     - tags
   artifacts:
@@ -175,8 +166,6 @@ tumbleweed/x86_64/gcc:
       -DPICKY_DEVELOPER=ON
       -DUNIT_TESTING=ON .. &&
       make -j$(nproc) && ctest --output-on-failure
-  tags:
-    - shared
   except:
     - tags
   artifacts:
@@ -195,8 +184,6 @@ tumbleweed/x86_64/gcc7:
       -DPICKY_DEVELOPER=ON
       -DUNIT_TESTING=ON .. &&
       make -j$(nproc) && ctest --output-on-failure
-  tags:
-    - shared
   except:
     - tags
   artifacts:
@@ -215,8 +202,6 @@ tumbleweed/x86_64/clang:
       -DPICKY_DEVELOPER=ON
       -DUNIT_TESTING=ON .. &&
       make -j$(nproc) && ctest --output-on-failure
-  tags:
-    - shared
   except:
     - tags
   artifacts:
@@ -235,8 +220,6 @@ tumbleweed/x86/gcc:
       -DPICKY_DEVELOPER=ON
       -DUNIT_TESTING=ON .. &&
       make -j$(nproc) && ctest --output-on-failure
-  tags:
-    - shared
   except:
     - tags
   artifacts:
@@ -257,8 +240,6 @@ tumbleweed/static-analysis:
       -DPICKY_DEVELOPER=ON
       -DUNIT_TESTING=ON .. &&
       scan-build --status-bugs -o scan make -j$(nproc)
-  tags:
-    - shared
   except:
     - tags
   artifacts:
@@ -277,8 +258,6 @@ tumbleweed/helgrind:
       -DUNIT_TESTING=ON
       -DHELGRIND_TESTING=ON .. &&
       make -j$(nproc) && ctest --output-on-failure
-  tags:
-    - shared
   except:
     - tags
   artifacts:
@@ -299,8 +278,6 @@ ubuntu/x86_64:
       -DPICKY_DEVELOPER=ON
       -DUNIT_TESTING=ON .. &&
       make -j$(nproc) && ctest --output-on-failure
-  tags:
-    - shared
   except:
     - tags
   artifacts:
@@ -318,8 +295,6 @@ ubuntu/x86:
       -DPICKY_DEVELOPER=ON
       -DUNIT_TESTING=ON .. &&
       make -j$(nproc) && ctest --output-on-failure
-  tags:
-    - shared
   except:
     - tags
   artifacts:
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index c759d35..37799c8 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -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;
 }
 
 /****************************
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index eb9708b..cc1b1ec 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -143,7 +143,7 @@ foreach(_SWRAP_TEST ${SWRAP_TESTS})
     add_cmocka_test(${_SWRAP_TEST}
                     SOURCES ${_SWRAP_TEST}.c
                     COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} -D_GNU_SOURCE 
${LFS_CFLAGS}
-                    LINK_LIBRARIES ${TORTURE_LIBRARY} socket_wrapper_noop
+                    LINK_LIBRARIES ${TORTURE_LIBRARY} ${CMOCKA_LIBRARY} 
socket_wrapper_noop
                     LINK_OPTIONS ${DEFAULT_LINK_FLAGS})
     add_cmocka_test_environment(${_SWRAP_TEST})
 endforeach()
@@ -178,7 +178,7 @@ endif()
 add_cmocka_test(test_swrap_unit
                 SOURCES test_swrap_unit.c
                 COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} -D_GNU_SOURCE
-                LINK_LIBRARIES ${TORTURE_LIBRARY} socket_wrapper_noop
+                LINK_LIBRARIES ${TORTURE_LIBRARY} ${CMOCKA_LIBRARY} 
socket_wrapper_noop
                 LINK_OPTIONS ${DEFAULT_LINK_FLAGS})
 add_cmocka_test_environment(test_swrap_unit)
 
@@ -190,6 +190,6 @@ target_compile_options(thread_deadlock PRIVATE 
${DEFAULT_C_COMPILE_FLAGS})
 add_cmocka_test(test_fork_thread_deadlock
                 SOURCES test_fork_thread_deadlock.c
                 COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} -D_GNU_SOURCE
-                LINK_LIBRARIES ${TORTURE_LIBRARY} thread_deadlock
+                LINK_LIBRARIES ${TORTURE_LIBRARY} ${CMOCKA_LIBRARY} 
thread_deadlock
                 LINK_OPTIONS ${DEFAULT_LINK_FLAGS})
 add_cmocka_test_environment(test_fork_thread_deadlock)
diff --git a/tests/test_echo_tcp_poll.c b/tests/test_echo_tcp_poll.c
index 1632eae..a10ba3a 100644
--- a/tests/test_echo_tcp_poll.c
+++ b/tests/test_echo_tcp_poll.c
@@ -83,7 +83,7 @@ static void handle_poll_loop(size_t size, int s)
                                assert_int_not_equal(ret, -1);
                                nread += ret;
                                /* try to delay */
-                               sleep(5);
+                               sleep(1);
                        }
                        if (pfds[j].revents & POLLOUT) {
                                snprintf(send_buf, sizeof(send_buf),


-- 
Socket Wrapper Repository

Reply via email to