x86/kasan: Fix KASAN shadow region page tables
Currently KASAN shadow region page tables created without respect of physical offset (phys_base). This causes kernel halt when phys_base is not zero. So let's initialize KASAN shadow region page tables in kasan_early_init() using __pa_nodebug() which considers phys_base. This patch also separates x86_64_start_kernel() from KASAN low level details by moving kasan_map_early_shadow(init_level4_pgt) into kasan_early_init(). Remove the comment before clear_bss() which stopped bringing much profit to the code readability. Otherwise describing all the new order dependencies would be too verbose. Signed-off-by: Alexander Popov <alpopov@ptsecurity.com> Signed-off-by: Andrey Ryabinin <a.ryabinin@samsung.com> Cc: <stable@vger.kernel.org> # 4.0+ Cc: Alexander Potapenko <glider@google.com> Cc: Andrey Konovalov <adech.fo@gmail.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/1435828178-10975-3-git-send-email-a.ryabinin@samsung.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:

committed by
Ingo Molnar

parent
d0f77d4d04
commit
5d5aa3cfca
@@ -11,7 +11,19 @@
|
||||
extern pgd_t early_level4_pgt[PTRS_PER_PGD];
|
||||
extern struct range pfn_mapped[E820_X_MAX];
|
||||
|
||||
extern unsigned char kasan_zero_page[PAGE_SIZE];
|
||||
static pud_t kasan_zero_pud[PTRS_PER_PUD] __page_aligned_bss;
|
||||
static pmd_t kasan_zero_pmd[PTRS_PER_PMD] __page_aligned_bss;
|
||||
static pte_t kasan_zero_pte[PTRS_PER_PTE] __page_aligned_bss;
|
||||
|
||||
/*
|
||||
* This page used as early shadow. We don't use empty_zero_page
|
||||
* at early stages, stack instrumentation could write some garbage
|
||||
* to this page.
|
||||
* Latter we reuse it as zero shadow for large ranges of memory
|
||||
* that allowed to access, but not instrumented by kasan
|
||||
* (vmalloc/vmemmap ...).
|
||||
*/
|
||||
static unsigned char kasan_zero_page[PAGE_SIZE] __page_aligned_bss;
|
||||
|
||||
static int __init map_range(struct range *range)
|
||||
{
|
||||
@@ -36,7 +48,7 @@ static void __init clear_pgds(unsigned long start,
|
||||
pgd_clear(pgd_offset_k(start));
|
||||
}
|
||||
|
||||
void __init kasan_map_early_shadow(pgd_t *pgd)
|
||||
static void __init kasan_map_early_shadow(pgd_t *pgd)
|
||||
{
|
||||
int i;
|
||||
unsigned long start = KASAN_SHADOW_START;
|
||||
@@ -166,6 +178,26 @@ static struct notifier_block kasan_die_notifier = {
|
||||
};
|
||||
#endif
|
||||
|
||||
void __init kasan_early_init(void)
|
||||
{
|
||||
int i;
|
||||
pteval_t pte_val = __pa_nodebug(kasan_zero_page) | __PAGE_KERNEL;
|
||||
pmdval_t pmd_val = __pa_nodebug(kasan_zero_pte) | _KERNPG_TABLE;
|
||||
pudval_t pud_val = __pa_nodebug(kasan_zero_pmd) | _KERNPG_TABLE;
|
||||
|
||||
for (i = 0; i < PTRS_PER_PTE; i++)
|
||||
kasan_zero_pte[i] = __pte(pte_val);
|
||||
|
||||
for (i = 0; i < PTRS_PER_PMD; i++)
|
||||
kasan_zero_pmd[i] = __pmd(pmd_val);
|
||||
|
||||
for (i = 0; i < PTRS_PER_PUD; i++)
|
||||
kasan_zero_pud[i] = __pud(pud_val);
|
||||
|
||||
kasan_map_early_shadow(early_level4_pgt);
|
||||
kasan_map_early_shadow(init_level4_pgt);
|
||||
}
|
||||
|
||||
void __init kasan_init(void)
|
||||
{
|
||||
int i;
|
||||
|
Reference in New Issue
Block a user