Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1580874 > unrolled thread

[PATCH] arm64: fix warning about swapper_pg_dir overflow

Started byArnd Bergmann <arnd@arndb.de>
First post2017-02-14 22:30 +0100
Last post2017-02-15 12:40 +0100
Articles 4 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] arm64: fix warning about swapper_pg_dir overflow Arnd Bergmann <arnd@arndb.de> - 2017-02-14 22:30 +0100
    Re: [PATCH] arm64: fix warning about swapper_pg_dir overflow Ard Biesheuvel <ard.biesheuvel@linaro.org> - 2017-02-14 22:40 +0100
      Re: [PATCH] arm64: fix warning about swapper_pg_dir overflow Arnd Bergmann <arnd@arndb.de> - 2017-02-14 23:10 +0100
    Re: [PATCH] arm64: fix warning about swapper_pg_dir overflow Will Deacon <will.deacon@arm.com> - 2017-02-15 12:40 +0100

#1580874 — [PATCH] arm64: fix warning about swapper_pg_dir overflow

FromArnd Bergmann <arnd@arndb.de>
Date2017-02-14 22:30 +0100
Subject[PATCH] arm64: fix warning about swapper_pg_dir overflow
Message-ID<taSPE-72f-17@gated-at.bofh.it>
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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/arm64/mm/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 2131521ddc24..b805c017f789 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -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

[toc] | [next] | [standalone]


#1580883

FromArd Biesheuvel <ard.biesheuvel@linaro.org>
Date2017-02-14 22:40 +0100
Message-ID<taSZk-75C-17@gated-at.bofh.it>
In reply to#1580874
On 14 February 2017 at 21:27, Arnd Bergmann <arnd@arndb.de> wrote:
> 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.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

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

Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> ---
>  arch/arm64/mm/mmu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> index 2131521ddc24..b805c017f789 100644
> --- a/arch/arm64/mm/mmu.c
> +++ b/arch/arm64/mm/mmu.c
> @@ -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
>

[toc] | [prev] | [next] | [standalone]


#1580897

FromArnd Bergmann <arnd@arndb.de>
Date2017-02-14 23:10 +0100
Message-ID<taTsl-7x0-1@gated-at.bofh.it>
In reply to#1580883
On Tue, Feb 14, 2017 at 10:33 PM, Ard Biesheuvel
<ard.biesheuvel@linaro.org> wrote:
> On 14 February 2017 at 21:27, Arnd Bergmann <arnd@arndb.de> 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 ;-)

> Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

Thanks,

   Arnd

[toc] | [prev] | [next] | [standalone]


#1581242

FromWill Deacon <will.deacon@arm.com>
Date2017-02-15 12:40 +0100
Message-ID<tb66e-7Lf-35@gated-at.bofh.it>
In reply to#1580874
On Tue, Feb 14, 2017 at 10:27:01PM +0100, Arnd Bergmann wrote:
> 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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web