Re: [PATCH v2 10/39] x86/mm: Introduce _PAGE_COW

From: Edgecombe, Rick P
Date: Mon Oct 03 2022 - 18:20:53 EST


On Mon, 2022-10-03 at 23:54 +0200, Jann Horn wrote:
> > > These X86_FEATURE_SHSTK checks make me uneasy. Maybe use the
> > > _PAGE_COW
> > > logic for all machines with 64-bit entries. It will get you much
> > > more
> > > coverage and more universal rules.
> >
> > Yes, I didn't like them either at first. The reasoning originally
> > was
> > that _PAGE_COW is a bit more work and it might show up for some
> > benchmark.
> >
> > Looking at this again though, it is just a few more operations on
> > memory that is already getting touched either way. It must be a
> > very
> > tiny amount of impact if any. I'm fine removing them. Having just
> > one
> > set of logic around this would make it easier to reason about.
> >
> > Dave, any thoughts on this?
>
> But the rules wouldn't actually be universal - you'd still have to
> look at X86_FEATURE_SHSTK in code that wants to figure out whether a
> PTE is shadow stack (on a newer CPU) or readonly dirty (on an older
> CPU that can set dirty bits on non-present PTEs), right?

Good point. It still would need a check in pte_shstk() or pte_write(),
so pte_write() doesn't think CPU created Write=0,Dirty=1 memory is
writable. Which then percolates to most of the other checks anyway.