lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180105195535.GZ26807@redhat.com>
Date:   Fri, 5 Jan 2018 20:55:35 +0100
From:   Andrea Arcangeli <aarcange@...hat.com>
To:     Jiri Kosina <jikos@...nel.org>
Cc:     Dave Hansen <dave.hansen@...ux.intel.com>,
        Yisheng Xie <xieyisheng1@...wei.com>,
        linux-kernel@...r.kernel.org, linux-mm@...ck.org,
        richard.fellner@...dent.tugraz.at, moritz.lipp@...k.tugraz.at,
        daniel.gruss@...k.tugraz.at, michael.schwarz@...k.tugraz.at,
        luto@...nel.org, Linus Torvalds <torvalds@...ux-foundation.org>,
        keescook@...gle.com, hughd@...gle.com, x86@...nel.org
Subject: Re: [PATCH 05/23] x86, kaiser: unmap kernel from userspace page
 tables (core patch)

On Fri, Jan 05, 2018 at 08:17:17PM +0100, Jiri Kosina wrote:
> On Fri, 5 Jan 2018, Dave Hansen wrote:
> 
> > > --- a/arch/x86/platform/efi/efi_64.c
> > > +++ b/arch/x86/platform/efi/efi_64.c
> > > @@ -95,6 +95,12 @@ pgd_t * __init efi_call_phys_prolog(void
> > >  		save_pgd[pgd] = *pgd_offset_k(pgd * PGDIR_SIZE);
> > >  		vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
> > >  		set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
> > > +		/*
> > > +		 * pgprot API doesn't clear it for PGD
> > > +		 *
> > > +		 * Will be brought back automatically in _epilog()
> > > +		 */
> > > +		pgd_offset_k(pgd * PGDIR_SIZE)->pgd &= ~_PAGE_NX;
> > >  	}
> > >  	__flush_tlb_all();

Upstream & downstream looks different, how the above looks completely
different I don't know, but I got it and updating is easy. Great
catch.

> > 
> > Wait a sec...  Where does the _PAGE_USER come from?  Shouldn't we see
> > the &init_mm in there and *not* set _PAGE_USER?
> 
> That's because pgd_populate() uses _PAGE_TABLE and not _KERNPG_TABLE for 
> reasons that are behind me.

For vsyscalls? I also had to single out warnings out of init_mm.pgd
for the same reasons.

How does the below (untested) look?

>From ab949b80124588c4791568429cf8a234dda16340 Mon Sep 17 00:00:00 2001
From: Jiri Kosina <jikos@...nel.org>
Date: Fri, 5 Jan 2018 20:00:25 +0100
Subject: [RHEL7.5 PATCH 1/1] x86/kaiser/efi: unbreak EFI old_memmap

old_memmap's efi_call_phys_prolog() calls set_pgd() with swapper PGD that
has PAGE_USER set, which makes PTI set NX on it, and therefore EFI can't
execute it's code.

Fix that by forcefully clearing _PAGE_NX from the PGD (this can't be done
by the pgprot API).

_PAGE_NX will be automatically reintroduced in efi_call_phys_epilog(), as
_set_pgd() will again notice that this is _PAGE_USER, and set _PAGE_NX on
it.

Signed-off-by: Jiri Kosina <jkosina@...e.cz>
Signed-off-by: Andrea Arcangeli <aarcange@...hat.com>
---
 arch/x86/platform/efi/efi_64.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
index f951026ea2d2..395079128d98 100644
--- a/arch/x86/platform/efi/efi_64.c
+++ b/arch/x86/platform/efi/efi_64.c
@@ -110,6 +110,7 @@ void __init efi_call_phys_prelog(void)
 		vaddr = (unsigned long)__va(pgd * PGDIR_SIZE);
 		pgd_efi = pgd_offset_k(addr_pgd);
 		save_pgd[pgd] = *pgd_efi;
+		pgd_efi->pgd &= ~_PAGE_NX;
 
 		pud = pud_alloc(&init_mm, pgd_efi, addr_pgd);
 		if (!pud) {

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