Re: [RFC PATCH v2 16/27] mm: Modify can_follow_write_pte/pmd for shadow stack

From: Yu-cheng Yu
Date: Wed Jul 11 2018 - 13:10:44 EST


On Tue, 2018-07-10 at 16:37 -0700, Dave Hansen wrote:
> On 07/10/2018 03:26 PM, Yu-cheng Yu wrote:
> >
> > There are three possible shadow stack PTE settings:
> >
> > Â Normal SHSTK PTE: (R/O + DIRTY_HW)
> > Â SHSTK PTE COW'ed: (R/O + DIRTY_HW)
> > Â SHSTK PTE shared as R/O data: (R/O + DIRTY_SW)
> >
> > Update can_follow_write_pte/pmd for the shadow stack.
> First of all, thanks for the excellent patch headers.ÂÂIt's nice to
> have
> that reference every time even though it's repeated.
>
> >
> > -static inline bool can_follow_write_pte(pte_t pte, unsigned int
> > flags)
> > +static inline bool can_follow_write_pte(pte_t pte, unsigned int
> > flags,
> > + bool shstk)
> > Â{
> > + bool pte_cowed = shstk ? is_shstk_pte(pte):pte_dirty(pte);
> > +
> > Â return pte_write(pte) ||
> > - ((flags & FOLL_FORCE) && (flags & FOLL_COW) &&
> > pte_dirty(pte));
> > + ((flags & FOLL_FORCE) && (flags & FOLL_COW) &&
> > pte_cowed);
> > Â}
> Can we just pass the VMA in here?ÂÂThis use is OK-ish, but I
> generally
> detest true/false function arguments because you can't tell what they
> are when they show up without a named variable.
>
> But...ÂÂWhy does this even matter?ÂÂYour own example showed that all
> shadowstack PTEs have either DIRTY_HW or DIRTY_SW set, and
> pte_dirty()
> checks both.
>
> That makes this check seem a bit superfluous.

My understanding is that we don't want to follow write pte if the page
is shared as read-only. ÂFor a SHSTK page, that is (R/O + DIRTY_SW),
which means the SHSTK page has not been COW'ed. ÂIs that right?

Thanks,
Yu-cheng