[PATCH v2 3/3] aarch64: GCS: add clone3 tests for shadow stack

Yury Khrustalev yury.khrustalev@arm.com
Tue Sep 9 12:19:32 GMT 2025


* Adhemerval

On Tue, Aug 26, 2025 at 04:46:01PM -0300, Adhemerval Zanella Netto wrote:
> 
> On 07/07/25 09:47, Yury Khrustalev wrote:
> > If GCS is available check that new thread is created with a
> > shadow stack allocated by Glibc.
> > 
> > Check that shadow stack is de-allocated if a new thread hasn't
> > started or has been cancelled.
> >
> > ...
> >
> > +  pthread_t th;
> > +  if (pthread_create (&th, NULL, fun, NULL) != 0)
> > +    {
> > +      perror ("expected: pthread_create");
> > +      setrlimit (RLIMIT_AS, &prev);
> > +      struct pthread *pd = (struct pthread *)th;
> > +      void *token = pd->shadow_stack_token;
> > +      pthread_join (th, NULL);
> 
> ...
> and I do not think
> we should add a test that rely on an specific implementation detail
> (where pthread_create might return a ligering value in the handler).

This is not why we need this test. This test is an attempt to check
that, when the underlying syscall fails, we deallocate memory for the
shadow stack that we allocate at a point way before making this call.

This test helped find a bug in the original implementation, and I think
we should keep it.

The problem is that the way I simulate the failure of the clone3()
syscall is not very useful (and also not very reliable): I set small
limit on the total memory, so clone3() fails with "Cannot allocate
memory" however before that map_shadow_stack() fails with a similar
result, so shadow stack doesn't get allocated and we can't check if
it would be deallocated or not.

I don't really like fiddling with memory limit here, but I can't think
of another way to simulate clone3() failure while map_shadow_stack()
would be successful. Any advice appreciated.

Thanks,
Yury



More information about the Libc-alpha mailing list