public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/100114] New: libasan built against latest glibc doesn't work
@ 2021-04-16 12:45 jakub at gcc dot gnu.org
  2021-04-16 12:49 ` [Bug sanitizer/100114] " jakub at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-04-16 12:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100114

            Bug ID: 100114
           Summary: libasan built against latest glibc doesn't work
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org
  Target Milestone: ---

If libsanitizer is built against glibc trunk, nothing really works:
./a
==91==ERROR: AddressSanitizer failed to allocate 0x0 (0) bytes of
SetAlternateSignalStack (error code: 22)
==91==Process memory map follows:

I think this is caused by
// TODO(glider): different tools may require different altstack size.
static const uptr kAltStackSize = SIGSTKSZ * 4;  // SIGSTKSZ is not enough.

void SetAlternateSignalStack() {
  stack_t altstack, oldstack;
  CHECK_EQ(0, sigaltstack(nullptr, &oldstack));
  // If the alternate stack is already in place, do nothing.
  // Android always sets an alternate stack, but it's too small for us.
  if (!SANITIZER_ANDROID && !(oldstack.ss_flags & SS_DISABLE)) return;
  // TODO(glider): the mapped stack should have the MAP_STACK flag in the
  // future. It is not required by man 2 sigaltstack now (they're using
  // malloc()).
  void* base = MmapOrDie(kAltStackSize, __func__);
  altstack.ss_sp = (char*) base;
  altstack.ss_flags = 0;
  altstack.ss_size = kAltStackSize;
  CHECK_EQ(0, sigaltstack(&altstack, nullptr));
}

called from
#0  0x00007ffff7644650 in sigaltstack () from ./libasan.so.6
#1  0x00007ffff76bca92 in __sanitizer::SetAlternateSignalStack() () from
./libasan.so.6
#2  0x00007ffff76bcc65 in __sanitizer::InstallDeadlySignalHandlers(void
(*)(int, void*, void*)) () from ./libasan.so.6
#3  0x00007ffff76ab60c in __asan::AsanInitInternal() [clone .part.0] () from
./libasan.so.6
#4  0x00007ffff7fdb6ee in _dl_init () from /lib64/ld-linux-x86-64.so.2
#5  0x00007ffff7fcc0ca in _dl_start_user () from /lib64/ld-linux-x86-64.so.2

and __asan_init which tail calls AsanInitInternal is registered in
.preinit_array.

As in newer glibcs SIGSTKSZ is no longer a constant - since
https://sourceware.org/git/?p=glibc.git;a=commit;h=6c57d320484988e87e446e2e60ce42816bf51d53
- I think the above is invalid C++, because the function is called before the
kAltStackSize variable is constructed (which is why we end up with calling
MmapOrDie(0, __func__);
and that fails miserably.

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-02-07  5:54 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-16 12:45 [Bug sanitizer/100114] New: libasan built against latest glibc doesn't work jakub at gcc dot gnu.org
2021-04-16 12:49 ` [Bug sanitizer/100114] " jakub at gcc dot gnu.org
2021-04-16 12:52 ` rguenth at gcc dot gnu.org
2021-04-16 13:20 ` hjl.tools at gmail dot com
2021-04-16 13:22 ` jakub at gcc dot gnu.org
2021-04-17  9:30 ` cvs-commit at gcc dot gnu.org
2021-04-17 19:25 ` jakub at gcc dot gnu.org
2021-04-19  6:57 ` rguenth at gcc dot gnu.org
2021-04-20  9:46 ` cvs-commit at gcc dot gnu.org
2021-04-20 23:35 ` cvs-commit at gcc dot gnu.org
2021-04-22 16:53 ` cvs-commit at gcc dot gnu.org
2021-04-22 17:10 ` jakub at gcc dot gnu.org
2021-08-05  8:52 ` marxin at gcc dot gnu.org
2021-09-11 14:29 ` pinskia at gcc dot gnu.org
2023-02-07  5:36 ` alexander.enaldiev at gmail dot com
2023-02-07  5:54 ` fw at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).