falcosecurity / libs

libsinsp, libscap, the kernel module driver, and the eBPF driver sources
https://falcosecurity.github.io/libs/
Apache License 2.0
212 stars 159 forks source link

Coverage build is broken for plugin tests #1701

Closed LucaGuerra closed 3 months ago

LucaGuerra commented 4 months ago

Describe the bug

$ cmake -DCMAKE_BUILD_TYPE=Coverage -DUSE_BUNDLED_DEPS=On
$ make -j10 unit-test-libsinsp
$ ./libsinsp/test/unit-test-libsinsp

[snip]
[ RUN      ] sinsp_with_test_input.plugin_syscall_extract
Segmentation fault

The stack trace is quite interesting

#0  __memmove_evex_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:341
#1  0x00007ffff7d4c55d in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&) ()
   from /lib/x86_64-linux-gnu/libstdc++.so.6
#2  0x0000555556140984 in plugin_extract_fields (s=0x555558b9aff0, ev=0x7fffffffcf70, in=0x7fffffffcfc0) at /home/ubuntu/dev/falcosecurity/libs/userspace/libsinsp/test/plugins/syscall_extract.cpp:356
#3  0x00005555564fc1a9 in sinsp_plugin::extract_fields (this=0x555558ba1b60, evt=0x555558b50578, num_fields=1, fields=0x7fffffffd100) at /home/ubuntu/dev/falcosecurity/libs/userspace/libsinsp/plugin.cpp:900
#4  0x0000555556670930 in sinsp_filter_check_plugin::extract (this=0x555558b6d7f0, evt=0x555558b50578, values=std::vector of length 0, capacity 0, sanitize_strings=true)
    at /home/ubuntu/dev/falcosecurity/libs/userspace/libsinsp/plugin_filtercheck.cpp:181
#5  0x00005555564d6aeb in sinsp_filter_check::tostring (this=0x555558b6d7f0, evt=0x555558b50578) at /home/ubuntu/dev/falcosecurity/libs/userspace/libsinsp/sinsp_filtercheck.cpp:1164
#6  0x0000555555ded150 in sinsp_with_test_input::get_field_as_string (this=0x555558b50400, evt=0x555558b50578, field_name="sample.proc_name", flist=...)
    at /home/ubuntu/dev/falcosecurity/libs/userspace/libsinsp/test/sinsp_with_test_input.cpp:485
#7  0x0000555555f4110d in sinsp_with_test_input_plugin_syscall_extract_Test::TestBody (this=0x555558b50400) at /home/ubuntu/dev/falcosecurity/libs/userspace/libsinsp/test/plugins.ut.cpp:176
#8  0x00005555576dacf9 in testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void> (object=0x555558b50400, method=&virtual testing::Test::TestBody(), location=0x5555578ffe3b "the test body")
    at /home/ubuntu/dev/falcosecurity/libs/build-coverage/googletest-src/googletest/src/gtest.cc:2599
#9  0x00005555576ce72f in testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void> (object=0x555558b50400, method=&virtual testing::Test::TestBody(), location=0x5555578ffe3b "the test body")
    at /home/ubuntu/dev/falcosecurity/libs/build-coverage/googletest-src/googletest/src/gtest.cc:2635
#10 0x000055555768587d in testing::Test::Run (this=0x555558b50400) at /home/ubuntu/dev/falcosecurity/libs/build-coverage/googletest-src/googletest/src/gtest.cc:2674
#11 0x00005555576870b6 in testing::TestInfo::Run (this=0x555558b34bd0) at /home/ubuntu/dev/falcosecurity/libs/build-coverage/googletest-src/googletest/src/gtest.cc:2853
#12 0x0000555557688471 in testing::TestSuite::Run (this=0x555558b25f10) at /home/ubuntu/dev/falcosecurity/libs/build-coverage/googletest-src/googletest/src/gtest.cc:3012
#13 0x00005555576ab795 in testing::internal::UnitTestImpl::RunAllTests (this=0x555558b21ae0) at /home/ubuntu/dev/falcosecurity/libs/build-coverage/googletest-src/googletest/src/gtest.cc:5870
#14 0x00005555576dc5d6 in testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> (object=0x555558b21ae0,
    method=(bool (testing::internal::UnitTestImpl::*)(testing::internal::UnitTestImpl * const)) 0x5555576aae92 <testing::internal::UnitTestImpl::RunAllTests()>,
    location=0x5555579008b0 "auxiliary test code (environments or event listeners)") at /home/ubuntu/dev/falcosecurity/libs/build-coverage/googletest-src/googletest/src/gtest.cc:2599
#15 0x00005555576d0623 in testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> (object=0x555558b21ae0,
    method=(bool (testing::internal::UnitTestImpl::*)(testing::internal::UnitTestImpl * const)) 0x5555576aae92 <testing::internal::UnitTestImpl::RunAllTests()>,
    location=0x5555579008b0 "auxiliary test code (environments or event listeners)") at /home/ubuntu/dev/falcosecurity/libs/build-coverage/googletest-src/googletest/src/gtest.cc:2635
#16 0x00005555576a8241 in testing::UnitTest::Run (this=0x555558aba900 <testing::UnitTest::GetInstance()::instance>) at /home/ubuntu/dev/falcosecurity/libs/build-coverage/googletest-src/googletest/src/gtest.cc:5444
#17 0x0000555556819ff3 in RUN_ALL_TESTS () at /home/ubuntu/dev/falcosecurity/libs/build-coverage/googletest-src/googletest/include/gtest/gtest.h:2293
#18 0x0000555556819e8c in main (argc=1, argv=0x7fffffffe198) at /home/ubuntu/dev/falcosecurity/libs/build-coverage/googletest-src/googletest/src/gtest_main.cc:51
(gdb) up
#1  0x00007ffff7d4c55d in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&) ()
   from /lib/x86_64-linux-gnu/libstdc++.so.6
(gdb) up
#2  0x0000555556140984 in plugin_extract_fields (s=0x555558b9aff0, ev=0x7fffffffcf70, in=0x7fffffffcfc0) at /home/ubuntu/dev/falcosecurity/libs/userspace/libsinsp/test/plugins/syscall_extract.cpp:356
356                     ps->strstorage = std::string(tmp.str);
(gdb) p tmp.str
$1 = 0x555558b7eeb0 "init"
(gdb) p ps->strstorage
$3 = ""
(gdb) x/1qwx &ps->strstorage
0x555558b9b018: 0x00000000

I wonder if that's because we initialize that structure with new plugin_state() which memsets() the thing to zero instead of default initializing it? 🤔

LucaGuerra commented 3 months ago

should be fixed by : https://github.com/falcosecurity/libs/pull/1766

If something happens again I'll open another issue

/close

poiana commented 3 months ago

@LucaGuerra: Closing this issue.

In response to [this](https://github.com/falcosecurity/libs/issues/1701#issuecomment-2042358016): >should be fixed by : https://github.com/falcosecurity/libs/pull/1766 > >If something happens again I'll open another issue > >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.