Skip to content

Commit b234e8a

Browse files
thgarnieIngo Molnar
authored andcommitted
x86/mm: Separate variable for trampoline PGD
Use a separate global variable to define the trampoline PGD used to start other processors. This change will allow KALSR memory randomization to change the trampoline PGD to be correctly aligned with physical memory. Signed-off-by: Thomas Garnier <thgarnie@google.com> Signed-off-by: Kees Cook <keescook@chromium.org> Cc: Alexander Kuleshov <kuleshovmail@gmail.com> Cc: Alexander Popov <alpopov@ptsecurity.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Cc: Baoquan He <bhe@redhat.com> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Borislav Petkov <bp@suse.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Christian Borntraeger <borntraeger@de.ibm.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Dave Young <dyoung@redhat.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Jan Beulich <JBeulich@suse.com> Cc: Joerg Roedel <jroedel@suse.de> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Juergen Gross <jgross@suse.com> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Lv Zheng <lv.zheng@intel.com> Cc: Mark Salter <msalter@redhat.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Matt Fleming <matt@codeblueprint.co.uk> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephen Smalley <sds@tycho.nsa.gov> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Toshi Kani <toshi.kani@hpe.com> Cc: Xiao Guangrong <guangrong.xiao@linux.intel.com> Cc: Yinghai Lu <yinghai@kernel.org> Cc: kernel-hardening@lists.openwall.com Cc: linux-doc@vger.kernel.org Link: http://lkml.kernel.org/r/1466556426-32664-5-git-send-email-keescook@chromium.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent faa3793 commit b234e8a

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

arch/x86/include/asm/pgtable.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,18 @@ extern int direct_gbpages;
729729
void init_mem_mapping(void);
730730
void early_alloc_pgt_buf(void);
731731

732+
#ifdef CONFIG_X86_64
733+
/* Realmode trampoline initialization. */
734+
extern pgd_t trampoline_pgd_entry;
735+
static inline void __meminit init_trampoline(void)
736+
{
737+
/* Default trampoline pgd value */
738+
trampoline_pgd_entry = init_level4_pgt[pgd_index(__PAGE_OFFSET)];
739+
}
740+
#else
741+
static inline void init_trampoline(void) { }
742+
#endif
743+
732744
/* local pte updates need not use xchg for locking */
733745
static inline pte_t native_local_ptep_get_and_clear(pte_t *ptep)
734746
{

arch/x86/mm/init.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,9 @@ void __init init_mem_mapping(void)
590590
/* the ISA range is always mapped regardless of memory holes */
591591
init_memory_mapping(0, ISA_END_ADDRESS);
592592

593+
/* Init the trampoline, possibly with KASLR memory offset */
594+
init_trampoline();
595+
593596
/*
594597
* If the allocation is in bottom-up direction, we setup direct mapping
595598
* in bottom-up, otherwise we setup direct mapping in top-down.

arch/x86/realmode/init.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
struct real_mode_header *real_mode_header;
99
u32 *trampoline_cr4_features;
1010

11+
/* Hold the pgd entry used on booting additional CPUs */
12+
pgd_t trampoline_pgd_entry;
13+
1114
void __init reserve_real_mode(void)
1215
{
1316
phys_addr_t mem;
@@ -84,7 +87,7 @@ void __init setup_real_mode(void)
8487
*trampoline_cr4_features = __read_cr4();
8588

8689
trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
87-
trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
90+
trampoline_pgd[0] = trampoline_pgd_entry.pgd;
8891
trampoline_pgd[511] = init_level4_pgt[511].pgd;
8992
#endif
9093
}

0 commit comments

Comments
 (0)