Skip to contentSkip to conversation

arm64: fix warning about swapper_pg_dir overflow

PATCH In review Arnd Bergmann 4 participants 5 messages Feb 14, 2017 – Feb 15, 2017 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: fix warning about swapper_pg_dir overflow

With 4 levels of 16KB pages, we get this warning about the fact that we are copying a whole page into an array that is declared as having only two pointers for the top level of the page table:

arch/arm64/mm/mmu.c: In function 'paging_init':
arch/arm64/mm/mmu.c:528:2: error: 'memcpy' writing 16384 bytes into a region of size 16 overflows the destination [-Werror=stringop-overflow=]

This is harmless since we actually reserve a whole page in the definition of the array that comes from, and just the extern declaration is short. The pgdir is initialized to zero either way, so copying the actual entries here seems like the best solution.

---
 arch/arm64/mm/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/mmu.c +1 -1
index 2131521ddc24..b805c017f789 100644
@@ -525,7 +525,7 @@ void __init paging_init(void)
 	 * To do this we need to go via a temporary pgd.
 	 */
 	cpu_replace_ttbr1(__va(pgd_phys));
-	memcpy(swapper_pg_dir, pgd, PAGE_SIZE);
+	memcpy(swapper_pg_dir, pgd, PGD_SIZE);
 	cpu_replace_ttbr1(lm_alias(swapper_pg_dir));
 
 	pgd_clear_fixmap();
Signature · 1 line
2.9.0
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Arnd Bergmann

With 4 levels of 16KB pages, we get this warning about the fact that we are copying a whole page into an array that is declared as having only two pointers for the top level of the page table:

arch/arm64/mm/mmu.c: In function 'paging_init':
arch/arm64/mm/mmu.c:528:2: error: 'memcpy' writing 16384 bytes into a region of size 16 overflows the destination [-Werror=stringop-overflow=]

Quoted 6 lines

This is harmless since we actually reserve a whole page in the definition of the array that comes from, and just the extern declaration is short. The pgdir is initialized to zero either way, so copying the actual entries here seems like the best solution.

We should see the same issue with 64k/3 levels, since its PGD_SIZE is also much smaller than its PAGE_SIZE. This is a much more common configuration, so I am surprised you found it on 16k/4 levels first.

In any case, the fix is correct IMO, so

Quoted 20 lines
---
 arch/arm64/mm/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/mmu.c +1 -2
index 2131521ddc24..b805c017f789 100644
@@ -525,7 +525,7 @@ void __init paging_init(void)
         * To do this we need to go via a temporary pgd.
         */
        cpu_replace_ttbr1(__va(pgd_phys));
-       memcpy(swapper_pg_dir, pgd, PAGE_SIZE);
+       memcpy(swapper_pg_dir, pgd, PGD_SIZE);
        cpu_replace_ttbr1(lm_alias(swapper_pg_dir));
 
        pgd_clear_fixmap();
--

2.9.0

#2 lore raw
Quoted 5 lines · Ard Biesheuvel

On 14 February 2017 at 21:27, Arnd Bergmann <[email protected]> wrote:

We should see the same issue with 64k/3 levels, since its PGD_SIZE is also much smaller than its PAGE_SIZE. This is a much more common configuration, so I am surprised you found it on 16k/4 levels first.

I hadn't been doing regular build tests on arm64 and just started up some randconfig builds, this was the first bug I ran into ;-)

Quoted 1 line

Thanks,

Arnd

reviewer Acked-by on v1 1/1
#3 lore raw
In reply to Arnd Bergmann
Quoted 7 lines · Arnd Bergmann

With 4 levels of 16KB pages, we get this warning about the fact that we are copying a whole page into an array that is declared as having only two pointers for the top level of the page table:

arch/arm64/mm/mmu.c: In function 'paging_init':
arch/arm64/mm/mmu.c:528:2: error: 'memcpy' writing 16384 bytes into a region of size 16 overflows the destination [-Werror=stringop-overflow=]

Quoted 6 lines

This is harmless since we actually reserve a whole page in the definition of the array that comes from, and just the extern declaration is short. The pgdir is initialized to zero either way, so copying the actual entries here seems like the best solution.

Thanks,
Mark.

Quoted 20 lines
---
 arch/arm64/mm/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/mmu.c +1 -1
index 2131521ddc24..b805c017f789 100644
@@ -525,7 +525,7 @@ void __init paging_init(void)
 	 * To do this we need to go via a temporary pgd.
 	 */
 	cpu_replace_ttbr1(__va(pgd_phys));
-	memcpy(swapper_pg_dir, pgd, PAGE_SIZE);
+	memcpy(swapper_pg_dir, pgd, PGD_SIZE);
 	cpu_replace_ttbr1(lm_alias(swapper_pg_dir));
 
 	pgd_clear_fixmap();
Signature · 1 line
2.9.0
#4 lore raw
In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann

With 4 levels of 16KB pages, we get this warning about the fact that we are copying a whole page into an array that is declared as having only two pointers for the top level of the page table:

arch/arm64/mm/mmu.c: In function 'paging_init':
arch/arm64/mm/mmu.c:528:2: error: 'memcpy' writing 16384 bytes into a region of size 16 overflows the destination [-Werror=stringop-overflow=]

This is harmless since we actually reserve a whole page in the definition of the array that comes from, and just the extern declaration is short. The pgdir is initialized to zero either way, so copying the actual entries here seems like the best solution.

Thanks, I'll queue this up for 4.11 with the acks.

Will