linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm/kasan:fix the arry size of kasan_early_shadow_pte
@ 2021-01-09  4:46 Hailong liu
  2021-01-09  8:51 ` Ard Biesheuvel
  2021-01-09 21:26 ` Linus Walleij
  0 siblings, 2 replies; 7+ messages in thread
From: Hailong liu @ 2021-01-09  4:46 UTC (permalink / raw)
  To: aryabinin
  Cc: linux, glider, dvyukov, akpm, kasan-dev, linux-arm-kernel,
	linux-mm, linux-kernel, hailongliiu, Hailong Liu, Ziliang Guo

From: Hailong Liu <liu.hailong6@zte.com.cn>

The size of kasan_early_shadow_pte[] now is PTRS_PER_PTE which defined to
512 for arm architecture. This means that it only covers the prev Linux pte
entries, but not the HWTABLE pte entries for arm.

The reason it works well current is that the symbol kasan_early_shadow_page
immediately following kasan_early_shadow_pte in memory is page aligned,
which makes kasan_early_shadow_pte look like a 4KB size array. But we can't
ensure the order always right with different compiler/linker, nor more bss
symbols be introduced.

We had a test with QEMU + vexpress:put a 512KB-size symbol with attribute
__section(".bss..page_aligned") after kasan_early_shadow_pte, and poison it
after kasan_early_init(). Then enabled CONFIG_KASAN, it failed to boot up.

Signed-off-by: Hailong Liu <liu.hailong6@zte.com.cn>
Signed-off-by: Ziliang Guo <guo.ziliang@zte.com.cn>
---
 include/linux/kasan.h | 6 +++++-
 mm/kasan/init.c       | 3 ++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/linux/kasan.h b/include/linux/kasan.h
index 5e0655fb2a6f..fe1ae73ff8b5 100644
--- a/include/linux/kasan.h
+++ b/include/linux/kasan.h
@@ -35,8 +35,12 @@ struct kunit_kasan_expectation {
 #define KASAN_SHADOW_INIT 0
 #endif
 
+#ifndef PTE_HWTABLE_PTRS
+#define PTE_HWTABLE_PTRS 0
+#endif
+
 extern unsigned char kasan_early_shadow_page[PAGE_SIZE];
-extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE];
+extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE + PTE_HWTABLE_PTRS];
 extern pmd_t kasan_early_shadow_pmd[PTRS_PER_PMD];
 extern pud_t kasan_early_shadow_pud[PTRS_PER_PUD];
 extern p4d_t kasan_early_shadow_p4d[MAX_PTRS_PER_P4D];
diff --git a/mm/kasan/init.c b/mm/kasan/init.c
index bc0ad208b3a7..7ca0b92d5886 100644
--- a/mm/kasan/init.c
+++ b/mm/kasan/init.c
@@ -64,7 +64,8 @@ static inline bool kasan_pmd_table(pud_t pud)
 	return false;
 }
 #endif
