[PATCH v5 12/16] riscv/cfi: Store shadow stack information in TLS

Gabriel Ravier gabravier@gmail.com
Sun Sep 13 22:37:52 GMT 2026


On 6/28/26 9:02 AM, Jesse Huang wrote:
> Switching between different ucontexts involves two cases.  One case is
> when both contexts share the same shadow stack, which requires unwinding.
> The other is when each context uses a different shadow stack, which
> requires a stack switch using a shadow stack restore token.
>
> By storing the shadow stack base in TLS and comparing it to the value
> stored in the context, we can tell the difference and perform the right
> action.
> ---
>   sysdeps/riscv/nptl/Makefile        | 1 +
>   sysdeps/riscv/nptl/tcb-offsets.sym | 5 +++++
>   sysdeps/riscv/nptl/tls.h           | 2 ++
>   3 files changed, 8 insertions(+)
>   create mode 100644 sysdeps/riscv/nptl/Makefile
>   create mode 100644 sysdeps/riscv/nptl/tcb-offsets.sym
>
> [snip]
> --- a/sysdeps/riscv/nptl/tls.h
> +++ b/sysdeps/riscv/nptl/tls.h
> @@ -44,6 +44,8 @@ typedef struct
>   {
>     dtv_t *dtv;
>     void *private;
> +  /* The marker for the current shadow stack.  */
> +  unsigned long long int ssp_base;
>   } tcbhead_t;
>   
>   /* This is the size of the initial TCB.  Because our TCB is before the thread


Intuitively I'd have thought ssp_base should be uintptr_t...



More information about the Libc-alpha mailing list