armv8: mmu: Detect page table overflow in emergency pt creation
authorAlexander Graf <agraf@suse.de>
Sat, 30 Jul 2016 21:13:03 +0000 (23:13 +0200)
committerTom Rini <trini@konsulko.com>
Sat, 6 Aug 2016 00:55:18 +0000 (20:55 -0400)
We create 2 sets of page tables: One for normal operation, one for
emergency (used while modifying the former).

Because the page tables grow dynamically, we have code that checks
for overflow. Unfortunately we didn't adjust the available space
variable while creating the emergency tables, so potentially someone
might run into an overflow there (not seen in real world yet though!).

Fix it by properly adjusting the size as well as the base offset in
emergency page table creation.

Reported-by: York Sun <york.sun@nxp.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
Reviewed-by: York Sun <york.sun@nxp.com>
arch/arm/cpu/armv8/cache_v8.c

index ac909a15ffaa6974c2c633a2e73bd00a62c6d41d..cd3f6c10ae1286c93dc93881c40064ab2ae8bcae 100644 (file)
@@ -380,6 +380,7 @@ void setup_pgtables(void)
 static void setup_all_pgtables(void)
 {
        u64 tlb_addr = gd->arch.tlb_addr;
+       u64 tlb_size = gd->arch.tlb_size;
 
        /* Reset the fill ptr */
        gd->arch.tlb_fillptr = tlb_addr;
@@ -388,10 +389,13 @@ static void setup_all_pgtables(void)
        setup_pgtables();
 
        /* Create emergency page tables */
+       gd->arch.tlb_size -= (uintptr_t)gd->arch.tlb_fillptr -
+                            (uintptr_t)gd->arch.tlb_addr;
        gd->arch.tlb_addr = gd->arch.tlb_fillptr;
        setup_pgtables();
        gd->arch.tlb_emerg = gd->arch.tlb_addr;
        gd->arch.tlb_addr = tlb_addr;
+       gd->arch.tlb_size = tlb_size;
 }
 
 /* to activate the MMU we need to set up virtual memory */