-pte_t kasan_early_shadow_pte[PTRS_PER_PTE] __page_aligned_bss;
+pte_t kasan_early_shadow_pte[PTRS_PER_PTE + PTE_HWTABLE_PTRS]
+	__page_aligned_bss;
 
 static inline bool kasan_pte_table(pmd_t pmd)
 {
-- 
2.17.1



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

* Re: [PATCH] arm/kasan:fix the arry size of kasan_early_shadow_pte
  2021-01-09  4:46 [PATCH] arm/kasan:fix the arry size of kasan_early_shadow_pte Hailong liu
@ 2021-01-09  8:51 ` Ard Biesheuvel
  2021-01-09 21:26 ` Linus Walleij
  1 sibling, 0 replies; 7+ messages in thread
From: Ard Biesheuvel @ 2021-01-09  8:51 UTC (permalink / raw)
  To: Hailong liu, Linus Walleij
  Cc: Andrey Ryabinin, Ziliang Guo, Hailong Liu, kasan-dev,
	Linux Kernel Mailing List, Linux Memory Management List,
	Alexander Potapenko, Dmitry Vyukov, Andrew Morton, Linux ARM,
	Russell King

(+ Linus)

On Sat, 9 Jan 2021 at 05:50, Hailong liu <hailongliiu@yeah.net> wrote:
>
> From: Hailong Liu <liu.hailong6@zte.com.cn>
>
> The size of kasan_early_shadow_pte[] now is PTRS_PER_PTE which defined to
> 512 for arm architecture. This means that it only covers the prev Linux pte
> entries, but not the HWTABLE pte entries for arm.
>
> The reason it works well current is that the symbol kasan_early_shadow_page
> immediately following kasan_early_shadow_pte in memory is page aligned,
> which makes kasan_early_shadow_pte look like a 4KB size array. But we can't
> ensure the order always right with different compiler/linker, nor more bss
> symbols be introduced.
>
> We had a test with QEMU + vexpress:put a 512KB-size symbol with attribute
> __section(".bss..page_aligned") after kasan_early_shadow_pte, and poison it
> after kasan_early_init(). Then enabled CONFIG_KASAN, it failed to boot up.
>
> Signed-off-by: Hailong Liu <liu.hailong6@zte.com.cn>
> Signed-off-by: Ziliang Guo <guo.ziliang@zte.com.cn>
> ---
>  include/linux/kasan.h | 6 +++++-
>  mm/kasan/init.c       | 3 ++-
>  2 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/kasan.h b/include/linux/kasan.h
> index 5e0655fb2a6f..fe1ae73ff8b5 100644
> --- a/include/linux/kasan.h
> +++ b/include/linux/kasan.h
> @@ -35,8 +35,12 @@ struct kunit_kasan_expectation {
>  #define KASAN_SHADOW_INIT 0
>  #endif
>
> +#ifndef PTE_HWTABLE_PTRS
> +#define PTE_HWTABLE_PTRS 0
> +#endif
> +
>  extern unsigned char kasan_early_shadow_page[PAGE_SIZE];
> -extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE];
> +extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE + PTE_HWTABLE_PTRS];
>  extern pmd_t kasan_early_shadow_pmd[PTRS_PER_PMD];
>  extern pud_t kasan_early_shadow_pud[PTRS_PER_PUD];
>  extern p4d_t kasan_early_shadow_p4d[MAX_PTRS_PER_P4D];
> diff --git a/mm/kasan/init.c b/mm/kasan/init.c
> index bc0ad208b3a7..7ca0b92d5886 100644
> --- a/mm/kasan/init.c
> +++ b/mm/kasan/init.c
> @@ -64,7 +64,8 @@ static inline bool kasan_pmd_table(pud_t pud)
>         return false;
>  }
>  #endif
> -pte_t kasan_early_shadow_pte[PTRS_PER_PTE] __page_aligned_bss;
> +pte_t kasan_early_shadow_pte[PTRS_PER_PTE + PTE_HWTABLE_PTRS]
> +       __page_aligned_bss;
>
>  static inline bool kasan_pte_table(pmd_t pmd)
>  {
> --
> 2.17.1
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel


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

* Re: [PATCH] arm/kasan:fix the arry size of kasan_early_shadow_pte
  2021-01-09  4:46 [PATCH] arm/kasan:fix the arry size of kasan_early_shadow_pte Hailong liu
  2021-01-09  8:51 ` Ard Biesheuvel
@ 2021-01-09 21:26 ` Linus Walleij
  2021-01-10 10:20   ` hailong
  1 sibling, 1 reply; 7+ messages in thread
From: Linus Walleij @ 2021-01-09 21:26 UTC (permalink / raw)
  To: Hailong liu
  Cc: Andrey Ryabinin, Ziliang Guo, Hailong Liu, Russell King,
	kasan-dev, linux-kernel, Linux Memory Management List,
	Alexander Potapenko, Dmitry Vyukov, Andrew Morton, Linux ARM

On Sat, Jan 9, 2021 at 5:51 AM Hailong liu <hailongliiu@yeah.net> wrote:

> From: Hailong Liu <liu.hailong6@zte.com.cn>
>
> The size of kasan_early_shadow_pte[] now is PTRS_PER_PTE which defined to
> 512 for arm architecture. This means that it only covers the prev Linux pte
> entries, but not the HWTABLE pte entries for arm.
>
> The reason it works well current is that the symbol kasan_early_shadow_page
> immediately following kasan_early_shadow_pte in memory is page aligned,
> which makes kasan_early_shadow_pte look like a 4KB size array. But we can't
> ensure the order always right with different compiler/linker, nor more bss
> symbols be introduced.
>
> We had a test with QEMU + vexpress:put a 512KB-size symbol with attribute
> __section(".bss..page_aligned") after kasan_early_shadow_pte, and poison it
> after kasan_early_init(). Then enabled CONFIG_KASAN, it failed to boot up.
>
> Signed-off-by: Hailong Liu <liu.hailong6@zte.com.cn>
> Signed-off-by: Ziliang Guo <guo.ziliang@zte.com.cn>

OK I see the problem, I think.

> +#ifndef PTE_HWTABLE_PTRS
> +#define PTE_HWTABLE_PTRS 0
> +#endif

Can this even happen? We have either pgtable-2level.h or
pgtable-3level.h, both of which define PTE_HWTABLE_PTRS.

>  extern unsigned char kasan_early_shadow_page[PAGE_SIZE];
> -extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE];
> +extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE + PTE_HWTABLE_PTRS];

Yeah this looks exactly like bm_pte so it makes sense.

If you drop the first ifndef,
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij


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

* Re:Re: [PATCH] arm/kasan:fix the arry size of kasan_early_shadow_pte
  2021-01-09 21:26 ` Linus Walleij
@ 2021-01-10 10:20   ` hailong
  2021-01-10 12:03     ` Linus Walleij
  0 siblings, 1 reply; 7+ messages in thread
From: hailong @ 2021-01-10 10:20 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andrey Ryabinin, Ziliang Guo, Hailong Liu, Russell King,
	kasan-dev, linux-kernel, Linux Memory Management List,
	Alexander Potapenko, Dmitry Vyukov, Andrew Morton, Linux ARM

[-- Attachment #1: Type: text/plain, Size: 1886 bytes --]


At 2021-01-10 05:26:08, "Linus Walleij" <linus.walleij@linaro.org> wrote:
>On Sat, Jan 9, 2021 at 5:51 AM Hailong liu <hailongliiu@yeah.net> wrote:
>
>> From: Hailong Liu <liu.hailong6@zte.com.cn>
>>
>> The size of kasan_early_shadow_pte[] now is PTRS_PER_PTE which defined to
>> 512 for arm architecture. This means that it only covers the prev Linux pte
>> entries, but not the HWTABLE pte entries for arm.
>>
>> The reason it works well current is that the symbol kasan_early_shadow_page
>> immediately following kasan_early_shadow_pte in memory is page aligned,
>> which makes kasan_early_shadow_pte look like a 4KB size array. But we can't
>> ensure the order always right with different compiler/linker, nor more bss
>> symbols be introduced.
>>
>> We had a test with QEMU + vexpress:put a 512KB-size symbol with attribute
>> __section(".bss..page_aligned") after kasan_early_shadow_pte, and poison it
>> after kasan_early_init(). Then enabled CONFIG_KASAN, it failed to boot up.
>>
>> Signed-off-by: Hailong Liu <liu.hailong6@zte.com.cn>
>> Signed-off-by: Ziliang Guo <guo.ziliang@zte.com.cn>
>
>OK I see the problem, I think.
>
>> +#ifndef PTE_HWTABLE_PTRS
>> +#define PTE_HWTABLE_PTRS 0
>> +#endif
>
>Can this even happen? We have either pgtable-2level.h or
>pgtable-3level.h, both of which define PTE_HWTABLE_PTRS.
>

I guess not for arm. But I'm not sure for other ARCHs.

>>  extern unsigned char kasan_early_shadow_page[PAGE_SIZE];
>> -extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE];
>> +extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE + PTE_HWTABLE_PTRS];
>
>Yeah this looks exactly like bm_pte so it makes sense.
>

