public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug dynamic-link/31991] New: Using LD_AUDIT with LD_PRELOAD and TLS segfaults
@ 2024-07-18 16:09 matthewkenigsberg at gmail dot com
  2024-07-18 21:14 ` [Bug dynamic-link/31991] " akostadinov at gmail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: matthewkenigsberg at gmail dot com @ 2024-07-18 16:09 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=31991

            Bug ID: 31991
           Summary: Using LD_AUDIT with LD_PRELOAD and TLS segfaults
           Product: glibc
           Version: 2.31
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: dynamic-link
          Assignee: unassigned at sourceware dot org
          Reporter: matthewkenigsberg at gmail dot com
  Target Milestone: ---

When a library loaded with LD_PRELOAD uses sufficient TLS and an audit library
is also loaded with LD_AUDIT, the program being run segfaults with:
./main: error while loading shared libraries: ./preload.so: cannot allocate
memory in static TLS block

This was originally reported in a jemalloc issue:
https://github.com/jemalloc/jemalloc/issues/2472

The case reported there is LD_PRELOAD=$MY_SCRATCH_DIR/mylibs/lib/libjemalloc.so
LD_AUDIT=libsimple.so ls

libjemalloc uses a large enough amount of TLS, so ls segfaults

When I tried to extract a more minimal reproducer, it seems jemalloc does not
have to be involved at all, so I'm wondering if this is actually a bug in
glibc.

I don't see the bug if the amount of TLS is small. If I change 465 to 464
below, I don't see the segfault.

Here's a minimal reproducer:

cat <<EOF > preload.c
__thread int preload_data[465] __attribute__((tls_model("initial-exec")));

int preload_function() {
    return preload_data[0];
}
EOF

gcc -shared preload.c -o preload.so

cat <<EOF > audit.c
unsigned int
la_version( unsigned int version )
{
  return version;
}
EOF

gcc -shared audit.c -o audit.so

cat <<EOF > main.c
#include <stdio.h>

int main()
{
    printf("Hello, World!\n");
    return 0;
}
EOF

gcc main.c -o main

./main # succeeds
LD_PRELOAD=./preload.so ./main # succeeds
LD_AUDIT=./audit.so ./main # succeeds
LD_PRELOAD=./preload.so LD_AUDIT=./audit.so ./main # segfaults

I'm running on aarch64 Debian 5.10 with glibc 2.31. gcc --version gives:
gcc (Debian 10.2.1-6) 10.2.1 20210110

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2024-09-19 19:12 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-18 16:09 [Bug dynamic-link/31991] New: Using LD_AUDIT with LD_PRELOAD and TLS segfaults matthewkenigsberg at gmail dot com
2024-07-18 21:14 ` [Bug dynamic-link/31991] " akostadinov at gmail dot com
2024-07-19  6:43 ` [Bug dynamic-link/31991] Insufficient static TLS reservation when auditing leads to process start failure fweimer at redhat dot com
2024-07-19 23:25 ` matthewkenigsberg at gmail dot com
2024-07-25 22:40 ` matthewkenigsberg at gmail dot com
2024-07-26 10:59 ` fweimer at redhat dot com
2024-09-19 16:30 ` matthewkenigsberg at gmail dot com
2024-09-19 16:43 ` fweimer at redhat dot com
2024-09-19 16:48 ` fweimer at redhat dot com
2024-09-19 19:12 ` matthewkenigsberg at gmail dot com

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).