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

wsh: fix a crash when a symbol can't be loaded #39

Merged
merged 1 commit into from Nov 6, 2022

Conversation

aurel32
Copy link
Contributor

@aurel32 aurel32 commented Oct 11, 2022

In case a symbol can be loaded dlsym() returns NULL. This need to be handled instead of blindly passing the 0 address do dladdr(), otherwise that causes a crash:

$ ./bin/wsh
init
WARNING: No binary loaded in memory. Try loadbin(). For help type help("loadbin").

[SIGSEGV] Read 0x19 (address not mapped to object)
0x7f7edd231cb1 /lib/x86_64-linux-gnu/libc.so.6(+0x14fcb1)
0x42017f52 ./bin/wsh(scan_syms+0x152)
0x420183c8 ./bin/wsh(parse_link_map_dyn+0x58)
0x4201c371 ./bin/wsh(wsh_run+0x61)
0x4200ecba ./bin/wsh(main+0x3a)
0x7f7edd10520a /lib/x86_64-linux-gnu/libc.so.6(+0x2320a)
0x7f7edd1052bc /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x7c)
0x4200ed0a ./bin/wsh(_start+0x2a)
Segmentation fault (core dumped)

This is reproducible for instance when wsh has been built against glibc <= 2.33, but executed on glibc >= 2.34. This is due to the merge of libdl.so into libc.so, resulting in libdl.so only containing weak symbols. wsh then crashes when trying to dlsym the _ITM_deregisterTMCloneTable symbol.

Rebuilding wcc against glibc >= 2.34 workarounds the problem as the resulting wsh binary is not linked against libdl.so anymore.

In case a symbol can be loaded dlsym() returns NULL. This need to be
handled instead of blindly passing the 0 address do dladdr(), otherwise
that causes a crash:

$ ./bin/wsh
init
WARNING: No binary loaded in memory. Try loadbin(). For help type help("loadbin").

[SIGSEGV]       Read    0x19        (address not mapped to object)
        0x7f7edd231cb1    /lib/x86_64-linux-gnu/libc.so.6(+0x14fcb1)
        0x42017f52    ./bin/wsh(scan_syms+0x152)
        0x420183c8    ./bin/wsh(parse_link_map_dyn+0x58)
        0x4201c371    ./bin/wsh(wsh_run+0x61)
        0x4200ecba    ./bin/wsh(main+0x3a)
        0x7f7edd10520a    /lib/x86_64-linux-gnu/libc.so.6(+0x2320a)
        0x7f7edd1052bc    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x7c)
        0x4200ed0a    ./bin/wsh(_start+0x2a)
Segmentation fault (core dumped)

This is reproducible for instance when wsh has been built against glibc
<= 2.33, but executed on glibc >= 2.34. This is due to the merge of
libdl.so into libc.so, resulting in libdl.so only containing weak
symbols. wsh then crashes when trying to dlsym the
_ITM_deregisterTMCloneTable symbol.

Rebuilding wcc against glibc >= 2.34 workarounds the problem as the
resulting wsh binary is not linked against libdl.so anymore.
Copy link
Owner

@endrazine endrazine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix to deal with symbols that would return NULL via dlsym().

@endrazine
Copy link
Owner

Hi Aurel32,

Thanks for your bug report and patch :)

Best regards,

j-

@endrazine endrazine merged commit 503f6df into endrazine:master Nov 6, 2022
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.

None yet

2 participants