Yes, it comes from prototype of pm_pte. And it does solve the
problems our project encountered and seems to work well for now.

>If you drop the first ifndef,
>Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
>
>Yours,
>Linus Walleij

Thanks.

[-- Attachment #2: Type: text/html, Size: 2278 bytes --]

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

* Re: Re: [PATCH] arm/kasan:fix the arry size of kasan_early_shadow_pte
  2021-01-10 10:20   ` hailong
@ 2021-01-10 12:03     ` Linus Walleij
  2021-01-12  6:18       ` Andrew Morton
  0 siblings, 1 reply; 7+ messages in thread
From: Linus Walleij @ 2021-01-10 12:03 UTC (permalink / raw)
  To: hailong
  Cc: Andrey Ryabinin, Ziliang Guo, Hailong Liu, Russell King,
	kasan-dev, linux-kernel, Linux Memory Management List,
	Alexander Potapenko, Dmitry Vyukov, Andrew Morton, Linux ARM

On Sun, Jan 10, 2021 at 11:21 AM hailong <hailongliiu@yeah.net> wrote:

> >> +#ifndef PTE_HWTABLE_PTRS
> >> +#define PTE_HWTABLE_PTRS 0
> >> +#endif
> >
> >Can this even happen? We have either pgtable-2level.h or
> >pgtable-3level.h, both of which define PTE_HWTABLE_PTRS.
> >
>
> I guess not for arm. But I'm not sure for other ARCHs.

Oh it's a generic include. Sorry for the confusion.

All good then!

Yours,
Linus Walleij


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

* Re: [PATCH] arm/kasan:fix the arry size of kasan_early_shadow_pte
  2021-01-10 12:03     ` Linus Walleij
@ 2021-01-12  6:18       ` Andrew Morton
  2021-01-12  9:05         ` Ard Biesheuvel
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2021-01-12  6:18 UTC (permalink / raw)
  To: Linus Walleij
  Cc: hailong, Andrey Ryabinin, Ziliang Guo, Hailong Liu, Russell King,
	kasan-dev, linux-kernel, Linux Memory Management List,
	Alexander Potapenko, Dmitry Vyukov, Linux ARM

On Sun, 10 Jan 2021 13:03:49 +0100 Linus Walleij <linus.walleij@linaro.org> wrote:

> On Sun, Jan 10, 2021 at 11:21 AM hailong <hailongliiu@yeah.net> wrote:
> 
> > >> +#ifndef PTE_HWTABLE_PTRS
> > >> +#define PTE_HWTABLE_PTRS 0
> > >> +#endif
> > >
> > >Can this even happen? We have either pgtable-2level.h or
> > >pgtable-3level.h, both of which define PTE_HWTABLE_PTRS.
> > >
> >
> > I guess not for arm. But I'm not sure for other ARCHs.
> 
> Oh it's a generic include. Sorry for the confusion.
> 
> All good then!
> 

This code is 2+ years old.  Do we think it warrants a cc:stable?


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

* Re: [PATCH] arm/kasan:fix the arry size of kasan_early_shadow_pte
  2021-01-12  6:18       ` Andrew Morton
@ 2021-01-12  9:05         ` Ard Biesheuvel
  0 siblings, 0 replies; 7+ messages in thread
From: Ard Biesheuvel @ 2021-01-12  9:05 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Linus Walleij, Ziliang Guo, linux-kernel, Hailong Liu,
	Russell King, kasan-dev, hailong, Linux Memory Management List,
	Alexander Potapenko, Linux ARM, Andrey Ryabinin, Dmitry Vyukov

On Tue, 12 Jan 2021 at 07:19, Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Sun, 10 Jan 2021 13:03:49 +0100 Linus Walleij <linus.walleij@linaro.org> wrote:
>
> > On Sun, Jan 10, 2021 at 11:21 AM hailong <hailongliiu@yeah.net> wrote:
> >
> > > >> +#ifndef PTE_HWTABLE_PTRS
> > > >> +#define PTE_HWTABLE_PTRS 0
> > > >> +#endif
> > > >
> > > >Can this even happen? We have either pgtable-2level.h or
> > > >pgtable-3level.h, both of which define PTE_HWTABLE_PTRS.
> > > >
> > >
> > > I guess not for arm. But I'm not sure for other ARCHs.
> >
> > Oh it's a generic include. Sorry for the confusion.
> >
> > All good then!
> >
>
> This code is 2+ years old.  Do we think it warrants a cc:stable?
>

Not needed - ARM only gained Kasan support this cycle, and this patch
does not affect any other architectures


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

end of thread, other threads:[~2021-01-12  9:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-09  4:46 [PATCH] arm/kasan:fix the arry size of kasan_early_shadow_pte Hailong liu
2021-01-09  8:51 ` Ard Biesheuvel
2021-01-09 21:26 ` Linus Walleij
2021-01-10 10:20   ` hailong
2021-01-10 12:03     ` Linus Walleij
2021-01-12  6:18       ` Andrew Morton
2021-01-12  9:05         ` Ard Biesheuvel

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