From: Dave Hansen <dave.hansen@intel.com>
To: Andy Lutomirski <luto@kernel.org>,
Sean Christopherson <sean.j.christopherson@intel.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
X86 ML <x86@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 14:21:35 -0700 [thread overview]
Message-ID: <8a62de3e-defa-6681-c853-cd5140c5f0b5@intel.com> (raw)
In-Reply-To: <CALCETrU-HXfr_eAfeS1t7JH+-gOh0ZfAoGxjcOckxEX1fN_YDA@mail.gmail.com>
On 09/04/2018 12:56 PM, Andy Lutomirski wrote:
> I have no objection to this patch.
>
> Dave, why did you think that we could get a PK fault on the vsyscall
> page, even on kernels that still marked it executable? Sure, you
> could get an instruction in the vsyscall page to get a PK fault, but
> CR2 wouldn't point to the vsyscall page, right?
I'm inferring the CR2 value from the page fault trace point. I see
entries like this:
protection_keys-4313 [002] d... 420257.094541: page_fault_user:
address=_end ip=_end error_code=0x15
But, that's not a PK fault, and it triggers the "misaligned vsyscall
(exploit attempt or buggy program)" stuff in dmesg. It's just the
symptom of trying to execute the non-executable vsyscall page.
I'm not a super big fan of this particular patch, though. The
fault_in_kernel_space() check is really presuming two things:
1. pkey faults (PF_PK=1) only occur on user pages (_PAGE_USER=1)
2. fault_in_kernel_space()==1 addresses are never user pages
#1 is a hardware expectation. We *can* look for that directly by just
making sure that X86_PF_PK is only set when it also comes with
X86_PF_USER in the hardware page fault error code.
(...
Aside: We should probably explicitly separate out the hardware
error code from the software-munged version, like we do here:
> if (user_mode(regs)) {
> local_irq_enable();
> error_code |= X86_PF_USER)
But, #2 is a bit of a more loose check. It wasn't true for the recent
vsyscall, and I've also seen goofy drivers map memory out to userspace
quite a few times in the kernel address space.
So, I'd much rather see a X86_PF_USER check than a X86_PF_USER check.
But, as for pkeys...
The original intent here was to relay: "protection key faults can never
be spurious". The reason in my silly comment was that we don't do lazy
flushing, but that's imprecise: the real reasoning is that we don't ever
have kernel pages on which we can take protection key faults.
IOW, I think the check here should be for "protection key faults only
occur on user pages", and all the *spurious* checking should be looking
at *just* user vs. kernel pages, like:
static int spurious_fault_check(unsigned long error_code, pte_t *pte)
{
/* Only expect spurious faults on kernel pages: */
WARN_ON_ONCE(pte_flags(*pte) & _PAGE_USER);
/* Only expect spurious faults originating from kernel code: */
WARN_ON_ONCE(error_code & X86_PF_USER);
...
next prev parent reply other threads:[~2018-09-04 21:21 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-07 17:29 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
2018-09-04 19:56 ` Andy Lutomirski
2018-09-04 21:21 ` Dave Hansen [this message]
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=8a62de3e-defa-6681-c853-cd5140c5f0b5@intel.com \
--to=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=sean.j.christopherson@intel.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
all inboxes | Powered by JetHome®