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

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Thu Sep 4 13:40:55 GMT 2025



On 04/09/25 10:24, Yury Khrustalev wrote:
> On Wed, Sep 03, 2025 at 04:46:47PM -0300, Adhemerval Zanella Netto wrote:
>>
>> On 01/09/25 07:36, Yury Khrustalev wrote:
>>> On Tue, Aug 26, 2025 at 04:07:25PM -0300, Adhemerval Zanella Netto wrote:
>>>>
>>>> On 07/07/25 09:47, Yury Khrustalev wrote:
>>>>> Includes aarch64 GCS support code, does not include x86 shstk
>>>>> support (should be similar to the aarch64 case).
>>>>  
>>>>> diff --git a/nptl/descr.h b/nptl/descr.h
>>>>> index ada6867a19..733e7b0ce6 100644
>>>>> --- a/nptl/descr.h
>>>>> +++ b/nptl/descr.h
>>>>> @@ -384,6 +384,13 @@ struct pthread
>>>>>    /* This is what the user specified and what we will report.  */
>>>>>    size_t reported_guardsize;
>>>>>  
>>>>> +  /* Shadow stack base pointer.  */
>>>>> +  void *shadow_stack_base;
>>>>> +  /* Shadow stack architecture-defined token.  */
>>>>> +  void *shadow_stack_token;
>>>>
>>>> Isn't the shadow_stack_token derived from 'shadow_stack_base + shadow_stack_size - (2 * sizeof(void *)',
>>>> since we allocate it with SHADOW_STACK_SET_TOKEN | SHADOW_STACK_SET_MARKER?
>>>
>>> The token is derived in a target-specific way. In general, we need all 3
>>> things at once: base and size for allocation / deallocation and token
>>> for target-specific operations on shadow stacks.
>>
>> My question is whether we need to save the 'shadow_stack_token' if we can
>> derive its address from shadow_stack_base itself.  It can be a arch-specific
>> function if required.
> 
> We can calculate token based on base and size on aarch64. Are sure that
> this will be the case for all platforms? And if not, would it be easy to
> add token back?

I would expect x86 to follow aarch64 w.r.t to map_shadow_stack flags handling,
but it seems that this part is really arch-specific.  So maybe it would be good
to keep shadow_stack_token for now.


More information about the Libc-alpha mailing list