arm64: kasan: support CONFIG_KASAN_VMALLOC
Subsystems (4)
v2 cover arm64: kasan: support CONFIG_KASAN_VMALLOC
Linux supports KAsan for VMALLOC since commit 3c5c3cfb9ef4da9 ("kasan: support backing vmalloc space with real shadow memory")
Acroding to how x86 ported it [1], they early allocated p4d and pgd, but in arm64 I just simulate how KAsan supports MODULES_VADDR in arm64 by not to populate the vmalloc area except for kimg address.
Test environment:
4G and 8G Qemu virt,
39-bit VA + 4k PAGE_SIZE with 3-level page table, test by lib/test_kasan.ko and lib/test_kasan_module.ko
It also works in Kaslr with CONFIG_RANDOMIZE_MODULE_REGION_FULL and randomize module region inside vmalloc area.
[1]: commit 0609ae011deb41c ("x86/kasan: support KASAN_VMALLOC")
v2 -> v1
1. kasan_init.c tweak indent
2. change Kconfig depends only on HAVE_ARCH_KASAN
3. support randomized module region.
v1:
https://lore.kernel.org/lkml/[email protected]/
Lecopzer Chen (4):
arm64: kasan: don't populate vmalloc area for CONFIG_KASAN_VMALLOC
arm64: kasan: abstract _text and _end to KERNEL_START/END
arm64: Kconfig: support CONFIG_KASAN_VMALLOC
arm64: kaslr: support randomized module area with KASAN_VMALLOC
arch/arm64/Kconfig | 1 + arch/arm64/kernel/kaslr.c | 18 ++++++++++-------- arch/arm64/kernel/module.c | 16 +++++++++------- arch/arm64/mm/kasan_init.c | 29 +++++++++++++++++++++-------- 4 files changed, 41 insertions(+), 23 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/4 arm64: kasan: don't populate vmalloc area for CONFIG_KASAN_VMALLOC
Linux support KAsan for VMALLOC since commit 3c5c3cfb9ef4da9 ("kasan: support backing vmalloc space with real shadow memory")
Like how the MODULES_VADDR does now, just not to early populate the VMALLOC_START between VMALLOC_END.
similarly, the kernel code mapping is now in the VMALLOC area and should keep these area populated.
--- arch/arm64/mm/kasan_init.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
arch/arm64/mm/kasan_init.c +18 -5
@@ -214,6 +214,7 @@ static void __init kasan_init_shadow(void) {u64 kimg_shadow_start, kimg_shadow_end;u64 mod_shadow_start, mod_shadow_end; +u64 vmalloc_shadow_start, vmalloc_shadow_end;phys_addr_t pa_start, pa_end;u64 i;
@@ -223,6 +224,9 @@ static void __init kasan_init_shadow(void) mod_shadow_start = (u64 )kasan_mem_to_shadow ((void *)MODULES_VADDR ); mod_shadow_end = (u64 )kasan_mem_to_shadow ((void *)MODULES_END ); + vmalloc_shadow_start = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_START ); + vmalloc_shadow_end = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_END ); +/* * We are going to perform proper setup of shadow memory. * At first we should unmap early shadow (clear_pgds() call below).
@@ -241,12 +245,21 @@ static void __init kasan_init_shadow(void)kasan_populate_early_shadow (kasan_mem_to_shadow ((void *)PAGE_END ), (void *)mod_shadow_start); -kasan_populate_early_shadow ((void *)kimg_shadow_end, - (void *)KASAN_SHADOW_END ); +if (IS_ENABLED (CONFIG_KASAN_VMALLOC )) { +kasan_populate_early_shadow ((void *)vmalloc_shadow_end, + (void *)KASAN_SHADOW_END ); +if (vmalloc_shadow_start > mod_shadow_end) +kasan_populate_early_shadow ((void *)mod_shadow_end, + (void *)vmalloc_shadow_start); + + }else { +kasan_populate_early_shadow ((void *)kimg_shadow_end, + (void *)KASAN_SHADOW_END ); +if (kimg_shadow_start > mod_shadow_end) +kasan_populate_early_shadow ((void *)mod_shadow_end, + (void *)kimg_shadow_start); + } -if (kimg_shadow_start > mod_shadow_end) -kasan_populate_early_shadow ((void *)mod_shadow_end, - (void *)kimg_shadow_start);for_each_mem_range (i, &pa_start, &pa_end) {void *start = (void *)__phys_to_virt (pa_start);
Signature · 1 line
2.25.1
Re: [PATCH v2 1/4] arm64: kasan: don't populate vmalloc area for CONFIG_KASAN_VMALLOC
Quoted 10 lines · Lecopzer Chen
Linux support KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Like how the
MODULES_VADDRdoes now, just not to early populate theVMALLOC_STARTbetweenVMALLOC_END.
similarly, the kernel code mapping is now in the VMALLOC area and should keep these area populated.Signed-off-by Lecopzer Chen <[email protected]>
This commit log text is a bit hard to follow. You are saying that the vmalloc region is *not* backed with zero shadow or any default mapping at all, right, and everything gets allocated on demand, just like is the case for modules?
Quoted 17 lines
--- arch/arm64/mm/kasan_init.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)arch/arm64/mm/kasan_init.c +1
-0@@ -214,6 +214,7 @@ static void __init kasan_init_shadow(void) {u64 kimg_shadow_start, kimg_shadow_end;u64 mod_shadow_start, mod_shadow_end; +u64 vmalloc_shadow_start, vmalloc_shadow_end;phys_addr_t pa_start, pa_end;u64 i;
arch/arm64/mm/kasan_init.c static void __init kasan_init_shadow(void) · line 229
Quoted 6 lines
arch/arm64/mm/kasan_init.c +3
-0@@ -223,6 +224,9 @@ static void __init kasan_init_shadow(void) mod_shadow_start = (u64 )kasan_mem_to_shadow ((void *)MODULES_VADDR ); mod_shadow_end = (u64 )kasan_mem_to_shadow ((void *)MODULES_END ); + vmalloc_shadow_start = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_START ); + vmalloc_shadow_end = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_END ); +
This and the below seems overly complicated, given that VMALLOC_START == MODULES_END. Can we simplify this?
Quoted 33 lines
arch/arm64/mm/kasan_init.c +14
-6/* * We are going to perform proper setup of shadow memory. * At first we should unmap early shadow (clear_pgds() call below). @@ -241,12 +245,21 @@ static void __init kasan_init_shadow(void)kasan_populate_early_shadow (kasan_mem_to_shadow ((void *)PAGE_END ), (void *)mod_shadow_start); -kasan_populate_early_shadow ((void *)kimg_shadow_end, - (void *)KASAN_SHADOW_END ); +if (IS_ENABLED (CONFIG_KASAN_VMALLOC )) { +kasan_populate_early_shadow ((void *)vmalloc_shadow_end, + (void *)KASAN_SHADOW_END ); +if (vmalloc_shadow_start > mod_shadow_end) +kasan_populate_early_shadow ((void *)mod_shadow_end, + (void *)vmalloc_shadow_start); + + }else { +kasan_populate_early_shadow ((void *)kimg_shadow_end, + (void *)KASAN_SHADOW_END ); +if (kimg_shadow_start > mod_shadow_end) +kasan_populate_early_shadow ((void *)mod_shadow_end, + (void *)kimg_shadow_start); + } -if (kimg_shadow_start > mod_shadow_end) -kasan_populate_early_shadow ((void *)mod_shadow_end, - (void *)kimg_shadow_start);for_each_mem_range (i, &pa_start, &pa_end) {void *start = (void *)__phys_to_virt (pa_start); --2.25.1
Re: [PATCH v2 1/4] arm64: kasan: don't populate vmalloc area for CONFIG_KASAN_VMALLOC
Quoted 10 lines · Lecopzer Chen
Quoted 9 lines
Linux support KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Like how the
MODULES_VADDRdoes now, just not to early populate theVMALLOC_STARTbetweenVMALLOC_END.
similarly, the kernel code mapping is now in the VMALLOC area and should keep these area populated.
Quoted 7 lines
Quoted 1 line
Signed-off-by Lecopzer Chen <[email protected]>This commit log text is a bit hard to follow. You are saying that the vmalloc region is *not* backed with zero shadow or any default mapping at all, right, and everything gets allocated on demand, just like is the case for modules?
It's much more like:
before:
MODULE_VADDR: no mapping, no zoreo shadow at initVMALLOC_VADDR: backed with zero shadow at init
after:
MODULE_VADDR: no mapping, no zoreo shadow at initVMALLOC_VADDR: no mapping, no zoreo shadow at init
So it should be both "not backed with zero shadow" and "not any mapping and everything gets allocated on demand".
And the "not backed with zero shadow" is like a subset of "not any mapping ...".
Is that being more clear if the commit revises to:
----------------------
Like how the MODULES_VADDR does now, just not to early populate the VMALLOC_START between VMALLOC_END.
Before:
MODULE_VADDR: no mapping, no zoreo shadow at initVMALLOC_VADDR: backed with zero shadow at init
After:
VMALLOC_VADDR: no mapping, no zoreo shadow at init
Thus the mapping will get allocate on demand by the core function of KASAN vmalloc.
similarly, the kernel code mapping is now in the VMALLOC area and should keep these area populated.
--------------------
Or would you have any suggestion?
Thanks a lot for your review!
BRs,
Lecopzer
Will Deacon
maintainerRe: [PATCH v2 1/4] arm64: kasan: don't populate vmalloc area for CONFIG_KASAN_VMALLOC
In reply to Lecopzer ChenQuoted 36 lines · Lecopzer Chen
Linux support KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Like how the
MODULES_VADDRdoes now, just not to early populate theVMALLOC_STARTbetweenVMALLOC_END.
similarly, the kernel code mapping is now in the VMALLOC area and should keep these area populated.Signed-off-by Lecopzer Chen <[email protected]>--- arch/arm64/mm/kasan_init.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)arch/arm64/mm/kasan_init.c +4
-0@@ -214,6 +214,7 @@ static void __init kasan_init_shadow(void) {u64 kimg_shadow_start, kimg_shadow_end;u64 mod_shadow_start, mod_shadow_end; +u64 vmalloc_shadow_start, vmalloc_shadow_end;phys_addr_t pa_start, pa_end;u64 i;@@ -223,6 +224,9 @@ static void __init kasan_init_shadow(void) mod_shadow_start = (u64 )kasan_mem_to_shadow ((void *)MODULES_VADDR ); mod_shadow_end = (u64 )kasan_mem_to_shadow ((void *)MODULES_END ); + vmalloc_shadow_start = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_START ); + vmalloc_shadow_end = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_END ); +/* * We are going to perform proper setup of shadow memory. * At first we should unmap early shadow (clear_pgds() call below).
arch/arm64/mm/kasan_init.c static void __init kasan_init_shadow(void) · line 248
Quoted 6 lines
arch/arm64/mm/kasan_init.c +1
-2@@ -241,12 +245,21 @@ static void __init kasan_init_shadow(void)kasan_populate_early_shadow (kasan_mem_to_shadow ((void *)PAGE_END ), (void *)mod_shadow_start); -kasan_populate_early_shadow ((void *)kimg_shadow_end, - (void *)KASAN_SHADOW_END ); +if (IS_ENABLED (CONFIG_KASAN_VMALLOC )) {
Do we really need yet another CONFIG option for KASAN? What's the use-case for *not* enabling this if you're already enabling one of the KASAN backends?
arch/arm64/mm/kasan_init.c static void __init kasan_init_shadow(void) · line 251
Quoted 3 lines
arch/arm64/mm/kasan_init.c +3
-0+kasan_populate_early_shadow ((void *)vmalloc_shadow_end, + (void *)KASAN_SHADOW_END ); +if (vmalloc_shadow_start > mod_shadow_end)
To echo Ard's concern: when is the above 'if' condition true?
Will
Re: [PATCH v2 1/4] arm64: kasan: don't populate vmalloc area for CONFIG_KASAN_VMALLOC
Quoted 38 lines · Lecopzer Chen
Quoted 37 lines
Linux support KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Like how the
MODULES_VADDRdoes now, just not to early populate theVMALLOC_STARTbetweenVMALLOC_END.
similarly, the kernel code mapping is now in the VMALLOC area and should keep these area populated.Signed-off-by Lecopzer Chen <[email protected]>--- arch/arm64/mm/kasan_init.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)arch/arm64/mm/kasan_init.c +4
-0@@ -214,6 +214,7 @@ static void __init kasan_init_shadow(void) {u64 kimg_shadow_start, kimg_shadow_end;u64 mod_shadow_start, mod_shadow_end; +u64 vmalloc_shadow_start, vmalloc_shadow_end;phys_addr_t pa_start, pa_end;u64 i;@@ -223,6 +224,9 @@ static void __init kasan_init_shadow(void) mod_shadow_start = (u64 )kasan_mem_to_shadow ((void *)MODULES_VADDR ); mod_shadow_end = (u64 )kasan_mem_to_shadow ((void *)MODULES_END ); + vmalloc_shadow_start = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_START ); + vmalloc_shadow_end = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_END ); +/* * We are going to perform proper setup of shadow memory. * At first we should unmap early shadow (clear_pgds() call below). @@ -241,12 +245,21 @@ static void __init kasan_init_shadow(void)
Quoted 9 lines
arch/arm64/mm/kasan_init.c static void __init kasan_init_shadow(void) · line 248
Quoted 5 lines
arch/arm64/mm/kasan_init.c +1
-2kasan_populate_early_shadow (kasan_mem_to_shadow ((void *)PAGE_END ), (void *)mod_shadow_start); -kasan_populate_early_shadow ((void *)kimg_shadow_end, - (void *)KASAN_SHADOW_END ); +if (IS_ENABLED (CONFIG_KASAN_VMALLOC )) {Do we really need yet another CONFIG option for KASAN? What's the use-case for *not* enabling this if you're already enabling one of the KASAN backends?
As I know, KASAN_VMALLOC now only supports KASAN_GENERIC and also KASAN_VMALLOC uses more memory to map real shadow memory (1/8 of vmalloc va).
There should be someone can enable KASAN_GENERIC but can't use VMALLOC due to memory issue.
Quoted 5 lines
arch/arm64/mm/kasan_init.c static void __init kasan_init_shadow(void) · line 251
Quoted 3 lines
arch/arm64/mm/kasan_init.c +3
-0+kasan_populate_early_shadow ((void *)vmalloc_shadow_end, + (void *)KASAN_SHADOW_END ); +if (vmalloc_shadow_start > mod_shadow_end)To echo Ard's concern: when is the above 'if' condition true?
After reviewing this code,
since VMALLOC_STAR is a compiler defined macro of MODULES_END, this if-condition will never be true.
I also test it with removing this and works fine.
I'll remove this in the next version patch,
thanks a lot for pointing out this.
BRs,
Lecopzer
Will Deacon
maintainerRe: [PATCH v2 1/4] arm64: kasan: don't populate vmalloc area for CONFIG_KASAN_VMALLOC
Quoted 48 lines · Lecopzer Chen
Quoted 38 lines · Lecopzer Chen
Quoted 37 lines
Linux support KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Like how the
MODULES_VADDRdoes now, just not to early populate theVMALLOC_STARTbetweenVMALLOC_END.
similarly, the kernel code mapping is now in the VMALLOC area and should keep these area populated.Signed-off-by Lecopzer Chen <[email protected]>--- arch/arm64/mm/kasan_init.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)arch/arm64/mm/kasan_init.c +4
-0@@ -214,6 +214,7 @@ static void __init kasan_init_shadow(void) {u64 kimg_shadow_start, kimg_shadow_end;u64 mod_shadow_start, mod_shadow_end; +u64 vmalloc_shadow_start, vmalloc_shadow_end;phys_addr_t pa_start, pa_end;u64 i;@@ -223,6 +224,9 @@ static void __init kasan_init_shadow(void) mod_shadow_start = (u64 )kasan_mem_to_shadow ((void *)MODULES_VADDR ); mod_shadow_end = (u64 )kasan_mem_to_shadow ((void *)MODULES_END ); + vmalloc_shadow_start = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_START ); + vmalloc_shadow_end = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_END ); +/* * We are going to perform proper setup of shadow memory. * At first we should unmap early shadow (clear_pgds() call below). @@ -241,12 +245,21 @@ static void __init kasan_init_shadow(void)Quoted 9 lines
arch/arm64/mm/kasan_init.c static void __init kasan_init_shadow(void) · line 248
Quoted 5 lines
arch/arm64/mm/kasan_init.c +1
-2kasan_populate_early_shadow (kasan_mem_to_shadow ((void *)PAGE_END ), (void *)mod_shadow_start); -kasan_populate_early_shadow ((void *)kimg_shadow_end, - (void *)KASAN_SHADOW_END ); +if (IS_ENABLED (CONFIG_KASAN_VMALLOC )) {Do we really need yet another CONFIG option for KASAN? What's the use-case for *not* enabling this if you're already enabling one of the KASAN backends?
Quoted 2 lines
As I know,
KASAN_VMALLOCnow only supportsKASAN_GENERICand alsoKASAN_VMALLOCuses more memory to map real shadow memory (1/8 of vmalloc va).
The shadow is allocated dynamically though, isn't it?
Quoted 2 lines
There should be someone can enable
KASAN_GENERICbut can't use VMALLOC due to memory issue.
That doesn't sound particularly realistic to me. The reason I'm pushing here is because I would _really_ like to move to VMAP stack unconditionally, and that would effectively force KASAN_VMALLOC to be set if KASAN is in use.
So unless there's a really good reason not to do that, please can we make this unconditional for arm64? Pretty please?
Will
Re: [PATCH v2 1/4] arm64: kasan: don't populate vmalloc area for CONFIG_KASAN_VMALLOC
Quoted 50 lines · Lecopzer Chen
Quoted 48 lines
Quoted 47 lines · Lecopzer Chen
Quoted 36 lines
Linux support KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Like how the
MODULES_VADDRdoes now, just not to early populate theVMALLOC_STARTbetweenVMALLOC_END.
similarly, the kernel code mapping is now in the VMALLOC area and should keep these area populated.Signed-off-by Lecopzer Chen <[email protected]>---
arch/arm64/mm/kasan_init.c | 23 ++++++++++++++++++-----1 file changed, 18 insertions(+), 5 deletions(-)arch/arm64/mm/kasan_init.c +4
-0@@ -214,6 +214,7 @@ static void __init kasan_init_shadow(void) { u64 kimg_shadow_start, kimg_shadow_end; u64 mod_shadow_start, mod_shadow_end; +u64 vmalloc_shadow_start, vmalloc_shadow_end; phys_addr_t pa_start, pa_end; u64 i;@@ -223,6 +224,9 @@ static void __init kasan_init_shadow(void) mod_shadow_start = (u64)kasan_mem_to_shadow((void *)MODULES_VADDR); mod_shadow_end = (u64)kasan_mem_to_shadow((void *)MODULES_END); + vmalloc_shadow_start = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_START ); + vmalloc_shadow_end = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_END ); + /** We are going to perform proper setup of shadow memory. * At first we should unmap early shadow (clear_pgds() call below). arch/arm64/mm/kasan_init.c static void __init kasan_init_shadow(void) · line 248
Quoted 6 lines
arch/arm64/mm/kasan_init.c +1
-2@@ -241,12 +245,21 @@ static void __init kasan_init_shadow(void) kasan_populate_early_shadow(kasan_mem_to_shadow((void *)PAGE_END), (void *)mod_shadow_start); -kasan_populate_early_shadow ((void *)kimg_shadow_end, - (void *)KASAN_SHADOW_END); +if (IS_ENABLED (CONFIG_KASAN_VMALLOC )) {Do we really need yet another CONFIG option for KASAN? What's the use-case for *not* enabling this if you're already enabling one of the KASAN backends?
Quoted 4 lines
Quoted 2 lines
As I know,
KASAN_VMALLOCnow only supportsKASAN_GENERICand alsoKASAN_VMALLOCuses more memory to map real shadow memory (1/8 of vmalloc va).The shadow is allocated dynamically though, isn't it?
Yes, but It's still a cost.
Quoted 9 lines
Quoted 2 lines
There should be someone can enable
KASAN_GENERICbut can't use VMALLOC due to memory issue.That doesn't sound particularly realistic to me. The reason I'm pushing here is because I would _really_ like to move to VMAP stack unconditionally, and that would effectively force
KASAN_VMALLOCto be set if KASAN is in use.So unless there's a really good reason not to do that, please can we make this unconditional for arm64? Pretty please?
I think it's fine since we have a good reason. Also if someone have memory issue in KASAN_VMALLOC, they can use SW_TAG, right?
However the SW_TAG/HW_TAG is not supported VMALLOC yet. So the code would be like
if (IS_ENABLED(CONFIG_KASAN_GENERIC))
/* explain the relationship between
* KASAN_GENERIC and KASAN_VMALLOC in arm64
* XXX: because we want VMAP stack....
*/
kasan_populate_early_shadow((void *)vmalloc_shadow_end,
(void *)KASAN_SHADOW_END);
else {
kasan_populate_early_shadow((void *)kimg_shadow_end,
(void *)KASAN_SHADOW_END);
if (kimg_shadow_start > mod_shadow_end)
kasan_populate_early_shadow((void *)mod_shadow_end,
(void *)kimg_shadow_start);
}and the arch/arm64/Kconfig will add
select KASAN_VMALLOC if KASAN_GENERIC
Is this code same as your thought?
BRs,
Lecopzer
Will Deacon
maintainerRe: [PATCH v2 1/4] arm64: kasan: don't populate vmalloc area for CONFIG_KASAN_VMALLOC
Quoted 67 lines · Lecopzer Chen
Quoted 50 lines · Lecopzer Chen
Quoted 48 lines
Quoted 47 lines · Lecopzer Chen
Quoted 36 lines
Linux support KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Like how the
MODULES_VADDRdoes now, just not to early populate theVMALLOC_STARTbetweenVMALLOC_END.
similarly, the kernel code mapping is now in the VMALLOC area and should keep these area populated.Signed-off-by Lecopzer Chen <[email protected]>---
arch/arm64/mm/kasan_init.c | 23 ++++++++++++++++++-----1 file changed, 18 insertions(+), 5 deletions(-)arch/arm64/mm/kasan_init.c +4
-0@@ -214,6 +214,7 @@ static void __init kasan_init_shadow(void) { u64 kimg_shadow_start, kimg_shadow_end; u64 mod_shadow_start, mod_shadow_end; +u64 vmalloc_shadow_start, vmalloc_shadow_end; phys_addr_t pa_start, pa_end; u64 i;@@ -223,6 +224,9 @@ static void __init kasan_init_shadow(void) mod_shadow_start = (u64)kasan_mem_to_shadow((void *)MODULES_VADDR); mod_shadow_end = (u64)kasan_mem_to_shadow((void *)MODULES_END); + vmalloc_shadow_start = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_START ); + vmalloc_shadow_end = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_END ); + /** We are going to perform proper setup of shadow memory. * At first we should unmap early shadow (clear_pgds() call below). arch/arm64/mm/kasan_init.c static void __init kasan_init_shadow(void) · line 248
Quoted 6 lines
arch/arm64/mm/kasan_init.c +1
-2@@ -241,12 +245,21 @@ static void __init kasan_init_shadow(void) kasan_populate_early_shadow(kasan_mem_to_shadow((void *)PAGE_END), (void *)mod_shadow_start); -kasan_populate_early_shadow ((void *)kimg_shadow_end, - (void *)KASAN_SHADOW_END); +if (IS_ENABLED (CONFIG_KASAN_VMALLOC )) {Do we really need yet another CONFIG option for KASAN? What's the use-case for *not* enabling this if you're already enabling one of the KASAN backends?
Quoted 4 lines
Quoted 2 lines
As I know,
KASAN_VMALLOCnow only supportsKASAN_GENERICand alsoKASAN_VMALLOCuses more memory to map real shadow memory (1/8 of vmalloc va).The shadow is allocated dynamically though, isn't it?
Yes, but It's still a cost.
Quoted 9 lines
Quoted 2 lines
There should be someone can enable
KASAN_GENERICbut can't use VMALLOC due to memory issue.That doesn't sound particularly realistic to me. The reason I'm pushing here is because I would _really_ like to move to VMAP stack unconditionally, and that would effectively force
KASAN_VMALLOCto be set if KASAN is in use.So unless there's a really good reason not to do that, please can we make this unconditional for arm64? Pretty please?
Quoted 8 lines
I think it's fine since we have a good reason. Also if someone have memory issue in
KASAN_VMALLOC, they can useSW_TAG, right?However the SW_TAG/HW_TAG is not supported VMALLOC yet. So the code would be like
if (
IS_ENABLED(CONFIG_KASAN_GENERIC))
Just make this CONFIG_KASAN_VMALLOC, since that depends on KASAN_GENERIC.
Quoted 4 lines
/* explain the relationship between * KASAN_GENERIC and KASAN_VMALLOC in arm64 * XXX: because we want VMAP stack.... */
I don't understand the relation with SW_TAGS. The VMAP_STACK dependency is:
depends on !KASAN || KASAN_HW_TAGS || KASAN_VMALLOC
which doesn't mention SW_TAGS at all. So that seems to imply that SW_TAGS and VMAP_STACK are mutually exclusive :(
Will
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
Re: [PATCH v2 1/4] arm64: kasan: don't populate vmalloc area for CONFIG_KASAN_VMALLOC
Quoted 80 lines · Will Deacon
Quoted 67 lines · Lecopzer Chen
Quoted 50 lines · Lecopzer Chen
Quoted 48 lines
Quoted 47 lines · Lecopzer Chen
Quoted 36 lines
Linux support KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Like how the
MODULES_VADDRdoes now, just not to early populate theVMALLOC_STARTbetweenVMALLOC_END.
similarly, the kernel code mapping is now in the VMALLOC area and should keep these area populated.Signed-off-by Lecopzer Chen <[email protected]>--- arch/arm64/mm/kasan_init.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)arch/arm64/mm/kasan_init.c +4
-0@@ -214,6 +214,7 @@ static void __init kasan_init_shadow(void) {u64 kimg_shadow_start, kimg_shadow_end;u64 mod_shadow_start, mod_shadow_end; +u64 vmalloc_shadow_start, vmalloc_shadow_end;phys_addr_t pa_start, pa_end;u64 i;@@ -223,6 +224,9 @@ static void __init kasan_init_shadow(void) mod_shadow_start = (u64 )kasan_mem_to_shadow ((void *)MODULES_VADDR ); mod_shadow_end = (u64 )kasan_mem_to_shadow ((void *)MODULES_END ); + vmalloc_shadow_start = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_START ); + vmalloc_shadow_end = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_END ); +/* * We are going to perform proper setup of shadow memory. * At first we should unmap early shadow (clear_pgds() call below). arch/arm64/mm/kasan_init.c static void __init kasan_init_shadow(void) · line 248
Quoted 6 lines
arch/arm64/mm/kasan_init.c +1
-2@@ -241,12 +245,21 @@ static void __init kasan_init_shadow(void)kasan_populate_early_shadow (kasan_mem_to_shadow ((void *)PAGE_END ), (void *)mod_shadow_start); -kasan_populate_early_shadow ((void *)kimg_shadow_end, - (void *)KASAN_SHADOW_END ); +if (IS_ENABLED (CONFIG_KASAN_VMALLOC )) {Do we really need yet another CONFIG option for KASAN? What's the use-case for *not* enabling this if you're already enabling one of the KASAN backends?
Quoted 4 lines
Quoted 2 lines
As I know,
KASAN_VMALLOCnow only supportsKASAN_GENERICand alsoKASAN_VMALLOCuses more memory to map real shadow memory (1/8 of vmalloc va).The shadow is allocated dynamically though, isn't it?
Yes, but It's still a cost.
Quoted 9 lines
Quoted 2 lines
There should be someone can enable
KASAN_GENERICbut can't use VMALLOC due to memory issue.That doesn't sound particularly realistic to me. The reason I'm pushing here is because I would _really_ like to move to VMAP stack unconditionally, and that would effectively force
KASAN_VMALLOCto be set if KASAN is in use.So unless there's a really good reason not to do that, please can we make this unconditional for arm64? Pretty please?
Quoted 8 lines
I think it's fine since we have a good reason. Also if someone have memory issue in
KASAN_VMALLOC, they can useSW_TAG, right?However the SW_TAG/HW_TAG is not supported VMALLOC yet. So the code would be like
if (
IS_ENABLED(CONFIG_KASAN_GENERIC))Just make this
CONFIG_KASAN_VMALLOC, since that depends onKASAN_GENERIC.
Quoted 8 lines
Quoted 4 lines
/* explain the relationship between
*KASAN_GENERICandKASAN_VMALLOCin arm64
* XXX: because we want VMAP stack.... */I don't understand the relation with
SW_TAGS. TheVMAP_STACKdependency is:depends on !KASAN || KASAN_HW_TAGS || KASAN_VMALLOC
This means that VMAP_STACK can be only enabled if KASAN_HW_TAGS=y or if KASAN_VMALLOC=y for other modes.
Quoted 3 lines
which doesn't mention
SW_TAGSat all. So that seems to imply thatSW_TAGSandVMAP_STACKare mutually exclusive :(
SW_TAGS doesn't yet have vmalloc support, so it's not compatible with VMAP_STACK. Once vmalloc support is added to SW_TAGS, KASAN_VMALLOC should be allowed to be enabled with SW_TAGS. This series is a step towards having that support, but doesn't implement it. That will be a separate effort.
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
Will Deacon
maintainerRe: [PATCH v2 1/4] arm64: kasan: don't populate vmalloc area for CONFIG_KASAN_VMALLOC
Quoted 94 lines · Andrey Konovalov
Quoted 80 lines · Will Deacon
Quoted 67 lines · Lecopzer Chen
Quoted 50 lines · Lecopzer Chen
Quoted 48 lines
Quoted 47 lines · Lecopzer Chen
Quoted 36 lines
Linux support KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Like how the
MODULES_VADDRdoes now, just not to early populate theVMALLOC_STARTbetweenVMALLOC_END.
similarly, the kernel code mapping is now in the VMALLOC area and should keep these area populated.Signed-off-by Lecopzer Chen <[email protected]>--- arch/arm64/mm/kasan_init.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)arch/arm64/mm/kasan_init.c +4
-0@@ -214,6 +214,7 @@ static void __init kasan_init_shadow(void) {u64 kimg_shadow_start, kimg_shadow_end;u64 mod_shadow_start, mod_shadow_end; +u64 vmalloc_shadow_start, vmalloc_shadow_end;phys_addr_t pa_start, pa_end;u64 i;@@ -223,6 +224,9 @@ static void __init kasan_init_shadow(void) mod_shadow_start = (u64 )kasan_mem_to_shadow ((void *)MODULES_VADDR ); mod_shadow_end = (u64 )kasan_mem_to_shadow ((void *)MODULES_END ); + vmalloc_shadow_start = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_START ); + vmalloc_shadow_end = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_END ); +/* * We are going to perform proper setup of shadow memory. * At first we should unmap early shadow (clear_pgds() call below). arch/arm64/mm/kasan_init.c static void __init kasan_init_shadow(void) · line 248
Quoted 6 lines
arch/arm64/mm/kasan_init.c +1
-2@@ -241,12 +245,21 @@ static void __init kasan_init_shadow(void)kasan_populate_early_shadow (kasan_mem_to_shadow ((void *)PAGE_END ), (void *)mod_shadow_start); -kasan_populate_early_shadow ((void *)kimg_shadow_end, - (void *)KASAN_SHADOW_END ); +if (IS_ENABLED (CONFIG_KASAN_VMALLOC )) {Do we really need yet another CONFIG option for KASAN? What's the use-case for *not* enabling this if you're already enabling one of the KASAN backends?
Quoted 4 lines
Quoted 2 lines
As I know,
KASAN_VMALLOCnow only supportsKASAN_GENERICand alsoKASAN_VMALLOCuses more memory to map real shadow memory (1/8 of vmalloc va).The shadow is allocated dynamically though, isn't it?
Yes, but It's still a cost.
Quoted 9 lines
Quoted 2 lines
There should be someone can enable
KASAN_GENERICbut can't use VMALLOC due to memory issue.That doesn't sound particularly realistic to me. The reason I'm pushing here is because I would _really_ like to move to VMAP stack unconditionally, and that would effectively force
KASAN_VMALLOCto be set if KASAN is in use.So unless there's a really good reason not to do that, please can we make this unconditional for arm64? Pretty please?
Quoted 8 lines
I think it's fine since we have a good reason. Also if someone have memory issue in
KASAN_VMALLOC, they can useSW_TAG, right?However the SW_TAG/HW_TAG is not supported VMALLOC yet. So the code would be like
if (
IS_ENABLED(CONFIG_KASAN_GENERIC))Just make this
CONFIG_KASAN_VMALLOC, since that depends onKASAN_GENERIC.Quoted 8 lines
Quoted 4 lines
/* explain the relationship between
*KASAN_GENERICandKASAN_VMALLOCin arm64
* XXX: because we want VMAP stack.... */I don't understand the relation with
SW_TAGS. TheVMAP_STACKdependency is:depends on !KASAN || KASAN_HW_TAGS || KASAN_VMALLOCThis means that
VMAP_STACKcan be only enabled if KASAN_HW_TAGS=y or if KASAN_VMALLOC=y for other modes.Quoted 1 line
Quoted 8 lines
Quoted 2 lines
which doesn't mention
SW_TAGSat all. So that seems to imply thatSW_TAGSandVMAP_STACKare mutually exclusive :(
SW_TAGSdoesn't yet have vmalloc support, so it's not compatible withVMAP_STACK. Once vmalloc support is added toSW_TAGS,KASAN_VMALLOCshould be allowed to be enabled withSW_TAGS. This series is a step towards having that support, but doesn't implement it. That will be a separate effort.
Ok, thanks. Then I think we should try to invert the dependency here, if possible, so that the KASAN backends depend on !VMAP_STACK if they don't support it, rather than silently disabling VMAP_STACK when they are selected.
Will
Re: [PATCH v2 1/4] arm64: kasan: don't populate vmalloc area for CONFIG_KASAN_VMALLOC
Quoted 105 lines · Will Deacon
Quoted 94 lines · Andrey Konovalov
Quoted 80 lines · Will Deacon
Quoted 67 lines · Lecopzer Chen
Quoted 50 lines · Lecopzer Chen
Quoted 48 lines
Quoted 47 lines · Lecopzer Chen
Quoted 36 lines
Linux support KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Like how the
MODULES_VADDRdoes now, just not to early populate theVMALLOC_STARTbetweenVMALLOC_END.
similarly, the kernel code mapping is now in the VMALLOC area and should keep these area populated.Signed-off-by Lecopzer Chen <[email protected]>--- arch/arm64/mm/kasan_init.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)arch/arm64/mm/kasan_init.c +4
-0@@ -214,6 +214,7 @@ static void __init kasan_init_shadow(void) {u64 kimg_shadow_start, kimg_shadow_end;u64 mod_shadow_start, mod_shadow_end; +u64 vmalloc_shadow_start, vmalloc_shadow_end;phys_addr_t pa_start, pa_end;u64 i;@@ -223,6 +224,9 @@ static void __init kasan_init_shadow(void) mod_shadow_start = (u64 )kasan_mem_to_shadow ((void *)MODULES_VADDR ); mod_shadow_end = (u64 )kasan_mem_to_shadow ((void *)MODULES_END ); + vmalloc_shadow_start = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_START ); + vmalloc_shadow_end = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_END ); +/* * We are going to perform proper setup of shadow memory. * At first we should unmap early shadow (clear_pgds() call below). arch/arm64/mm/kasan_init.c static void __init kasan_init_shadow(void) · line 248
Quoted 6 lines
arch/arm64/mm/kasan_init.c +1
-2@@ -241,12 +245,21 @@ static void __init kasan_init_shadow(void)kasan_populate_early_shadow (kasan_mem_to_shadow ((void *)PAGE_END ), (void *)mod_shadow_start); -kasan_populate_early_shadow ((void *)kimg_shadow_end, - (void *)KASAN_SHADOW_END ); +if (IS_ENABLED (CONFIG_KASAN_VMALLOC )) {Do we really need yet another CONFIG option for KASAN? What's the use-case for *not* enabling this if you're already enabling one of the KASAN backends?
Quoted 4 lines
Quoted 2 lines
As I know,
KASAN_VMALLOCnow only supportsKASAN_GENERICand alsoKASAN_VMALLOCuses more memory to map real shadow memory (1/8 of vmalloc va).The shadow is allocated dynamically though, isn't it?
Yes, but It's still a cost.
Quoted 9 lines
Quoted 2 lines
There should be someone can enable
KASAN_GENERICbut can't use VMALLOC due to memory issue.That doesn't sound particularly realistic to me. The reason I'm pushing here is because I would _really_ like to move to VMAP stack unconditionally, and that would effectively force
KASAN_VMALLOCto be set if KASAN is in use.So unless there's a really good reason not to do that, please can we make this unconditional for arm64? Pretty please?
Quoted 8 lines
I think it's fine since we have a good reason. Also if someone have memory issue in
KASAN_VMALLOC, they can useSW_TAG, right?However the SW_TAG/HW_TAG is not supported VMALLOC yet. So the code would be like
if (
IS_ENABLED(CONFIG_KASAN_GENERIC))Just make this
CONFIG_KASAN_VMALLOC, since that depends onKASAN_GENERIC.Quoted 8 lines
Quoted 4 lines
/* explain the relationship between
*KASAN_GENERICandKASAN_VMALLOCin arm64
* XXX: because we want VMAP stack.... */I don't understand the relation with
SW_TAGS. TheVMAP_STACKdependency is:depends on !KASAN || KASAN_HW_TAGS || KASAN_VMALLOCThis means that
VMAP_STACKcan be only enabled if KASAN_HW_TAGS=y or if KASAN_VMALLOC=y for other modes.Quoted 1 line
Quoted 8 lines
Quoted 2 lines
which doesn't mention
SW_TAGSat all. So that seems to imply thatSW_TAGSandVMAP_STACKare mutually exclusive :(
SW_TAGSdoesn't yet have vmalloc support, so it's not compatible withVMAP_STACK. Once vmalloc support is added toSW_TAGS,KASAN_VMALLOCshould be allowed to be enabled withSW_TAGS. This series is a step towards having that support, but doesn't implement it. That will be a separate effort.
Quoted 4 lines
Ok, thanks. Then I think we should try to invert the dependency here, if possible, so that the KASAN backends depend on !VMAP_STACK if they don't support it, rather than silently disabling
VMAP_STACKwhen they are selected.
SGTM. Not sure if I will get to this in the nearest future, so I filed a bug: https://bugzilla.kernel.org/show_bug.cgi?id=211581
Re: [PATCH v2 1/4] arm64: kasan: don't populate vmalloc area for CONFIG_KASAN_VMALLOC
In reply to Will DeaconWill Deacon <[email protected]> 於 2021年2月6日 週六 上午1:19寫道:
Quoted 73 lines · Lecopzer Chen
Quoted 71 lines
Quoted 49 lines · Lecopzer Chen
Quoted 47 lines
Quoted 47 lines · Lecopzer Chen
Quoted 36 lines
Linux support KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Like how the
MODULES_VADDRdoes now, just not to early populate theVMALLOC_STARTbetweenVMALLOC_END.
similarly, the kernel code mapping is now in the VMALLOC area and should keep these area populated.Signed-off-by Lecopzer Chen <[email protected]>--- arch/arm64/mm/kasan_init.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)arch/arm64/mm/kasan_init.c +4
-0@@ -214,6 +214,7 @@ static void __init kasan_init_shadow(void) {u64 kimg_shadow_start, kimg_shadow_end;u64 mod_shadow_start, mod_shadow_end; +u64 vmalloc_shadow_start, vmalloc_shadow_end;phys_addr_t pa_start, pa_end;u64 i;@@ -223,6 +224,9 @@ static void __init kasan_init_shadow(void) mod_shadow_start = (u64 )kasan_mem_to_shadow ((void *)MODULES_VADDR ); mod_shadow_end = (u64 )kasan_mem_to_shadow ((void *)MODULES_END ); + vmalloc_shadow_start = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_START ); + vmalloc_shadow_end = (u64 )kasan_mem_to_shadow ((void *)VMALLOC_END ); +/* * We are going to perform proper setup of shadow memory. * At first we should unmap early shadow (clear_pgds() call below). arch/arm64/mm/kasan_init.c static void __init kasan_init_shadow(void) · line 248
Quoted 6 lines
arch/arm64/mm/kasan_init.c +1
-2@@ -241,12 +245,21 @@ static void __init kasan_init_shadow(void)kasan_populate_early_shadow (kasan_mem_to_shadow ((void *)PAGE_END ), (void *)mod_shadow_start); -kasan_populate_early_shadow ((void *)kimg_shadow_end, - (void *)KASAN_SHADOW_END ); +if (IS_ENABLED (CONFIG_KASAN_VMALLOC )) {Do we really need yet another CONFIG option for KASAN? What's the use-case for *not* enabling this if you're already enabling one of the KASAN backends?
Quoted 5 lines
Quoted 3 lines
commit message
As I know,KASAN_VMALLOCnow only supportsKASAN_GENERICand alsoKASAN_VMALLOCuses more memory to map real shadow memory (1/8 of vmalloc va).The shadow is allocated dynamically though, isn't it?
Yes, but It's still a cost.
Quoted 9 lines
Quoted 2 lines
There should be someone can enable
KASAN_GENERICbut can't use VMALLOC due to memory issue.That doesn't sound particularly realistic to me. The reason I'm pushing here is because I would _really_ like to move to VMAP stack unconditionally, and that would effectively force
KASAN_VMALLOCto be set if KASAN is in use.So unless there's a really good reason not to do that, please can we make this unconditional for arm64? Pretty please?
I think it's fine since we have a good reason. Also if someone have memory issue in
KASAN_VMALLOC, they can useSW_TAG, right?
Quoted 6 lines
Quoted 4 lines
However the SW_TAG/HW_TAG is not supported VMALLOC yet. So the code would be like
if (
IS_ENABLED(CONFIG_KASAN_GENERIC))Just make this
CONFIG_KASAN_VMALLOC, since that depends onKASAN_GENERIC.
OK, this also make sense.
My first thought was that selecting KASAN_GENERIC implies VMALLOC in arm64 is a special case so this need well documented. I'll document this in the commit message of Kconfig patch to avoid messing up the code here.
I'm going to send V3 patch, thanks again for your review.
BRs,
Lecopzer
PATCH v2 2/4 arm64: kasan: abstract _text and _end to KERNEL_START/END
In reply to Lecopzer ChenArm64 provide defined macro for KERNEL_START and KERNEL_END, thus replace them by the abstration instead of using _text and _end.
--- arch/arm64/mm/kasan_init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm64/mm/kasan_init.c +3 -3
@@ -218,8 +218,8 @@ static void __init kasan_init_shadow(void)phys_addr_t pa_start, pa_end;u64 i; - kimg_shadow_start = (u64 )kasan_mem_to_shadow (_text) &PAGE_MASK ; - kimg_shadow_end =PAGE_ALIGN ((u64 )kasan_mem_to_shadow (_end)); + kimg_shadow_start = (u64 )kasan_mem_to_shadow (KERNEL_START ) &PAGE_MASK ; + kimg_shadow_end =PAGE_ALIGN ((u64 )kasan_mem_to_shadow (KERNEL_END )); mod_shadow_start = (u64 )kasan_mem_to_shadow ((void *)MODULES_VADDR ); mod_shadow_end = (u64 )kasan_mem_to_shadow ((void *)MODULES_END );
@@ -241,7 +241,7 @@ static void __init kasan_init_shadow(void)clear_pgds (KASAN_SHADOW_START ,KASAN_SHADOW_END );kasan_map_populate (kimg_shadow_start, kimg_shadow_end, -early_pfn_to_nid (virt_to_pfn (lm_alias (_text)))); +early_pfn_to_nid (virt_to_pfn (lm_alias (KERNEL_START ))));kasan_populate_early_shadow (kasan_mem_to_shadow ((void *)PAGE_END ), (void *)mod_shadow_start);
Signature · 1 line
2.25.1
Will Deacon
maintainerRe: [PATCH v2 2/4] arm64: kasan: abstract _text and _end to KERNEL_START/END
Quoted 24 lines · Lecopzer Chen
Arm64 provide defined macro for
KERNEL_STARTandKERNEL_END, thus replace them by the abstration instead of using_textand_end.Signed-off-by Lecopzer Chen <[email protected]>--- arch/arm64/mm/kasan_init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/arm64/mm/kasan_init.c +2
-2@@ -218,8 +218,8 @@ static void __init kasan_init_shadow(void)phys_addr_t pa_start, pa_end;u64 i; - kimg_shadow_start = (u64 )kasan_mem_to_shadow (_text) &PAGE_MASK ; - kimg_shadow_end =PAGE_ALIGN ((u64 )kasan_mem_to_shadow (_end)); + kimg_shadow_start = (u64 )kasan_mem_to_shadow (KERNEL_START ) &PAGE_MASK ; + kimg_shadow_end =PAGE_ALIGN ((u64 )kasan_mem_to_shadow (KERNEL_END )); mod_shadow_start = (u64 )kasan_mem_to_shadow ((void *)MODULES_VADDR ); mod_shadow_end = (u64 )kasan_mem_to_shadow ((void *)MODULES_END );
arch/arm64/mm/kasan_init.c static void __init kasan_init_shadow(void) · line 244
Quoted 5 lines
arch/arm64/mm/kasan_init.c +1
-1@@ -241,7 +241,7 @@ static void __init kasan_init_shadow(void)clear_pgds (KASAN_SHADOW_START ,KASAN_SHADOW_END );kasan_map_populate (kimg_shadow_start, kimg_shadow_end, -early_pfn_to_nid (virt_to_pfn (lm_alias (_text)))); +early_pfn_to_nid (virt_to_pfn (lm_alias (KERNEL_START ))));
To be honest, I think this whole line is pointless. We should be able to pass NUMA_NO_NODE now that we're not abusing the vmemmap() allocator to populate the shadow.
Will
Re: [PATCH v2 2/4] arm64: kasan: abstract _text and _end to KERNEL_START/END
Quoted 27 lines · Lecopzer Chen
Quoted 26 lines
Arm64 provide defined macro for
KERNEL_STARTandKERNEL_END, thus replace them by the abstration instead of using_textand_end.Signed-off-by Lecopzer Chen <[email protected]>--- arch/arm64/mm/kasan_init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/arm64/mm/kasan_init.c +2
-2@@ -218,8 +218,8 @@ static void __init kasan_init_shadow(void)phys_addr_t pa_start, pa_end;u64 i; - kimg_shadow_start = (u64 )kasan_mem_to_shadow (_text) &PAGE_MASK ; - kimg_shadow_end =PAGE_ALIGN ((u64 )kasan_mem_to_shadow (_end)); + kimg_shadow_start = (u64 )kasan_mem_to_shadow (KERNEL_START ) &PAGE_MASK ; + kimg_shadow_end =PAGE_ALIGN ((u64 )kasan_mem_to_shadow (KERNEL_END )); mod_shadow_start = (u64 )kasan_mem_to_shadow ((void *)MODULES_VADDR ); mod_shadow_end = (u64 )kasan_mem_to_shadow ((void *)MODULES_END );@@ -241,7 +241,7 @@ static void __init kasan_init_shadow(void)clear_pgds (KASAN_SHADOW_START ,KASAN_SHADOW_END );
Quoted 7 lines
arch/arm64/mm/kasan_init.c static void __init kasan_init_shadow(void) · line 244
Quoted 3 lines
arch/arm64/mm/kasan_init.c +1
-1kasan_map_populate (kimg_shadow_start, kimg_shadow_end, -early_pfn_to_nid (virt_to_pfn (lm_alias (_text)))); +early_pfn_to_nid (virt_to_pfn (lm_alias (KERNEL_START ))));To be honest, I think this whole line is pointless. We should be able to pass
NUMA_NO_NODEnow that we're not abusing thevmemmap()allocator to populate the shadow.
Do we need to fix this in this series? it seems another topic. If not, should this patch be removed in this series?
Thanks,
Lecopzer
Will Deacon
maintainerRe: [PATCH v2 2/4] arm64: kasan: abstract _text and _end to KERNEL_START/END
Quoted 35 lines · Lecopzer Chen
Quoted 27 lines · Lecopzer Chen
Quoted 26 lines
Arm64 provide defined macro for
KERNEL_STARTandKERNEL_END, thus replace them by the abstration instead of using_textand_end.Signed-off-by Lecopzer Chen <[email protected]>--- arch/arm64/mm/kasan_init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/arm64/mm/kasan_init.c +2
-2@@ -218,8 +218,8 @@ static void __init kasan_init_shadow(void)phys_addr_t pa_start, pa_end;u64 i; - kimg_shadow_start = (u64 )kasan_mem_to_shadow (_text) &PAGE_MASK ; - kimg_shadow_end =PAGE_ALIGN ((u64 )kasan_mem_to_shadow (_end)); + kimg_shadow_start = (u64 )kasan_mem_to_shadow (KERNEL_START ) &PAGE_MASK ; + kimg_shadow_end =PAGE_ALIGN ((u64 )kasan_mem_to_shadow (KERNEL_END )); mod_shadow_start = (u64 )kasan_mem_to_shadow ((void *)MODULES_VADDR ); mod_shadow_end = (u64 )kasan_mem_to_shadow ((void *)MODULES_END );@@ -241,7 +241,7 @@ static void __init kasan_init_shadow(void)clear_pgds (KASAN_SHADOW_START ,KASAN_SHADOW_END );Quoted 7 lines
arch/arm64/mm/kasan_init.c static void __init kasan_init_shadow(void) · line 244
Quoted 3 lines
arch/arm64/mm/kasan_init.c +1
-1kasan_map_populate (kimg_shadow_start, kimg_shadow_end, -early_pfn_to_nid (virt_to_pfn (lm_alias (_text)))); +early_pfn_to_nid (virt_to_pfn (lm_alias (KERNEL_START ))));To be honest, I think this whole line is pointless. We should be able to pass
NUMA_NO_NODEnow that we're not abusing thevmemmap()allocator to populate the shadow.
Quoted 2 lines
Do we need to fix this in this series? it seems another topic. If not, should this patch be removed in this series?
Since you're reposting anyway, you may as well include a patch doing that. If you don't, then I will.
Will
Re: [PATCH v2 2/4] arm64: kasan: abstract _text and _end to KERNEL_START/END
I think it would be better to leave this for you since I'm not familiar with the relationship
between vmemmap() and NUMA_NO_NODE.
So I would just keep this patch in next version, is this fine with you?
Thanks for your help:)
Lecopzer
Will Deacon <[email protected]> 於 2021年2月4日 週四 下午10:55寫道:
Quoted 44 lines · Lecopzer Chen
Quoted 35 lines
Quoted 27 lines · Lecopzer Chen
Quoted 26 lines
Arm64 provide defined macro for
KERNEL_STARTandKERNEL_END, thus replace them by the abstration instead of using_textand_end.Signed-off-by Lecopzer Chen <[email protected]>--- arch/arm64/mm/kasan_init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/arm64/mm/kasan_init.c +2
-2@@ -218,8 +218,8 @@ static void __init kasan_init_shadow(void)phys_addr_t pa_start, pa_end;u64 i; - kimg_shadow_start = (u64 )kasan_mem_to_shadow (_text) &PAGE_MASK ; - kimg_shadow_end =PAGE_ALIGN ((u64 )kasan_mem_to_shadow (_end)); + kimg_shadow_start = (u64 )kasan_mem_to_shadow (KERNEL_START ) &PAGE_MASK ; + kimg_shadow_end =PAGE_ALIGN ((u64 )kasan_mem_to_shadow (KERNEL_END )); mod_shadow_start = (u64 )kasan_mem_to_shadow ((void *)MODULES_VADDR ); mod_shadow_end = (u64 )kasan_mem_to_shadow ((void *)MODULES_END );@@ -241,7 +241,7 @@ static void __init kasan_init_shadow(void)clear_pgds (KASAN_SHADOW_START ,KASAN_SHADOW_END );Quoted 7 lines
arch/arm64/mm/kasan_init.c static void __init kasan_init_shadow(void) · line 244
Quoted 3 lines
arch/arm64/mm/kasan_init.c +1
-1kasan_map_populate (kimg_shadow_start, kimg_shadow_end, -early_pfn_to_nid (virt_to_pfn (lm_alias (_text)))); +early_pfn_to_nid (virt_to_pfn (lm_alias (KERNEL_START ))));To be honest, I think this whole line is pointless. We should be able to pass
NUMA_NO_NODEnow that we're not abusing thevmemmap()allocator to populate the shadow.Quoted 2 lines
Do we need to fix this in this series? it seems another topic. If not, should this patch be removed in this series?
Since you're reposting anyway, you may as well include a patch doing that. If you don't, then I will.
Will
Will Deacon
maintainerRe: [PATCH v2 2/4] arm64: kasan: abstract _text and _end to KERNEL_START/END
Quoted 5 lines · Lecopzer Chen
I think it would be better to leave this for you since I'm not familiar with the relationship
betweenvmemmap()andNUMA_NO_NODE.So I would just keep this patch in next version, is this fine with you?
Yes, ok.
Will
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
PATCH v2 3/4 arm64: Kconfig: support CONFIG_KASAN_VMALLOC
In reply to Lecopzer Chennow we can backed shadow memory in vmalloc area,
thus support KASAN_VMALLOC in KASAN_GENERIC mode.
--- arch/arm64/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm64/Kconfig +1 -0
@@ -136,6 +136,7 @@ config ARM64 select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_JUMP_LABEL_RELATIVE select HAVE_ARCH_KASAN if !(ARM64_16K_PAGES && ARM64_VA_BITS_48) + select HAVE_ARCH_KASAN_VMALLOC if HAVE_ARCH_KASAN select HAVE_ARCH_KASAN_SW_TAGS if HAVE_ARCH_KASAN select HAVE_ARCH_KASAN_HW_TAGS if (HAVE_ARCH_KASAN && ARM64_MTE) select HAVE_ARCH_KGDB
Signature · 1 line
2.25.1
PATCH v2 4/4 arm64: kaslr: support randomized module area with KASAN_VMALLOC
In reply to Lecopzer ChenAfter KASAN_VMALLOC works in arm64, we can randomize module region into vmalloc area now.
Test:
VMALLOC area ffffffc010000000 fffffffdf0000000 before the patch: module_alloc_base/end ffffffc008b80000 ffffffc010000000 after the patch: module_alloc_base/end ffffffdcf4bed000 ffffffc010000000 And the function that insmod some modules is fine.
--- arch/arm64/kernel/kaslr.c | 18 ++++++++++-------- arch/arm64/kernel/module.c | 16 +++++++++------- 2 files changed, 19 insertions(+), 15 deletions(-)
arch/arm64/kernel/kaslr.c +10 -8
@@ -161,15 +161,17 @@ u64 __init kaslr_early_init(u64 dt_phys)/* use the top 16 bits to randomize the linear region */ memstart_offset_seed = seed >>48 ; -if (IS_ENABLED (CONFIG_KASAN_GENERIC ) || -IS_ENABLED (CONFIG_KASAN_SW_TAGS )) +if (!IS_ENABLED (CONFIG_KASAN_VMALLOC ) && + (IS_ENABLED (CONFIG_KASAN_GENERIC ) || +IS_ENABLED (CONFIG_KASAN_SW_TAGS )))/* -* KASAN does not expect the module region to intersect the -* vmalloc region, since shadow memory is allocated for each -* module at load time, whereas the vmalloc region is shadowed -* by KASAN zero pages. So keep modules out of the vmalloc -* region if KASAN is enabled, and put the kernel well within -* 4 GB of the module region. +* KASAN without KASAN_VMALLOC does not expect the module region +* to intersect the vmalloc region, since shadow memory is +* allocated for each module at load time, whereas the vmalloc +* region is shadowed by KASAN zero pages. So keep modules +* out of the vmalloc region if KASAN is enabled without +* KASAN_VMALLOC, and put the kernel well within 4 GB of the +* module region. */ return offset %SZ_2G ;
arch/arm64/kernel/module.c +9 -7
@@ -40,14 +40,16 @@ void *module_alloc(unsigned long size) NUMA_NO_NODE, __builtin_return_address(0));if (!p &&IS_ENABLED (CONFIG_ARM64_MODULE_PLTS ) && - !IS_ENABLED (CONFIG_KASAN_GENERIC ) && - !IS_ENABLED (CONFIG_KASAN_SW_TAGS )) + (IS_ENABLED (CONFIG_KASAN_VMALLOC ) || + (!IS_ENABLED (CONFIG_KASAN_GENERIC ) && + !IS_ENABLED (CONFIG_KASAN_SW_TAGS ))))/* -* KASAN can only deal with module allocations being served -* from the reserved module region, since the remainder of -* the vmalloc region is already backed by zero shadow pages, -* and punching holes into it is non-trivial. Since the module -* region is not randomized when KASAN is enabled, it is even +* KASAN without KASAN_VMALLOC can only deal with module +* allocations being served from the reserved module region, +* since the remainder of the vmalloc region is already +* backed by zero shadow pages, and punching holes into it +* is non-trivial. Since the module region is not randomized +* when KASAN is enabled without KASAN_VMALLOC, it is even * less likely that the module region gets exhausted, so we * can simply omit this fallback in that case. */
Signature · 1 line
2.25.1
Will Deacon
maintainerRe: [PATCH v2 4/4] arm64: kaslr: support randomized module area with KASAN_VMALLOC
Quoted 25 lines · Lecopzer Chen
After
KASAN_VMALLOCworks in arm64, we can randomize module region into vmalloc area now.Test:
VMALLOC area ffffffc010000000 fffffffdf0000000 before the patch: module_alloc_base/end ffffffc008b80000 ffffffc010000000 after the patch: module_alloc_base/end ffffffdcf4bed000 ffffffc010000000 And the function that insmod some modules is fine.Suggested-by Ard Biesheuvel <[email protected]>Signed-off-by Lecopzer Chen <[email protected]>--- arch/arm64/kernel/kaslr.c | 18 ++++++++++-------- arch/arm64/kernel/module.c | 16 +++++++++------- 2 files changed, 19 insertions(+), 15 deletions(-)arch/arm64/kernel/kaslr.c +0
-0
arch/arm64/kernel/kaslr.c u64 __init kaslr_early_init(u64 dt_phys) · line 165
Quoted 7 lines
arch/arm64/kernel/kaslr.c +2
-2@@ -161,15 +161,17 @@ u64 __init kaslr_early_init(u64 dt_phys)/* use the top 16 bits to randomize the linear region */ memstart_offset_seed = seed >>48 ; -if (IS_ENABLED (CONFIG_KASAN_GENERIC ) || -IS_ENABLED (CONFIG_KASAN_SW_TAGS )) + if (!IS_ENABLED(CONFIG_KASAN_VMALLOC) && + (IS_ENABLED(CONFIG_KASAN_GENERIC) ||
CONFIG_KASAN_VMALLOC depends on CONFIG_KASAN_GENERIC so why is this necessary?
Will
Re: [PATCH v2 4/4] arm64: kaslr: support randomized module area with KASAN_VMALLOC
Quoted 38 lines · Lecopzer Chen
Quoted 25 lines
After
KASAN_VMALLOCworks in arm64, we can randomize module region into vmalloc area now.Test:
VMALLOC area ffffffc010000000 fffffffdf0000000 before the patch: module_alloc_base/end ffffffc008b80000 ffffffc010000000 after the patch: module_alloc_base/end ffffffdcf4bed000 ffffffc010000000 And the function that insmod some modules is fine.Suggested-by Ard Biesheuvel <[email protected]>Signed-off-by Lecopzer Chen <[email protected]>--- arch/arm64/kernel/kaslr.c | 18 ++++++++++-------- arch/arm64/kernel/module.c | 16 +++++++++------- 2 files changed, 19 insertions(+), 15 deletions(-)arch/arm64/kernel/kaslr.c +0
-0arch/arm64/kernel/kaslr.c u64 __init kaslr_early_init(u64 dt_phys) · line 165
Quoted 7 lines
arch/arm64/kernel/kaslr.c +2
-2@@ -161,15 +161,17 @@ u64 __init kaslr_early_init(u64 dt_phys)/* use the top 16 bits to randomize the linear region */ memstart_offset_seed = seed >>48 ; -if (IS_ENABLED (CONFIG_KASAN_GENERIC ) || -IS_ENABLED (CONFIG_KASAN_SW_TAGS )) + if (!IS_ENABLED(CONFIG_KASAN_VMALLOC) && + (IS_ENABLED(CONFIG_KASAN_GENERIC) ||
CONFIG_KASAN_VMALLOCdepends onCONFIG_KASAN_GENERICso why is this necessary?
Quoted 1 line
Will
CONFIG_KASAN_VMALLOC=y means CONFIG_KASAN_GENERIC=y but CONFIG_KASAN_GENERIC=y doesn't means CONFIG_KASAN_VMALLOC=y
So this if-condition allows only KASAN rather than KASAN + KASAN_VMALLOC enabled.
Please correct me if I'm wrong.
thanks,
Lecopzer
Will Deacon
maintainerRe: [PATCH v2 4/4] arm64: kaslr: support randomized module area with KASAN_VMALLOC
Quoted 40 lines · Lecopzer Chen
Quoted 38 lines · Lecopzer Chen
Quoted 25 lines
After
KASAN_VMALLOCworks in arm64, we can randomize module region into vmalloc area now.Test:
VMALLOC area ffffffc010000000 fffffffdf0000000 before the patch: module_alloc_base/end ffffffc008b80000 ffffffc010000000 after the patch: module_alloc_base/end ffffffdcf4bed000 ffffffc010000000 And the function that insmod some modules is fine.Suggested-by Ard Biesheuvel <[email protected]>Signed-off-by Lecopzer Chen <[email protected]>--- arch/arm64/kernel/kaslr.c | 18 ++++++++++-------- arch/arm64/kernel/module.c | 16 +++++++++------- 2 files changed, 19 insertions(+), 15 deletions(-)arch/arm64/kernel/kaslr.c +0
-0arch/arm64/kernel/kaslr.c u64 __init kaslr_early_init(u64 dt_phys) · line 165
Quoted 7 lines
arch/arm64/kernel/kaslr.c +2
-2@@ -161,15 +161,17 @@ u64 __init kaslr_early_init(u64 dt_phys)/* use the top 16 bits to randomize the linear region */ memstart_offset_seed = seed >>48 ; -if (IS_ENABLED (CONFIG_KASAN_GENERIC ) || -IS_ENABLED (CONFIG_KASAN_SW_TAGS )) + if (!IS_ENABLED(CONFIG_KASAN_VMALLOC) && + (IS_ENABLED(CONFIG_KASAN_GENERIC) ||
CONFIG_KASAN_VMALLOCdepends onCONFIG_KASAN_GENERICso why is this necessary?Quoted 1 line
Will
Quoted 7 lines
CONFIG_KASAN_VMALLOC=ymeansCONFIG_KASAN_GENERIC=ybutCONFIG_KASAN_GENERIC=ydoesn't meansCONFIG_KASAN_VMALLOC=ySo this if-condition allows only KASAN rather than KASAN +
KASAN_VMALLOCenabled.Please correct me if I'm wrong.
Sorry, you're completely right -- I missed the '!' when I read this initially.
Will
Dear reviewers and maintainers,
Could we have chance to upstream this in 5.12-rc?
So if these patches have any problem I can fix as soon as possible before next -rc comming.
thanks!
BRs,
Lecopzer
Quoted 38 lines · Lecopzer Chen
Linux supports KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Acroding to how x86 ported it [1], they early allocated p4d and pgd, but in arm64 I just simulate how KAsan supports
MODULES_VADDRin arm64 by not to populate the vmalloc area except for kimg address.Test environment:
4G and 8G Qemu virt,
39-bit VA + 4kPAGE_SIZEwith 3-level page table, test bylib/test_kasan.koandlib/test_kasan_module.koIt also works in Kaslr with
CONFIG_RANDOMIZE_MODULE_REGION_FULLand randomize module region inside vmalloc area.[1]: commit
0609ae011deb41c("x86/kasan: supportKASAN_VMALLOC")Signed-off-by Lecopzer Chen <[email protected]>Acked-by Andrey Konovalov <[email protected]>Tested-by Andrey Konovalov <[email protected]>v2 -> v1
1.kasan_init.ctweak indent
2. changeKconfigdepends only onHAVE_ARCH_KASAN
3. support randomized module region.v1:
https://lore.kernel.org/lkml/[email protected]/Lecopzer Chen (4):
arm64: kasan: don't populate vmalloc area forCONFIG_KASAN_VMALLOC
arm64: kasan: abstract_textand_endto KERNEL_START/END
arm64:Kconfig: supportCONFIG_KASAN_VMALLOC
arm64: kaslr: support randomized module area withKASAN_VMALLOC
Quoted 9 lines
arch/arm64/Kconfig | 1 + arch/arm64/kernel/kaslr.c | 18 ++++++++++-------- arch/arm64/kernel/module.c | 16 +++++++++------- arch/arm64/mm/kasan_init.c | 29 +++++++++++++++++++++-------- 4 files changed, 41 insertions(+), 23 deletions(-)--
2.25.1
Hi Will,
Could you PTAL at the arm64 changes?
Thanks!
Will Deacon
maintainerQuoted 45 lines · Andrey Konovalov
Quoted 44 lines · Lecopzer Chen
Linux supports KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Acroding to how x86 ported it [1], they early allocated p4d and pgd, but in arm64 I just simulate how KAsan supports
MODULES_VADDRin arm64 by not to populate the vmalloc area except for kimg address.Test environment:
4G and 8G Qemu virt,
39-bit VA + 4kPAGE_SIZEwith 3-level page table, test bylib/test_kasan.koandlib/test_kasan_module.koIt also works in Kaslr with
CONFIG_RANDOMIZE_MODULE_REGION_FULLand randomize module region inside vmalloc area.[1]: commit
0609ae011deb41c("x86/kasan: supportKASAN_VMALLOC")Signed-off-by Lecopzer Chen <[email protected]>Acked-by Andrey Konovalov <[email protected]>Tested-by Andrey Konovalov <[email protected]>v2 -> v1
1.kasan_init.ctweak indent
2. changeKconfigdepends only onHAVE_ARCH_KASAN
3. support randomized module region.v1:
https://lore.kernel.org/lkml/[email protected]/Lecopzer Chen (4):
arm64: kasan: don't populate vmalloc area forCONFIG_KASAN_VMALLOC
arm64: kasan: abstract_textand_endto KERNEL_START/END
arm64:Kconfig: supportCONFIG_KASAN_VMALLOC
arm64: kaslr: support randomized module area withKASAN_VMALLOCarch/arm64/Kconfig | 1 + arch/arm64/kernel/kaslr.c | 18 ++++++++++-------- arch/arm64/kernel/module.c | 16 +++++++++------- arch/arm64/mm/kasan_init.c | 29 +++++++++++++++++++++-------- 4 files changed, 41 insertions(+), 23 deletions(-)
Quoted 7 lines
Quoted 3 lines
--
2.25.1Hi Will,
Could you PTAL at the arm64 changes?
Sorry, wanted to get to this today but I ran out of time in the end. On the list for next week!
Will
Quoted 29 lines · Lecopzer Chen
Linux supports KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Acroding to how x86 ported it [1], they early allocated p4d and pgd, but in arm64 I just simulate how KAsan supports
MODULES_VADDRin arm64 by not to populate the vmalloc area except for kimg address.Test environment:
4G and 8G Qemu virt,
39-bit VA + 4kPAGE_SIZEwith 3-level page table, test bylib/test_kasan.koandlib/test_kasan_module.koIt also works in Kaslr with
CONFIG_RANDOMIZE_MODULE_REGION_FULLand randomize module region inside vmalloc area.[1]: commit
0609ae011deb41c("x86/kasan: supportKASAN_VMALLOC")Signed-off-by Lecopzer Chen <[email protected]>Acked-by Andrey Konovalov <[email protected]>Tested-by Andrey Konovalov <[email protected]>v2 -> v1
1.kasan_init.ctweak indent
2. changeKconfigdepends only onHAVE_ARCH_KASAN
3. support randomized module region.
Quoted 9 lines
v1:
https://lore.kernel.org/lkml/[email protected]/Lecopzer Chen (4):
arm64: kasan: don't populate vmalloc area forCONFIG_KASAN_VMALLOC
arm64: kasan: abstract_textand_endto KERNEL_START/END
arm64:Kconfig: supportCONFIG_KASAN_VMALLOC
arm64: kaslr: support randomized module area withKASAN_VMALLOC
I failed to realize that VMAP_STACK and KASAN are currently mutually exclusive on arm64, and that this series actually fixes that, which is a big improvement, so it would make sense to call that out.
This builds and runs fine for me on a VM running under KVM.
Will Deacon
maintainerQuoted 6 lines · Lecopzer Chen
Linux supports KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Acroding to how x86 ported it [1], they early allocated p4d and pgd, but in arm64 I just simulate how KAsan supports
MODULES_VADDRin arm64 by not to populate the vmalloc area except for kimg address.
The one thing I've failed to grok from your series is how you deal with vmalloc allocations where the shadow overlaps with the shadow which has already been allocated for the kernel image. Please can you explain?
Thanks,
Will
Quoted 11 lines · Lecopzer Chen
Quoted 6 lines
Linux supports KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Acroding to how x86 ported it [1], they early allocated p4d and pgd, but in arm64 I just simulate how KAsan supports
MODULES_VADDRin arm64 by not to populate the vmalloc area except for kimg address.The one thing I've failed to grok from your series is how you deal with vmalloc allocations where the shadow overlaps with the shadow which has already been allocated for the kernel image. Please can you explain?
The most key point is we don't map anything in the vmalloc shadow address. So we don't care where the kernel image locate inside vmalloc area.
kasan_map_populate(kimg_shadow_start, kimg_shadow_end,...)
Kernel image was populated with real mapping in its shadow address. I `bypass' the whole shadow of vmalloc area, the only place you can find about vmalloc_shadow is
kasan_populate_early_shadow((void *)vmalloc_shadow_end, (void *)KASAN_SHADOW_END); ----------- vmalloc_shadow_start | | | | | | <= non-mapping | | | | |-----------| |///////////|<- kimage shadow with page table mapping. |-----------| | | | | <= non-mapping | | ------------- vmalloc_shadow_end |00000000000| |00000000000| <= Zero shadow |00000000000|
------------- KASAN_SHADOW_END
vmalloc shadow will be mapped 'ondemend', see kasan_populate_vmalloc() in mm/vmalloc.c in detail.
So the shadow of vmalloc will be allocated later if anyone use its va.
BRs,
Lecopzer
Will Deacon
maintainerQuoted 40 lines · Lecopzer Chen
Quoted 11 lines · Lecopzer Chen
Quoted 6 lines
Linux supports KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Acroding to how x86 ported it [1], they early allocated p4d and pgd, but in arm64 I just simulate how KAsan supports
MODULES_VADDRin arm64 by not to populate the vmalloc area except for kimg address.The one thing I've failed to grok from your series is how you deal with vmalloc allocations where the shadow overlaps with the shadow which has already been allocated for the kernel image. Please can you explain?
The most key point is we don't map anything in the vmalloc shadow address. So we don't care where the kernel image locate inside vmalloc area.
kasan_map_populate(kimg_shadow_start, kimg_shadow_end,...)Kernel image was populated with real mapping in its shadow address. I `bypass' the whole shadow of vmalloc area, the only place you can find about
vmalloc_shadowiskasan_populate_early_shadow((void *)vmalloc_shadow_end, (void *)KASAN_SHADOW_END); ----------- vmalloc_shadow_start | | | | | | <= non-mapping | | | | |-----------| |///////////|<- kimage shadow with page table mapping. |-----------| | | | | <= non-mapping | | ------------- vmalloc_shadow_end |00000000000| |00000000000| <= Zero shadow |00000000000|
Quoted 5 lines
-------------
KASAN_SHADOW_ENDvmalloc shadow will be mapped 'ondemend', see
kasan_populate_vmalloc()inmm/vmalloc.cin detail.
So the shadow of vmalloc will be allocated later if anyone use its va.
Indeed, but the question I'm asking is what happens when an on-demand shadow allocation from vmalloc overlaps with the shadow that we allocated early for the kernel image?
Sounds like I have to go and read the code...
Will
Quoted 48 lines · Lecopzer Chen
Quoted 6 lines
Quoted 6 lines · Lecopzer Chen
Quoted 5 lines
Linux supports KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Acroding to how x86 ported it [1], they early allocated p4d and pgd, but in arm64 I just simulate how KAsan supports
MODULES_VADDRinarm64
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
by not to populate the vmalloc area except for kimg address.
The one thing I've failed to grok from your series is how you deal with vmalloc allocations where the shadow overlaps with the shadow which has already been allocated for the kernel image. Please can you explain?
The most key point is we don't map anything in the vmalloc shadow
address.
Quoted 26 lines
So we don't care where the kernel image locate inside vmalloc area.
kasan_map_populate(kimg_shadow_start, kimg_shadow_end,...)Kernel image was populated with real mapping in its shadow address. I `bypass' the whole shadow of vmalloc area, the only place you can find about
vmalloc_shadowiskasan_populate_early_shadow((void *)vmalloc_shadow_end, (void *)KASAN_SHADOW_END); ----------- vmalloc_shadow_start | | | | | | <= non-mapping | | | | |-----------| |///////////|<- kimage shadow with page table mapping. |-----------| | | | | <= non-mapping | | ------------- vmalloc_shadow_end |00000000000| |00000000000| <= Zero shadow |00000000000|Quoted 5 lines
-------------
KASAN_SHADOW_ENDvmalloc shadow will be mapped 'ondemend', see
kasan_populate_vmalloc()inmm/vmalloc.cin detail.
So the shadow of vmalloc will be allocated later if anyone use its va.
Quoted 8 lines
Indeed, but the question I'm asking is what happens when an on-demand shadow
allocation from vmalloc overlaps with the shadow that we allocated early for
the kernel image?Sounds like I have to go and read the code...
oh, sorry I misunderstood your question.
FWIW,
I think this won't happend because this mean vmalloc() provides va which already allocated by kimg, as I know, vmalloc_init() will insert early allocated vma into its vmalloc rb tree
Quoted 1 line
, and this early allocated vma will include kernel image.
After quick review of mm init code,
this early allocated for vma is at map_kernel() in arch/arm64/mm/mmu.c
BRs
Lecopzer
Quoted 47 lines · Lecopzer Chen
Quoted 40 lines
Quoted 11 lines · Lecopzer Chen
Quoted 6 lines
Linux supports KAsan for VMALLOC since commit
3c5c3cfb9ef4da9("kasan: support backing vmalloc space with real shadow memory")Acroding to how x86 ported it [1], they early allocated p4d and pgd, but in arm64 I just simulate how KAsan supports
MODULES_VADDRin arm64 by not to populate the vmalloc area except for kimg address.The one thing I've failed to grok from your series is how you deal with vmalloc allocations where the shadow overlaps with the shadow which has already been allocated for the kernel image. Please can you explain?
The most key point is we don't map anything in the vmalloc shadow address. So we don't care where the kernel image locate inside vmalloc area.
kasan_map_populate(kimg_shadow_start, kimg_shadow_end,...)Kernel image was populated with real mapping in its shadow address. I `bypass' the whole shadow of vmalloc area, the only place you can find about
vmalloc_shadowiskasan_populate_early_shadow((void *)vmalloc_shadow_end, (void *)KASAN_SHADOW_END); ----------- vmalloc_shadow_start | | | | | | <= non-mapping | | | | |-----------| |///////////|<- kimage shadow with page table mapping. |-----------| | | | | <= non-mapping | | ------------- vmalloc_shadow_end |00000000000| |00000000000| <= Zero shadow |00000000000|Quoted 5 lines
-------------
KASAN_SHADOW_ENDvmalloc shadow will be mapped 'ondemend', see
kasan_populate_vmalloc()inmm/vmalloc.cin detail.
So the shadow of vmalloc will be allocated later if anyone use its va.
Quoted 5 lines
Indeed, but the question I'm asking is what happens when an on-demand shadow allocation from vmalloc overlaps with the shadow that we allocated early for the kernel image?
Sounds like I have to go and read the code...
oh, sorry I misunderstood your question.
FWIW,
I think this won't happend because this mean vmalloc() provides va which already allocated by kimg, as I know, vmalloc_init() will insert early allocated vma into its vmalloc rb tree
, and this early allocated vma will include kernel image.
After quick review of mm init code,
this early allocated for vma is at map_kernel() in arch/arm64/mm/mmu.c
BRs
Lecopzer