[PATCH v2 2/3] nptl: Add libc allocated shadow stack for new threads

Mark Brown broonie@kernel.org
Mon Sep 8 18:41:14 GMT 2025


On Mon, Sep 08, 2025 at 02:14:34PM +0200, Florian Weimer wrote:
> * Florian Weimer:

> > Not sure if it helps, but glibc always calls the exit system call from
> > the start routine, after unwinding the stack (with longjmp if
> > necessary).  So the regular stack is always the same as the original
> > stack.  Due to the unwinding, the shadow stack does not necessarily have
> > to be the same because we never return from a frame that already existed
> > when pthread_exit/pthread_cancel were called.  On the other hand, we use
> > a generic mechanism (either setjmp or DWARF unwinding) which supports
> > that.  I expect that either approach will switch back the shadow stack
> > to its original value, too.

> Correction: on x86-64, we do not switch shadow stacks for some
> complicated reason, but we could restore it before we make the exit
> system call (from the function that is called from clone).  Restoring on
> intermediate frames is tricky (almost impossible).

I wonder if we could do something like write a cap token to the GCS when
threads exit.  That would enable reuse, especially for something like
you describe above where you're going to be at the original entry point.
It would I think need to be unconditional though, but any user who
doesn't want to reuse would presumably be deallocating pretty quickly so
perhaps that's fine.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20250908/73f0bffd/attachment-0001.sig>


More information about the Libc-alpha mailing list