From fac763de70d443a2d52028f4129c4accdead46fa Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Mon, 18 Mar 2024 15:19:45 +0100 Subject: [PATCH 1/2] chore(test/libsisnp_e2e): use an unique_ptr for m_inspector. Signed-off-by: Federico Di Pierro --- test/libsinsp_e2e/container/container.cpp | 13 ++++++++++--- test/libsinsp_e2e/event_capture.cpp | 21 ++++++--------------- test/libsinsp_e2e/event_capture.h | 2 +- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/test/libsinsp_e2e/container/container.cpp b/test/libsinsp_e2e/container/container.cpp index 64245a4162..7635e17fb0 100644 --- a/test/libsinsp_e2e/container/container.cpp +++ b/test/libsinsp_e2e/container/container.cpp @@ -167,9 +167,16 @@ TEST_F(sys_call_test, container_clone_nspid) { FAIL(); } - - wait(NULL); - free(stack); + else if (ctid == 0) + { + free(stack); + _exit(0); + } + else + { + free(stack); + waitpid(ctid, NULL, 0); + } }; // diff --git a/test/libsinsp_e2e/event_capture.cpp b/test/libsinsp_e2e/event_capture.cpp index b360a02775..6b66f4ccc5 100644 --- a/test/libsinsp_e2e/event_capture.cpp +++ b/test/libsinsp_e2e/event_capture.cpp @@ -31,7 +31,7 @@ unsigned long event_capture::m_buffer_dim = DEFAULT_DRIVER_BUFFER_BYTES_DIM; concurrent_object_handle event_capture::get_inspector_handle() { - return {m_inspector, m_inspector_mutex}; + return {m_inspector.get(), m_inspector_mutex}; } void event_capture::capture() @@ -40,7 +40,7 @@ void event_capture::capture() { // Begin init synchronized section std::scoped_lock init_lock(m_inspector_mutex, m_object_state_mutex); - m_inspector = new sinsp(); + m_inspector = std::make_unique(); m_inspector->m_thread_manager->set_max_thread_table_size(m_max_thread_table_size); m_inspector->m_thread_timeout_ns = m_thread_timeout_ns; @@ -49,9 +49,9 @@ void event_capture::capture() m_inspector->set_get_procs_cpu_from_driver(true); - m_param.m_inspector = m_inspector; + m_param.m_inspector = m_inspector.get(); - m_before_open(m_inspector); + m_before_open(m_inspector.get()); ASSERT_FALSE(m_inspector->is_capture()); ASSERT_FALSE(m_inspector->is_live()); @@ -79,7 +79,6 @@ void event_capture::capture() m_capture_started = true; m_condition_started.notify_one(); } - delete m_inspector; return; } @@ -95,7 +94,7 @@ void event_capture::capture() { m_dump_filename = std::string(LIBSINSP_TEST_CAPTURES_PATH) + test_info->test_case_name() + "_" + test_info->name() + ".scap"; - dumper = std::make_unique(m_inspector, m_dump_filename.c_str(), + dumper = std::make_unique(m_inspector.get(), m_dump_filename.c_str(), 0, 0, 0, 0, true); } } // End init synchronized section @@ -165,11 +164,7 @@ void event_capture::capture() { // Begin teardown synchronized section std::scoped_lock teardown_lock(m_inspector_mutex, m_object_state_mutex); - m_before_close(m_inspector); - - m_inspector->stop_capture(); - - delete m_inspector; + m_before_close(m_inspector.get()); m_capture_stopped = true; m_condition_stopped.notify_one(); @@ -180,10 +175,6 @@ void event_capture::capture() void event_capture::stop_capture() { - if (m_inspector) - { - m_inspector->stop_capture(); - } { std::scoped_lock init_lock(m_inspector_mutex, m_object_state_mutex); m_capture_stopped = true; diff --git a/test/libsinsp_e2e/event_capture.h b/test/libsinsp_e2e/event_capture.h index debf83bf0b..79517e1419 100644 --- a/test/libsinsp_e2e/event_capture.h +++ b/test/libsinsp_e2e/event_capture.h @@ -223,7 +223,7 @@ class event_capture std::string m_start_failure_message; std::string m_dump_filename; callback_param m_param; - sinsp* m_inspector; + std::unique_ptr m_inspector; sinsp_mode_t m_mode; uint64_t m_max_timeouts; }; From 4d19812257d7406c2a34aaaf1cda85a43af69bdc Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Mon, 18 Mar 2024 15:20:54 +0100 Subject: [PATCH 2/2] fix(ci): fixed recent asan-related CI issues. See actions/runner-images#9524 (comment) for the fix. Signed-off-by: Federico Di Pierro --- .github/workflows/ci.yml | 6 ++++++ .github/workflows/e2e_ci.yml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index acb5b49e71..c769fff8de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -282,6 +282,12 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: fetch-depth: 0 + + - name: Fix kernel mmap rnd bits + # Asan in llvm 14 provided in ubuntu 22.04 is incompatible with + # high-entropy ASLR in much newer kernels that GitHub runners are + # using leading to random crashes: https://reviews.llvm.org/D148280 + run: sudo sysctl vm.mmap_rnd_bits=28 - name: Install deps ⛓️ run: | diff --git a/.github/workflows/e2e_ci.yml b/.github/workflows/e2e_ci.yml index 860827a0f1..67ac249478 100644 --- a/.github/workflows/e2e_ci.yml +++ b/.github/workflows/e2e_ci.yml @@ -27,6 +27,12 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: fetch-depth: 0 + + - name: Fix kernel mmap rnd bits + # Asan in llvm 14 provided in ubuntu 22.04 is incompatible with + # high-entropy ASLR in much newer kernels that GitHub runners are + # using leading to random crashes: https://reviews.llvm.org/D148280 + run: sudo sysctl vm.mmap_rnd_bits=28 - name: Install deps ⛓️ run: |