Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libcextract: Add support to zstd #104

Merged
merged 1 commit into from
Aug 13, 2024

Conversation

marcosps
Copy link
Collaborator

With this change clang-extract can parse kernel modules compressed using zstd.

@marcosps
Copy link
Collaborator Author

@giulianobelinassi it seems that the code is triggering a double-free on the Parser class, but I'm not able to understand why is this happening...

I can reproduce it using a kernel module that is compressed with zst. Can you take a look? We can check it tomorrow with a proper module to debug this issue.

@marcosps
Copy link
Collaborator Author

=================================================================
==39679==ERROR: AddressSanitizer: attempting double-free on 0x50b000000b40 in thread T0:
    #0 0x55d3cb5f53e8 in operator delete(void*) /home/abuild/rpmbuild/BUILD/llvm-18.1.8.src/projects/compiler-rt/lib/asan/asan_new_delete.cpp:143:3
    #1 0x55d3cb5fa02c in std::__new_allocator<char>::deallocate(char*, unsigned long) /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/new_allocator.h:172:2
    #2 0x55d3cb5f9fb7 in std::allocator<char>::deallocate(char*, unsigned long) /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/allocator.h:210:25
    #3 0x55d3cb5f9fb7 in std::allocator_traits<std::allocator<char>>::deallocate(std::allocator<char>&, char*, unsigned long) /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/alloc_traits.h:517:13
    #4 0x55d3cb5f9fb7 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_destroy(unsigned long) /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/basic_string.h:289:9
    #5 0x55d3cb5f9ea6 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_dispose() /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/basic_string.h:283:4
    #6 0x55d3cb5fa0d8 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/basic_string.h:804:9
    #7 0x55d3cb96cef4 in Parser::~Parser() /home/mpdesouza/git/clang-extract/build/../libcextract/Parser.hh:25:7
    #8 0x55d3cb9e0b4c in ElfObject::ElfObject(char const*) /home/mpdesouza/git/clang-extract/build/../libcextract/ElfCXX.cpp:141:1
    #9 0x55d3cb966390 in InlineAnalysis::InlineAnalysis(char const*, char const*, char const*, bool) /home/mpdesouza/git/clang-extract/build/../libcextract/InlineAnalysis.cpp:37:20
    #10 0x55d3cb610d53 in PassManager::Context::Context(ArgvParser&) /home/mpdesouza/git/clang-extract/build/../libcextract/Passes.hh:70:13
    #11 0x55d3cb60c7fc in PassManager::Run_Passes(ArgvParser&) /home/mpdesouza/git/clang-extract/build/../libcextract/Passes.cpp:653:13
    #12 0x55d3cb5f7203 in main /home/mpdesouza/git/clang-extract/build/../Main.cpp:38:24
    #13 0x7fe90622a33f in __libc_start_call_main (/lib64/libc.so.6+0x2a33f) (BuildId: b9cf52933b9968ed778c3a60dd03d2c3e18313f2)
    #14 0x7fe90622a408 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2a408) (BuildId: b9cf52933b9968ed778c3a60dd03d2c3e18313f2)
    #15 0x55d3cb5191f4 in _start /home/abuild/rpmbuild/BUILD/glibc-2.40/csu/../sysdeps/x86_64/start.S:115

