[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CALCETrVFQuMcUgfDkREGFHSSF9UW5yy4UuNZSpjw1962eSvLyw@mail.gmail.com>
Date: Sat, 22 Aug 2020 14:59:37 -0700
From: Andy Lutomirski <luto@...nel.org>
To: Peter Zijlstra <peterz@...radead.org>
Cc: LKML <linux-kernel@...r.kernel.org>,
linux-tip-commits@...r.kernel.org,
Andy Lutomirski <luto@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>, x86 <x86@...nel.org>
Subject: Re: [tip: x86/urgent] x86/entry, selftests: Further improve user
entry sanity checks
On Thu, Aug 20, 2020 at 3:24 AM <peterz@...radead.org> wrote:
>
> On Sat, Jul 04, 2020 at 05:49:10PM -0000, tip-bot2 for Andy Lutomirski wrote:
>
> > diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c
> > index f392a8b..e83b3f1 100644
> > --- a/arch/x86/entry/common.c
> > +++ b/arch/x86/entry/common.c
> > @@ -49,6 +49,23 @@
> > static void check_user_regs(struct pt_regs *regs)
> > {
> > if (IS_ENABLED(CONFIG_DEBUG_ENTRY)) {
> > + /*
> > + * Make sure that the entry code gave us a sensible EFLAGS
> > + * register. Native because we want to check the actual CPU
> > + * state, not the interrupt state as imagined by Xen.
> > + */
> > + unsigned long flags = native_save_fl();
> > + WARN_ON_ONCE(flags & (X86_EFLAGS_AC | X86_EFLAGS_DF |
> > + X86_EFLAGS_NT));
>
> This triggers with AC|TF on my !SMAP enabled machine.
>
> something like so then?
>
> diff --git a/arch/x86/include/asm/entry-common.h b/arch/x86/include/asm/entry-common.h
> index a8f9315b9eae..76410964585f 100644
> --- a/arch/x86/include/asm/entry-common.h
> +++ b/arch/x86/include/asm/entry-common.h
> @@ -18,8 +18,15 @@ static __always_inline void arch_check_user_regs(struct pt_regs *regs)
> * state, not the interrupt state as imagined by Xen.
> */
> unsigned long flags = native_save_fl();
> - WARN_ON_ONCE(flags & (X86_EFLAGS_AC | X86_EFLAGS_DF |
> - X86_EFLAGS_NT));
> + unsigned long mask = X86_EFLAGS_DF | X86_EFLAGS_NT;
> +
> + /*
> + * For !SMAP hardware we patch out CLAC on entry.
> + */
> + if (boot_cpu_has(X86_FEATURE_SMAP))
> + mask |= X86_EFLAGS_AC;
> +
> + WARN_ON_ONCE(flags & mask);
>
> /* We think we came from user mode. Make sure pt_regs agrees. */
> WARN_ON_ONCE(!user_mode(regs));
LGTM.
Acked-by: Andy Lutomirski <luto@...nel.org>
Powered by blists - more mailing lists