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

archive-file: Work-around when strtab.data() returns NULL #269

Closed
wants to merge 1 commit into from

Conversation

sina-ht
Copy link
Contributor

@sina-ht sina-ht commented Jan 13, 2022

Under certain environment, strtab.data() could return NULL, and link would
fail. See the ASAN output below.

AddressSanitizer:DEADLYSIGNAL

==1022==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7ffff6e9455d bp 0x000000000000 sp 0x7fffffff9aa8 T0)
==1022==The signal is caused by a READ memory access.
==1022==Hint: address points to the zero page.
#0 0x7ffff6e9455d in __strstr_sse2_unaligned (/lib/libc.so.6+0xb755d)
#1 0x7ffff7659b20 in __interceptor_strstr ../../../../gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:595
#2 0x7ffff7659b20 in __interceptor_strstr ../../../../gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:590
#3 0x555555b7d28c in std::vector<mold::MappedFile<mold::elf::Contextmold::elf::X86_64 >, std::allocator<mold::MappedFile<mold::elf::Contextmold::elf::X86_64 >> > mold::read_fat_archive_members<mold::elf::Contextmold::elf::X86_64 >(mold::elf::Contextmold::elf::X86_64&, mold::MappedFile<mold::elf::Contextmold::elf::X86_64 >*) elf/../archive-file.h:99

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib/libc.so.6+0xb755d) in __strstr_sse2_unaligned
==1022==ABORTING

Signed-off-by: Hiroshi Takekawa sian.ht@gmail.com

Under certain environment, strtab.data() could return NULL, and link would
fail. See the ASAN output below.

AddressSanitizer:DEADLYSIGNAL
=================================================================
==1022==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7ffff6e9455d bp 0x000000000000 sp 0x7fffffff9aa8 T0)
==1022==The signal is caused by a READ memory access.
==1022==Hint: address points to the zero page.
    #0 0x7ffff6e9455d in __strstr_sse2_unaligned (/lib/libc.so.6+0xb755d)
    rui314#1 0x7ffff7659b20 in __interceptor_strstr ../../../../gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:595
    rui314#2 0x7ffff7659b20 in __interceptor_strstr ../../../../gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:590
    rui314#3 0x555555b7d28c in std::vector<mold::MappedFile<mold::elf::Context<mold::elf::X86_64> >*, std::allocator<mold::MappedFile<mold::elf::Context<mold::elf::X86_64> >*> > mold::read_fat_archive_members<mold::elf::Context<mold::elf::X86_64> >(mold::elf::Context<mold::elf::X86_64>&, mold::MappedFile<mold::elf::Context<mold::elf::X86_64> >*) elf/../archive-file.h:99

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib/libc.so.6+0xb755d) in __strstr_sse2_unaligned
==1022==ABORTING

Signed-off-by: Hiroshi Takekawa <sian.ht@gmail.com>
@sina-ht
Copy link
Contributor Author

sina-ht commented Jan 13, 2022

I need this W/A to use mold in my environment. I don't know whether this could happen in others' or not. But it simply worked for me.
Would you identify what the problem is? If it's my environment only that needs this W/A, throw this away. It's my fault.
Otherwise consider pulling this or fix in a proper way. Thanks.

@rui314
Copy link
Owner

rui314 commented Jan 13, 2022

I think that mold crashed because strtab is not initialized when the control reaches there. I'm not sure whether your archive file is corrupted or mold's assumption is wrong. Could you attach an archive file with which mold crashes?

@sina-ht
Copy link
Contributor Author

sina-ht commented Jan 13, 2022

moldtest.tar.gz
This archive contains Makefile, source codes, objects, and archives.
Probably it'd be sufficient for you to have archives, but I compiled this archive for completeness.
Because the archives are libgcc/libc, so it's virtually impossible to link any program...
I built glibc and gcc by myself, so it'd be my fault, but I think it'd be nice for mold to avoid receiving SIGSEGV for broken (or malicious) files.
Thank you for your time.

rui314 added a commit that referenced this pull request Jan 13, 2022
I believe this pseudo member is relatively new to support archive
files larger than 4 GiB. I'm not sure if mold can handle such large
archives, but first of all, mold crashes when an archive with this
pseudo member is given.

This commit fixes the crash bug.

I don't know how to create an archive with this pseudo member, so
this commit does not have a testcase.

Reported by sina-ht at #269.
@rui314
Copy link
Owner

rui314 commented Jan 13, 2022

Thank you for sharing the file. It looks like your archives contains /SYM64/ pseudo members. We should explicitly skip them, so I made such change in bba506d.

@rui314 rui314 closed this Jan 13, 2022
@sina-ht
Copy link
Contributor Author

sina-ht commented Jan 13, 2022

Thank you for fix and giving me a credit for report.

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