[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87frdoybk4.ffs@tglx>
Date: Mon, 18 Aug 2025 16:00:27 +0200
From: Thomas Gleixner <tglx@...utronix.de>
To: Jens Axboe <axboe@...nel.dk>, LKML <linux-kernel@...r.kernel.org>
Cc: Michael Jeanson <mjeanson@...icios.com>, Mathieu Desnoyers
<mathieu.desnoyers@...icios.com>, Peter Zijlstra <peterz@...radead.org>,
"Paul E. McKenney" <paulmck@...nel.org>, Boqun Feng
<boqun.feng@...il.com>, Wei Liu <wei.liu@...nel.org>, Sean Christopherson
<seanjc@...gle.com>, Florian Weimer <fweimer@...hat.com>, Samuel Thibault
<sthibault@...ian.org>
Subject: BUG: rseq selftests and librseq vs. glibc fail
On Sun, Aug 17 2025 at 23:23, Thomas Gleixner wrote:
> It survives the self test suite after I wasted a day to figure out why
> the selftests reliably segfault on a machine which has debian trixie
> installed. The fix is in the branch.
That's glibc 2.41 FWIW. glibc 2.36 from Debian 12 does not have this
problem.
The fix unfortunately only works with a dynamically linked libc,
statically linked libc fails. The fix is basically a revert of
3bcbc20942db ("selftests/rseq: Play nice with binaries statically linked
against glibc 2.35+")
which introduced these weak libc symbols to make static libc linking work.
I have no idea why this creates havoc, but in GDB I saw that libc
manages to overwrite the TLS of the pthread at some place, but I gave up
decoding it further. If no pthread is created it just works. Removing
this weak muck makes it work too.
It's trivial to reproduce. All it needs is to have in the source:
__weak ptrdiff_t __rseq_offset;
w/o even being referenced and creating a pthread. Reproducer below.
TBH, this interface is a horrible hack. libc should expose a proper
function for querying whether it has registered rseq and return the
parameters in a struct. But well...
Build reproducer with:
# gcc -O2 -Wall -o t test.c
# ./t
Segmentation fault
# gcc -O2 -Wall -o t test.c -static
# ./t
#
Removing the weak __rseq_offset makes the dynamic case work too.
Yours sufficiently grumpy
tglx
----
#define _GNU_SOURCE
#include <pthread.h>
#include <stddef.h>
#define __weak __attribute__((__weak__))
__weak ptrdiff_t __rseq_offset;
static void *foo(void *arg)
{
return NULL;
}
int main(int argc, char **argv)
{
pthread_t t;
pthread_create(&t, NULL, foo, NULL);
pthread_join(t, NULL);
return 0;
}
Powered by blists - more mailing lists