Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/KASLR: Initialize mapping_info every time

As it turns out, mapping_info DOES need to be initialized every
time, because pgt_data address could be changed during kernel
relocation. So it can not be build time assigned.

Without this, page tables were not being corrected updated, which
could cause reboots when a physical address beyond 2G was chosen.

Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Baoquan He <bhe@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Borislav Petkov <bp@suse.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: kernel-hardening@lists.openwall.com
Cc: lasse.collin@tukaani.org
Link: http://lkml.kernel.org/r/1462825332-10505-2-git-send-email-keescook@chromium.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Kees Cook and committed by
Ingo Molnar
434a6c9f 36a39ac9

+5 -11
+5 -11
arch/x86/boot/compressed/pagetable.c
··· 90 90 } 91 91 92 92 /* 93 - * Mapping information structure passed to kernel_ident_mapping_init(). 94 - * Since this never changes, there's no reason to repeatedly fill it 95 - * in on the stack when calling add_identity_map(). 96 - */ 97 - static struct x86_mapping_info mapping_info = { 98 - .alloc_pgt_page = alloc_pgt_page, 99 - .context = &pgt_data, 100 - .pmd_flag = __PAGE_KERNEL_LARGE_EXEC, 101 - }; 102 - 103 - /* 104 93 * Adds the specified range to what will become the new identity mappings. 105 94 * Once all ranges have been added, the new mapping is activated by calling 106 95 * finalize_identity_maps() below. 107 96 */ 108 97 void add_identity_map(unsigned long start, unsigned long size) 109 98 { 99 + struct x86_mapping_info mapping_info = { 100 + .alloc_pgt_page = alloc_pgt_page, 101 + .context = &pgt_data, 102 + .pmd_flag = __PAGE_KERNEL_LARGE_EXEC, 103 + }; 110 104 unsigned long end = start + size; 111 105 112 106 /* Make sure we have a top level page table ready to use. */