mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Sean Christopherson <sean.j.christopherson@intel.com>,
	linux-kernel@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org
Subject: Re: [PATCH] x86/pkeys: Explicitly treat PK #PF on kernel address as a bad area
Date: Tue, 7 Aug 2018 11:28:58 -0700	[thread overview]
Message-ID: <b7fe6fad-7ce4-c7c1-31d7-cb609cf45b2f@intel.com> (raw)
In-Reply-To: <20180807172920.8766-1-sean.j.christopherson@intel.com>

On 08/07/2018 10:29 AM, Sean Christopherson wrote:
>  	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;

I just realized one more thing: the vsyscall page can bite us here.
It's at a fault_in_kernel_space() address and we *can* trigger a pkey
fault on it if we jump to an instruction that reads from a
pkey-protected area.

We can make a gadget out of unaligned vsyscall instructions that does
that.  See:

0xffffffffff600002:  shlb   $0x0,0x0(%rax)

Then, we turn off access to all pkeys, including pkey-0, then jump to
the unaligned vsyscall instruction, which reads %rax, which is a kernel
address:

        asm("movl $0xffffffff, %eax;\
             movl $0x00000000, %ecx;\
             movl $0x00000000, %edx;\
             wrpkru;\
             movq $0xffffffffff600000, %rax;\
             movq $0xffffffffff600002, %rbx;\
             jmpq *%rbx;");

So, my bad.  It was not a good suggestion to do a WARN_ON().  But, the
other funny thing is I would have expected spurious_fault() to get us
into a fault loop, which it doesn't.  It's definitely getting *called*
with my little test program (I see it in ftrace) but it's not quite
doing what I expect.

I need to dig a bit more.

  reply	other threads:[~2018-08-07 18:29 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 [this message]
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
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=b7fe6fad-7ce4-c7c1-31d7-cb609cf45b2f@intel.com \
    --to=dave.hansen@intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.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®