linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: fix warning about swapper_pg_dir overflow
@ 2017-02-14 21:27 Arnd Bergmann
  2017-02-14 21:33 ` Ard Biesheuvel
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Arnd Bergmann @ 2017-02-14 21:27 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon
  Cc: Arnd Bergmann, Ard Biesheuvel, Mark Rutland, Laura Abbott,
	Kefeng Wang, linux-arm-kernel, linux-kernel

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] arm64: fix warning about swapper_pg_dir overflow
  2017-02-14 21:27 [PATCH] arm64: fix warning about swapper_pg_dir overflow Arnd Bergmann
@ 2017-02-14 21:33 ` Ard Biesheuvel
  2017-02-14 22:06   ` Arnd Bergmann
  2017-02-15 10:56 ` Mark Rutland
  2017-02-15 11:33 ` Will Deacon
  2 siblings, 1 reply; 5+ messages in thread
From: Ard Biesheuvel @ 2017-02-14 21:33 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Catalin Marinas, Will Deacon, Mark Rutland, Laura Abbott,
	Kefeng Wang, linux-arm-kernel, linux-kernel

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
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] arm64: fix warning about swapper_pg_dir overflow
  2017-02-14 21:33 ` Ard Biesheuvel
@ 2017-02-14 22:06   ` Arnd Bergmann
  0 siblings, 0 replies; 5+ messages in thread
From: Arnd Bergmann @ 2017-02-14 22:06 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: Catalin Marinas, Will Deacon, Mark Rutland, Laura Abbott,
	Kefeng Wang, linux-arm-kernel, linux-kernel

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] arm64: fix warning about swapper_pg_dir overflow
  2017-02-14 21:27 [PATCH] arm64: fix warning about swapper_pg_dir overflow Arnd Bergmann
  2017-02-14 21:33 ` Ard Biesheuvel
@ 2017-02-15 10:56 ` Mark Rutland
  2017-02-15 11:33 ` Will Deacon
  2 siblings, 0 replies; 5+ messages in thread
From: Mark Rutland @ 2017-02-15 10:56 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Catalin Marinas, Will Deacon, Ard Biesheuvel, Laura Abbott,
	Kefeng Wang, linux-arm-kernel, linux-kernel, nd

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.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Acked-by: Mark Rutland <mark.rutland@arm.com>

Thanks,
Mark.

> ---
>  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
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] arm64: fix warning about swapper_pg_dir overflow
  2017-02-14 21:27 [PATCH] arm64: fix warning about swapper_pg_dir overflow Arnd Bergmann
  2017-02-14 21:33 ` Ard Biesheuvel
  2017-02-15 10:56 ` Mark Rutland
@ 2017-02-15 11:33 ` Will Deacon
  2 siblings, 0 replies; 5+ messages in thread
From: Will Deacon @ 2017-02-15 11:33 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Catalin Marinas, Ard Biesheuvel, Mark Rutland, Laura Abbott,
	Kefeng Wang, linux-arm-kernel, linux-kernel

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-02-15 11:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-14 21:27 [PATCH] arm64: fix warning about swapper_pg_dir overflow Arnd Bergmann
2017-02-14 21:33 ` Ard Biesheuvel
2017-02-14 22:06   ` Arnd Bergmann
2017-02-15 10:56 ` Mark Rutland
2017-02-15 11:33 ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).