From: Sean Christopherson <sean.j.christopherson@intel.com>
To: linux-kernel@vger.kernel.org
Cc: Dave Hansen <dave.hansen@intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, Andy Lutomirski <luto@kernel.org>,
Jann Horn <jannh@google.com>
Subject: Re: [PATCH] x86/pkeys: Explicitly treat PK #PF on kernel address as a bad area
Date: Tue, 4 Sep 2018 12:50:30 -0700 [thread overview]
Message-ID: <20180904195030.GA6269@linux.intel.com> (raw)
In-Reply-To: <20180807172920.8766-1-sean.j.christopherson@intel.com>
Cc-ing Jann and Andy.
On Tue, Aug 07, 2018 at 10:29:20AM -0700, Sean Christopherson wrote:
> Kernel addresses are always mapped with _PAGE_USER=0, i.e. PKRU
> isn't enforced, and so we should never see X86_PF_PK set on a
> kernel address fault. WARN once to capture the issue in case we
> somehow don't die, e.g. the access originated in userspace.
>
> Remove a similar check and its comment from spurious_fault_check().
> The intent of the comment (and later code[1]) was simply to document
> that spurious faults due to protection keys should be impossible, but
> that's irrelevant and a bit of a red herring since we should never
> get a protection keys fault on a kernel address regardless of the
> kernel's TLB flushing behavior.
>
> [1] http://lists-archives.com/linux-kernel/28407455-x86-pkeys-new-page-fault-error-code-bit-pf_pk.html
>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> Cc: Dave Hansen <dave.hansen@intel.com>
> ---
> There's no indication that this condition has ever been encountered.
> I came across the code in spurious_fault_check() and was confused as
> to why we would unconditionally treat a protection keys fault as
> spurious when the comment explicitly stated that such a case should
> be impossible.
>
> Dave Hansen suggested adding a WARN_ON_ONCE in spurious_fault_check(),
> but it seemed more appropriate to freak out on any protection keys
> fault on a kernel address since that would imply a hardware issue or
> kernel bug. I omitted a Suggested-by since this isn't necessarily
> what Dave had in mind.
>
> arch/x86/mm/fault.c | 16 ++++++++++------
> 1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
> index 2aafa6ab6103..f19a55972136 100644
> --- a/arch/x86/mm/fault.c
> +++ b/arch/x86/mm/fault.c
> @@ -1040,12 +1040,6 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
>
> if ((error_code & X86_PF_INSTR) && !pte_exec(*pte))
> return 0;
> - /*
> - * Note: We do not do lazy flushing on protection key
> - * changes, so no spurious fault will ever set X86_PF_PK.
> - */
> - if ((error_code & X86_PF_PK))
> - return 1;
>
> return 1;
> }
> @@ -1241,6 +1235,14 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
> * protection error (error_code & 9) == 0.
> */
> if (unlikely(fault_in_kernel_space(address))) {
> + /*
> + * We should never encounter a protection keys fault on a
> + * kernel address as kernel address are always mapped with
> + * _PAGE_USER=0, i.e. PKRU isn't enforced.
> + */
> + if (WARN_ON_ONCE(error_code & X86_PF_PK))
> + goto bad_kernel_address;
> +
> if (!(error_code & (X86_PF_RSVD | X86_PF_USER | X86_PF_PROT))) {
> if (vmalloc_fault(address) >= 0)
> return;
> @@ -1253,6 +1255,8 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
> /* kprobes don't want to hook the spurious faults: */
> if (kprobes_fault(regs))
> return;
> +
> +bad_kernel_address:
> /*
> * Don't take the mm semaphore here. If we fixup a prefetch
> * fault we could otherwise deadlock:
> --
> 2.18.0
>
next prev parent reply other threads:[~2018-09-04 19:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-07 17:29 [PATCH] x86/pkeys: Explicitly treat PK #PF on kernel address as a bad area Sean Christopherson
2018-08-07 18:28 ` Dave Hansen
2018-08-30 10:40 ` Thomas Gleixner
2018-08-30 23:33 ` Dave Hansen
2018-08-31 2:38 ` Jann Horn
2018-08-31 3:08 ` Andy Lutomirski
2018-09-04 19:50 ` Sean Christopherson [this message]
2018-09-04 19:56 ` Andy Lutomirski
2018-09-04 21:21 ` Dave Hansen
2018-09-04 21:27 ` Andy Lutomirski
2018-09-05 21:35 ` Dave Hansen
2018-09-05 21:39 ` Andy Lutomirski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180904195030.GA6269@linux.intel.com \
--to=sean.j.christopherson@intel.com \
--cc=dave.hansen@intel.com \
--cc=hpa@zytor.com \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).