public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Pavel Tatashin <pasha.tatashin@oracle.com>
Cc: steven.sistare@oracle.com, linux-kernel@vger.kernel.org,
	tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com,
	x86@kernel.org, jkosina@suse.cz, hughd@google.com,
	dave.hansen@linux.intel.com, luto@kernel.org,
	torvalds@linux-foundation.org
Subject: Re: [PATCH 4.4 v2] x86/pti/efi: broken conversion from efi to kernel page table
Date: Sat, 13 Jan 2018 14:53:42 +0100	[thread overview]
Message-ID: <20180113135342.GB28839@kroah.com> (raw)
In-Reply-To: <20180112200002.25907-1-pasha.tatashin@oracle.com>

On Fri, Jan 12, 2018 at 03:00:02PM -0500, Pavel Tatashin wrote:
> In entry_64.S we have code like this:
> 
>     /* Unconditionally use kernel CR3 for do_nmi() */
>     /* %rax is saved above, so OK to clobber here */
>     ALTERNATIVE "jmp 2f", "movq %cr3, %rax", X86_FEATURE_KAISER
>     /* If PCID enabled, NOFLUSH now and NOFLUSH on return */
>     ALTERNATIVE "", "bts $63, %rax", X86_FEATURE_PCID
>     pushq   %rax
>     /* mask off "user" bit of pgd address and 12 PCID bits: */
>     andq    $(~(X86_CR3_PCID_ASID_MASK | KAISER_SHADOW_PGD_OFFSET)), %rax
>     movq    %rax, %cr3
> 2:
> 
>     /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
>     call    do_nmi
> 
> With this instruction:
>     andq    $(~(X86_CR3_PCID_ASID_MASK | KAISER_SHADOW_PGD_OFFSET)), %rax
> 
> We unconditionally switch from whatever our CR3 was to kernel page table.
> But, in arch/x86/platform/efi/efi_64.c We temporarily set a different page
> table, that does not have the kernel page table with 0x1000 offset from it.
> 
> Look in efi_thunk() and efi_thunk_set_virtual_address_map().
> 
> So, while CR3 points to the other page table, we get an NMI interrupt,
> and clear 0x1000 from CR3, resulting in a bogus CR3 if the 0x1000 bit was
> set.
> 
> The efi page table comes from realmode/rm/trampoline_64.S:
> 
> arch/x86/realmode/rm/trampoline_64.S
> 
> 141 .bss
> 142 .balign PAGE_SIZE
> 143 GLOBAL(trampoline_pgd) .space PAGE_SIZE
> 
> Notice: alignment is PAGE_SIZE, so after applying KAISER_SHADOW_PGD_OFFSET
> which equal to PAGE_SIZE, we can get a different page table.
> 
> But, even if we fix alignment, here the trampoline binary is later copied
> into dynamically allocated memory in reserve_real_mode(), so we need to
> fix that place as well.
> 
> Fixes: 8a43ddfb93a0 ("KAISER: Kernel Address Isolation")
> 
> Signed-off-by: Pavel Tatashin <pasha.tatashin@oracle.com>
> Reviewed-by: Steven Sistare <steven.sistare@oracle.com>
> ---
>  arch/x86/include/asm/kaiser.h        | 10 ++++++++++
>  arch/x86/realmode/init.c             |  4 +++-
>  arch/x86/realmode/rm/trampoline_64.S |  3 ++-
>  3 files changed, 15 insertions(+), 2 deletions(-)
> 
> Changelog:
> 	v1 - v2: Fixed compiling issue when PTI config is disabled.

This one is now queued up, thanks.

greg k-h

      reply	other threads:[~2018-01-13 13:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-12 20:00 [PATCH 4.4 v2] x86/pti/efi: broken conversion from efi to kernel page table Pavel Tatashin
2018-01-13 13:53 ` Greg KH [this message]

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=20180113135342.GB28839@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=hughd@google.com \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=pasha.tatashin@oracle.com \
    --cc=steven.sistare@oracle.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --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