[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Cc: [email protected], [email protected], [email protected],
[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Bcc: [email protected]
Subject: Re: [PATCH v2 00/12] mm/kasan: make kasan=on|off work for all three
modes
Reply-To:
In-Reply-To: <[email protected]>
Forgot adding related ARCH mailing list or people to CC, add them.
Quoted 102 lines · Baoquan He
Currently only
hw_tagsmode of kasan can be enabled or disabled with kernel parameter kasan=on|off for built kernel. For kasan generic andsw_tagsmode, there's no way to disable them once kernel is built. This is not convenient sometime, e.g in system kdump is configured. When the 1st kernel has KASAN enabled and crash triggered to switch to kdump kernel, the generic orsw_tagsmode will cost much extra memory for kasan shadow while in fact it's meaningless to have kasan in kdump kernel.So this patchset moves the kasan=on|off out of
hw_tagsscope and into common code to make it visible in generic andsw_tagsmode too. Then we can add kasan=off in kdump kernel to reduce the unneeded meomry cost for kasan.Changelog:
====v1->v2:
- Add__ro_after_initfor__ro_after_init, and remove redundant blank lines inmm/kasan/common.c. Thanks to Marco.
- Fix a code bug in <linux/kasan-enabled.h> whenCONFIG_KASANis unset, this is found out by SeongJae and Lorenzo, and also reported by LKP report, thanks to them.
- Add a missingkasan_enabled()checking inkasan_report(). This will cause below KASAN report info even though kasan=off is set:================================================================== BUG: KASAN: stack-out-of-bounds in tick_program_event+0x130/0x150 Read of size 4 at addr ffff00005f747778 by task swapper/0/1 CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.16.0+ #8 PREEMPT(voluntary) Hardware name: GIGABYTE R272-P30-JG/MP32-AR0-JG, BIOS F31n (SCP: 2.10.20220810) 09/30/2022 Call trace: show_stack+0x30/0x90 (C) dump_stack_lvl+0x7c/0xa0 print_address_description.constprop.0+0x90/0x310 print_report+0x104/0x1f0 kasan_report+0xc8/0x110 __asan_report_load4_noabort+0x20/0x30 tick_program_event+0x130/0x150 ......snip... ==================================================================- Add
jump_label_init()calling beforekasan_init()insetup_arch()in these
architectures: xtensa, arm. Because they currenly rely onjump_label_init()inmain()which is a little late. Then the early static keykasan_flag_enabledinkasan_init()won't work.- In UML architecture, change to enable
kasan_flag_enabledinarch_mm_preinit()becausekasan_init()is enabled beforemain(), there's no chance to operate on static key inkasan_init().Test:
=====
In v1, I took test onx86_64for generic mode, and on arm64 for generic,sw_tagsandhw_tagsmode. All of them works well.In v2, I only tested on arm64 for generic,
sw_tagsandhw_tagsmode, it works. For powerpc, I got a BOOK3S/64 machine, while it says 'KASAN not enabled as it requires radix' and KASAN is disabled. Will look for other POWER machine to test this.
====Baoquan He (12):
mm/kasan: add conditional checks in functions to return directly if
kasan is disabled
mm/kasan: move kasan= code to common placemm/kasan/sw_tags: don't initialize kasan if it's disabledarch/arm: don't initialize kasan if it's disabledarch/arm64: don't initialize kasan if it's disabledarch/loongarch: don't initialize kasan if it's disabledarch/powerpc: don't initialize kasan if it's disabledarch/riscv: don't initialize kasan if it's disabledarch/x86: don't initialize kasan if it's disabledarch/xtensa: don't initialize kasan if it's disabledarch/um: don't initialize kasan if it's disabled mm/kasan: make kasan=on|off take effect for all three modesarch/arm/kernel/setup.c | 6 +++++ arch/arm/mm/kasan_init.c | 6 +++++ arch/arm64/mm/kasan_init.c | 7 ++++++ arch/loongarch/mm/kasan_init.c | 5 ++++ arch/powerpc/mm/kasan/init_32.c | 8 +++++- arch/powerpc/mm/kasan/init_book3e_64.c | 6 +++++ arch/powerpc/mm/kasan/init_book3s_64.c | 6 +++++ arch/riscv/mm/kasan_init.c | 6 +++++ arch/um/kernel/mem.c | 6 +++++ arch/x86/mm/kasan_init_64.c | 6 +++++ arch/xtensa/kernel/setup.c | 1 + arch/xtensa/mm/kasan_init.c | 6 +++++ include/linux/kasan-enabled.h | 18 ++++++------- mm/kasan/common.c | 25 ++++++++++++++++++ mm/kasan/generic.c | 20 +++++++++++++-- mm/kasan/hw_tags.c | 35 ++------------------------ mm/kasan/init.c | 6 +++++ mm/kasan/quarantine.c | 3 +++ mm/kasan/report.c | 4 ++- mm/kasan/shadow.c | 23 ++++++++++++++++- mm/kasan/sw_tags.c | 9 +++++++ 21 files changed, 165 insertions(+), 47 deletions(-)Signature · 1 line
2.41.0
Quoted 16 lines · Baoquan He
[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Cc: [email protected], [email protected], [email protected],
[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Bcc: [email protected]
Subject: Re: [PATCH v2 00/12] mm/kasan: make kasan=on|off work for all three
modes
Reply-To:
In-Reply-To: <[email protected]>
Quoted 1 line
Forgot adding related ARCH mailing list or people to CC, add them.
Sorry for the noise, I made mistake on mail format when adding people to CC.
Quoted 106 lines · Baoquan He
Quoted 102 lines
Currently only
hw_tagsmode of kasan can be enabled or disabled with kernel parameter kasan=on|off for built kernel. For kasan generic andsw_tagsmode, there's no way to disable them once kernel is built. This is not convenient sometime, e.g in system kdump is configured. When the 1st kernel has KASAN enabled and crash triggered to switch to kdump kernel, the generic orsw_tagsmode will cost much extra memory for kasan shadow while in fact it's meaningless to have kasan in kdump kernel.So this patchset moves the kasan=on|off out of
hw_tagsscope and into common code to make it visible in generic andsw_tagsmode too. Then we can add kasan=off in kdump kernel to reduce the unneeded meomry cost for kasan.Changelog:
====v1->v2:
- Add__ro_after_initfor__ro_after_init, and remove redundant blank lines inmm/kasan/common.c. Thanks to Marco.
- Fix a code bug in <linux/kasan-enabled.h> whenCONFIG_KASANis unset, this is found out by SeongJae and Lorenzo, and also reported by LKP report, thanks to them.
- Add a missingkasan_enabled()checking inkasan_report(). This will cause below KASAN report info even though kasan=off is set:================================================================== BUG: KASAN: stack-out-of-bounds in tick_program_event+0x130/0x150 Read of size 4 at addr ffff00005f747778 by task swapper/0/1 CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.16.0+ #8 PREEMPT(voluntary) Hardware name: GIGABYTE R272-P30-JG/MP32-AR0-JG, BIOS F31n (SCP: 2.10.20220810) 09/30/2022 Call trace: show_stack+0x30/0x90 (C) dump_stack_lvl+0x7c/0xa0 print_address_description.constprop.0+0x90/0x310 print_report+0x104/0x1f0 kasan_report+0xc8/0x110 __asan_report_load4_noabort+0x20/0x30 tick_program_event+0x130/0x150 ......snip... ==================================================================- Add
jump_label_init()calling beforekasan_init()insetup_arch()in these
architectures: xtensa, arm. Because they currenly rely onjump_label_init()inmain()which is a little late. Then the early static keykasan_flag_enabledinkasan_init()won't work.- In UML architecture, change to enable
kasan_flag_enabledinarch_mm_preinit()becausekasan_init()is enabled beforemain(), there's no chance to operate on static key inkasan_init().Test:
=====
In v1, I took test onx86_64for generic mode, and on arm64 for generic,sw_tagsandhw_tagsmode. All of them works well.In v2, I only tested on arm64 for generic,
sw_tagsandhw_tagsmode, it works. For powerpc, I got a BOOK3S/64 machine, while it says 'KASAN not enabled as it requires radix' and KASAN is disabled. Will look for other POWER machine to test this.
====Baoquan He (12):
mm/kasan: add conditional checks in functions to return directly if
kasan is disabled
mm/kasan: move kasan= code to common placemm/kasan/sw_tags: don't initialize kasan if it's disabledarch/arm: don't initialize kasan if it's disabledarch/arm64: don't initialize kasan if it's disabledarch/loongarch: don't initialize kasan if it's disabledarch/powerpc: don't initialize kasan if it's disabledarch/riscv: don't initialize kasan if it's disabledarch/x86: don't initialize kasan if it's disabledarch/xtensa: don't initialize kasan if it's disabledarch/um: don't initialize kasan if it's disabled mm/kasan: make kasan=on|off take effect for all three modesarch/arm/kernel/setup.c | 6 +++++ arch/arm/mm/kasan_init.c | 6 +++++ arch/arm64/mm/kasan_init.c | 7 ++++++ arch/loongarch/mm/kasan_init.c | 5 ++++ arch/powerpc/mm/kasan/init_32.c | 8 +++++- arch/powerpc/mm/kasan/init_book3e_64.c | 6 +++++ arch/powerpc/mm/kasan/init_book3s_64.c | 6 +++++ arch/riscv/mm/kasan_init.c | 6 +++++ arch/um/kernel/mem.c | 6 +++++ arch/x86/mm/kasan_init_64.c | 6 +++++ arch/xtensa/kernel/setup.c | 1 + arch/xtensa/mm/kasan_init.c | 6 +++++ include/linux/kasan-enabled.h | 18 ++++++------- mm/kasan/common.c | 25 ++++++++++++++++++ mm/kasan/generic.c | 20 +++++++++++++-- mm/kasan/hw_tags.c | 35 ++------------------------ mm/kasan/init.c | 6 +++++ mm/kasan/quarantine.c | 3 +++ mm/kasan/report.c | 4 ++- mm/kasan/shadow.c | 23 ++++++++++++++++- mm/kasan/sw_tags.c | 9 +++++++ 21 files changed, 165 insertions(+), 47 deletions(-)Signature · 1 line
2.41.0