This is an archive of the discontinued LLVM Phabricator instance.

[asan] Fix asan initialization failure with newer (2.23+) glibc in use.
ClosedPublic

Authored by m.ostapenko on May 13 2016, 6:13 AM.

Details

Summary

This patch tries to fix https://llvm.org/bugs/show_bug.cgi?id=27310 by using the same hack for malloc as we use for calloc: allocate corresponding memory from internal buffer when ASan is not initialized. This way we could avoid nasty '==6987==AddressSanitizer CHECK failed: ../../../../libsanitizer/asan/asan_rtl.cc:556 "((!asan_init_is_running && "ASan init calls itself!")) != (0)" (0x0, 0x0)' errors in environments with glibc 2.23+ in use, where _dl_signal_error, called from dlsym for undefined symbols calls malloc in order to get a buffer for error message.

I've tested this patch with current trunk Glibc version with/without https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=24e2b1cede1952d7d4411a3cafd25dd8593dab9f applied under qemu-arm (host is Ubuntu 14.04 box) under both GCC and Clang regression testsuites and verified that initialization error gone. If that's not enough, I can proceed with installing, say, Fedora 23, and testing the patch there, but this may take some time.

Diff Detail

Repository
rL LLVM

Event Timeline

m.ostapenko retitled this revision from to [asan] Fix asan initialization failure with newer (2.23+) glibc in use..
m.ostapenko updated this object.
m.ostapenko added reviewers: kcc, eugenis, dvyukov.
m.ostapenko set the repository for this revision to rL LLVM.
m.ostapenko added subscribers: ygribov, llvm-commits.
ygribov added inline comments.May 13 2016, 7:42 AM
lib/asan/asan_malloc_linux.cc
29–31

Why push up the const? BTW sad we don't have "cold" attribute for globals...

34

What about overflow? That's bug in original code but anyhow...

35

Should this be s/kDlsymAllocPoolSize/sizeof(alloc_memory_for_dlsym)/ ? Also probably no need to compare with 0?

39

RoundUpTo?

m.ostapenko added inline comments.May 13 2016, 8:02 AM
lib/asan/asan_malloc_linux.cc
29–31

No particular reason actually, just was afraid 1024 is not enough.

34

Yeah, we need use uptr instead and check:

  1. ptr >= alloc_memory_for_dlsym
  2. (ptr - alloc_memory_for_dlsym) < sizeof(alloc_memory_for_dlsym)

Addressing Yura's nits.

m.ostapenko marked 6 inline comments as done.May 13 2016, 8:59 AM
kcc edited edge metadata.May 13 2016, 10:15 AM

Mostly LGTM.
It's sad we need to do this, looks like we have to...
Thanks!

lib/asan/asan_malloc_linux.cc
29–31

Please use a more descriptive name, e.g. allocated_for_dlsym

35

You can do a range check using unsigned arithmetic and just one compare.

44

replace with CHECK_LT, while you are at it

m.ostapenko edited edge metadata.

Updating according to last review. If it's OK, I'll commit this on Monday.

kcc accepted this revision.May 13 2016, 10:48 AM
kcc edited edge metadata.

LGTM, thanks again.

This revision is now accepted and ready to land.May 13 2016, 10:48 AM
This revision was automatically updated to reflect the committed changes.