V2 [PATCH] x86/CET: Add a setcontext test for CET

Carlos O'Donell carlos@redhat.com
Wed Jul 25 15:34:00 GMT 2018


On 07/25/2018 11:01 AM, H.J. Lu wrote:
> On Wed, Jul 25, 2018 at 6:29 AM, Carlos O'Donell <carlos@redhat.com> wrote:
>> On 07/25/2018 08:22 AM, H.J. Lu wrote:
>>> Verify that setcontext works with gaps above and below the newly
>>> allocated shadow stack.
>>>
>>> OK for master?
>>>
>>> H.J.
>>> ---
>>>       * sysdeps/x86/Makefile (tests): Add tst-cet-setcontext-1 if
>>>       CET is enabled.
>>>       (CFLAGS-tst-cet-setcontext-1.c): Add -mshstk.
>>>       * sysdeps/x86/tst-cet-setcontext-1.c: New file.
>>
>> OK for 2.28 only if you add a paragraph about exactly how the shadow
>> stacks are being laid out by the calls and why unmapping ctx3 and ctx4 works
>> to leave ctx1 with gap above and below.
>>
> 
> Here is the updated patch with a comment:
> 
>   /* NB: When shadow stack is enabled, makecontext calls arch_prctl
>      with ARCH_CET_ALLOC_SHSTK to allocate a new shadow stack which
>      can be unmapped.  The base address and size of the new shadow
>      stack are returned in __ssp[1] and __ssp[2].  makecontext is
>      called for CTX1, CTX3 and CTX4.  But only CTX1 is used.  New
>      shadow stacks are allocated in the order of CTX3, CTX1, CTX4.
>      It is very likely that CTX1's shadow stack is placed between
>      CTX3 and CTX4.  We munmap CTX3's and CTX4's shadow stacks to
>      create gaps above and below CTX1's shadow stack.  We check that
>      setcontext CTX1 works correctly in this case.  */

Perfect!

> It is also moved to sysdeps/unix/sysv/linux/x86/tst-cet-setcontext-1.c since
> it is Linux/x86 specific.
> 
> OK for master?

OK for 2.28.

Thanks for the update.

Cheers,
Carlos.



More information about the Libc-alpha mailing list