Re: [RFC PATCH v2 18/27] x86/cet/shstk: Introduce WRUSS instruction

From: Yu-cheng Yu
Date: Fri Jul 13 2018 - 13:40:53 EST


On Fri, 2018-07-13 at 05:12 -0700, Dave Hansen wrote:
> On 07/10/2018 03:26 PM, Yu-cheng Yu wrote:
> >
> > +static int is_wruss(struct pt_regs *regs, unsigned long error_code)
> > +{
> > + return (((error_code & (X86_PF_USER | X86_PF_SHSTK)) ==
> > + (X86_PF_USER | X86_PF_SHSTK)) && !user_mode(regs));
> > +}
> > +
> > Âstatic void
> > Âshow_fault_oops(struct pt_regs *regs, unsigned long error_code,
> > Â unsigned long address)
> > @@ -848,7 +859,7 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
> > Â struct task_struct *tsk = current;
> > Â
> > Â /* User mode accesses just cause a SIGSEGV */
> > - if (error_code & X86_PF_USER) {
> > + if ((error_code & X86_PF_USER) && !is_wruss(regs, error_code)) {
> > Â /*
> > Â Â* It's possible to have interrupts off here:
> > Â Â*/
> Please don't do it this way.
>
> We have two styles of page fault:
> 1. User page faults: find a VMA, try to handle (allocate memory et al.),
> ÂÂÂkill process if we can't handle.
> 2. Kernel page faults: search for a *discrete* set of conditions that
> ÂÂÂcan be handled, including faults in instructions marked in exception
> ÂÂÂtables.
>
> X86_PF_USER *means*: do user page fault handling.ÂÂIn the places where
> the hardware doesn't set it, but we still want user page fault handling,
> we manually set it, like this where we "downgrade" an implicit
> supervisor access to a user access:
>
> ÂÂÂÂÂÂÂÂif (user_mode(regs)) {
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂlocal_irq_enable();
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂerror_code |= X86_PF_USER;
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂflags |= FAULT_FLAG_USER;
>
> So, just please *clear* X86_PF_USER if !user_mode(regs) and X86_PF_SS.
> We do not want user page fault handling, thus we should not keep the bit
> set.

Agree. ÂI will change that.

Yu-cheng