Re: [NEEDS-REVIEW] Re: [PATCH v11 25/25] x86/cet/shstk: Add arch_prctl functions for shadow stack

From: Andy Lutomirski
Date: Mon Sep 14 2020 - 14:31:41 EST


> On Sep 14, 2020, at 7:50 AM, Dave Hansen <dave.hansen@xxxxxxxxx> wrote:
>
> On 9/11/20 3:59 PM, Yu-cheng Yu wrote:
> ...
>> Here are the changes if we take the mprotect(PROT_SHSTK) approach.
>> Any comments/suggestions?
>
> I still don't like it. :)
>
> I'll also be much happier when there's a proper changelog to accompany
> this which also spells out the alternatives any why they suck so much.
>

Let’s take a step back here. Ignoring the precise API, what exactly is
a shadow stack from the perspective of a Linux user program?

The simplest answer is that it’s just memory that happens to have
certain protections. This enables all kinds of shenanigans. A
program could map a memfd twice, once as shadow stack and once as
non-shadow-stack, and change its control flow. Similarly, a program
could mprotect its shadow stack, modify it, and mprotect it back. In
some threat models, though could be seen as a WRSS bypass. (Although
if an attacker can coerce a process to call mprotect(), the game is
likely mostly over anyway.)

But we could be more restrictive, or perhaps we could allow user code
to opt into more restrictions. For example, we could have shadow
stacks be special memory that cannot be written from usermode by any
means other than ptrace() and friends, WRSS, and actual shadow stack
usage.

What is the goal?

No matter what we do, the effects of calling vfork() are going to be a
bit odd with SHSTK enabled. I suppose we could disallow this, but
that seems likely to cause its own issues.