0x50b000000b40 is located 0 bytes inside of 100-byte region [0x50b000000b40,0x50b000000ba4)
freed by thread T0 here:
    #0 0x55d3cb5f53e8 in operator delete(void*) /home/abuild/rpmbuild/BUILD/llvm-18.1.8.src/projects/compiler-rt/lib/asan/asan_new_delete.cpp:143:3
    #1 0x55d3cb5fa02c in std::__new_allocator<char>::deallocate(char*, unsigned long) /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/new_allocator.h:172:2
    #2 0x55d3cb5f9fb7 in std::allocator<char>::deallocate(char*, unsigned long) /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/allocator.h:210:25
    #3 0x55d3cb5f9fb7 in std::allocator_traits<std::allocator<char>>::deallocate(std::allocator<char>&, char*, unsigned long) /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/alloc_traits.h:517:13
    #4 0x55d3cb5f9fb7 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_destroy(unsigned long) /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/basic_string.h:289:9
    #5 0x55d3cb5f9ea6 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_dispose() /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/basic_string.h:283:4
    #6 0x55d3cb5fa0d8 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/basic_string.h:804:9
    #7 0x55d3cb96cef4 in Parser::~Parser() /home/mpdesouza/git/clang-extract/build/../libcextract/Parser.hh:25:7
    #8 0x55d3cb9e2652 in ElfObject::~ElfObject() /home/mpdesouza/git/clang-extract/build/../libcextract/ElfCXX.cpp:156:1
    #9 0x55d3cb9e08ed in ElfObject::ElfObject(char const*) /home/mpdesouza/git/clang-extract/build/../libcextract/ElfCXX.cpp:131:18
    #10 0x55d3cb966390 in InlineAnalysis::InlineAnalysis(char const*, char const*, char const*, bool) /home/mpdesouza/git/clang-extract/build/../libcextract/InlineAnalysis.cpp:37:20
    #11 0x55d3cb610d53 in PassManager::Context::Context(ArgvParser&) /home/mpdesouza/git/clang-extract/build/../libcextract/Passes.hh:70:13
    #12 0x55d3cb60c7fc in PassManager::Run_Passes(ArgvParser&) /home/mpdesouza/git/clang-extract/build/../libcextract/Passes.cpp:653:13
    #13 0x55d3cb5f7203 in main /home/mpdesouza/git/clang-extract/build/../Main.cpp:38:24
    #14 0x7fe90622a33f in __libc_start_call_main (/lib64/libc.so.6+0x2a33f) (BuildId: b9cf52933b9968ed778c3a60dd03d2c3e18313f2)

previously allocated by thread T0 here:
    #0 0x55d3cb5f4b08 in operator new(unsigned long) /home/abuild/rpmbuild/BUILD/llvm-18.1.8.src/projects/compiler-rt/lib/asan/asan_new_delete.cpp:86:3
    #1 0x55d3cb5f9c9e in std::__new_allocator<char>::allocate(unsigned long, void const*) /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/new_allocator.h:151:27
    #2 0x55d3cb5f9c20 in std::allocator<char>::allocate(unsigned long) /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/allocator.h:198:32
    #3 0x55d3cb5f9c20 in std::allocator_traits<std::allocator<char>>::allocate(std::allocator<char>&, unsigned long) /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/alloc_traits.h:482:20
    #4 0x55d3cb5f9c20 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_S_allocate(std::allocator<char>&, unsigned long) /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/basic_string.h:126:16
    #5 0x55d3cb5f98c1 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_create(unsigned long&, unsigned long) /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/basic_string.tcc:159:14
    #6 0x55d3cb5ff38c in void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_construct<char const*>(char const*, char const*, std::forward_iterator_tag) /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/basic_string.tcc:229:14
    #7 0x55d3cb5fd748 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string<std::allocator<char>>(char const*, std::allocator<char> const&) /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/basic_string.h:649:2
    #8 0x55d3cb9779f2 in Parser::Parser(char const*) /home/mpdesouza/git/clang-extract/build/../libcextract/Parser.hh:40:19
    #9 0x55d3cb9dfe22 in ElfObject::ElfObject(char const*) /home/mpdesouza/git/clang-extract/build/../libcextract/ElfCXX.cpp:84:5
    #10 0x55d3cb966390 in InlineAnalysis::InlineAnalysis(char const*, char const*, char const*, bool) /home/mpdesouza/git/clang-extract/build/../libcextract/InlineAnalysis.cpp:37:20
    #11 0x55d3cb610d53 in PassManager::Context::Context(ArgvParser&) /home/mpdesouza/git/clang-extract/build/../libcextract/Passes.hh:70:13
    #12 0x55d3cb60c7fc in PassManager::Run_Passes(ArgvParser&) /home/mpdesouza/git/clang-extract/build/../libcextract/Passes.cpp:653:13
    #13 0x55d3cb5f7203 in main /home/mpdesouza/git/clang-extract/build/../Main.cpp:38:24
    #14 0x7fe90622a33f in __libc_start_call_main (/lib64/libc.so.6+0x2a33f) (BuildId: b9cf52933b9968ed778c3a60dd03d2c3e18313f2)

SUMMARY: AddressSanitizer: double-free /home/mpdesouza/git/clang-extract/build/../libcextract/Parser.hh:25:7 in Parser::~Parser()
==39679==ABORTING
****

With this change clang-extract can parse kernel modules compressed using
zstd.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
@marcosps
Copy link
Collaborator Author

Fixed. Let's check if the CI is happy now.

@giulianobelinassi giulianobelinassi merged commit 82f77f7 into SUSE:main Aug 13, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants