diff mbox series

[v2,3/5] kasan, arm64: don't instrument functions that enable kasan

Message ID 26fb6165a17abcf61222eda5184c030fb6b133d1.1596544734.git.andreyknvl@google.com (mailing list archive)
State New, archived
Headers show
Series kasan: support stack instrumentation for tag-based mode | expand

Commit Message

Andrey Konovalov Aug. 4, 2020, 12:41 p.m. UTC
This patch prepares Software Tag-Based KASAN for stack tagging support.

With stack tagging enabled, KASAN tags stack variable in each function
in its prologue. In start_kernel() stack variables get tagged before KASAN
is enabled via setup_arch()->kasan_init(). As the result the tags for
start_kernel()'s stack variables end up in the temporary shadow memory.
Later when KASAN gets enabled, switched to normal shadow, and starts
checking tags, this leads to false-positive reports, as proper tags are
missing in normal shadow.

Disable KASAN instrumentation for start_kernel(). Also disable it for
arm64's setup_arch() as a precaution (it doesn't have any stack variables
right now).

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
 arch/arm64/kernel/setup.c | 2 +-
 init/main.c               | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Catalin Marinas Aug. 4, 2020, 1:19 p.m. UTC | #1
On Tue, Aug 04, 2020 at 02:41:26PM +0200, Andrey Konovalov wrote:
> This patch prepares Software Tag-Based KASAN for stack tagging support.
> 
> With stack tagging enabled, KASAN tags stack variable in each function
> in its prologue. In start_kernel() stack variables get tagged before KASAN
> is enabled via setup_arch()->kasan_init(). As the result the tags for
> start_kernel()'s stack variables end up in the temporary shadow memory.
> Later when KASAN gets enabled, switched to normal shadow, and starts
> checking tags, this leads to false-positive reports, as proper tags are
> missing in normal shadow.
> 
> Disable KASAN instrumentation for start_kernel(). Also disable it for
> arm64's setup_arch() as a precaution (it doesn't have any stack variables
> right now).
> 
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>

I thought I acked this already. Either way:

Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Andrey Konovalov Aug. 4, 2020, 1:24 p.m. UTC | #2
On Tue, Aug 4, 2020 at 3:19 PM Catalin Marinas <catalin.marinas@arm.com> wrote:
>
> On Tue, Aug 04, 2020 at 02:41:26PM +0200, Andrey Konovalov wrote:
> > This patch prepares Software Tag-Based KASAN for stack tagging support.
> >
> > With stack tagging enabled, KASAN tags stack variable in each function
> > in its prologue. In start_kernel() stack variables get tagged before KASAN
> > is enabled via setup_arch()->kasan_init(). As the result the tags for
> > start_kernel()'s stack variables end up in the temporary shadow memory.
> > Later when KASAN gets enabled, switched to normal shadow, and starts
> > checking tags, this leads to false-positive reports, as proper tags are
> > missing in normal shadow.
> >
> > Disable KASAN instrumentation for start_kernel(). Also disable it for
> > arm64's setup_arch() as a precaution (it doesn't have any stack variables
> > right now).
> >
> > Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
>
> I thought I acked this already. Either way:
>
> Acked-by: Catalin Marinas <catalin.marinas@arm.com>

Sorry, I forgot to include that into v2. Thanks!
diff mbox series

Patch

diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 93b3844cf442..575da075a2b9 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -276,7 +276,7 @@  arch_initcall(reserve_memblock_reserved_regions);
 
 u64 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID };
 
-void __init setup_arch(char **cmdline_p)
+void __init __no_sanitize_address setup_arch(char **cmdline_p)
 {
 	init_mm.start_code = (unsigned long) _text;
 	init_mm.end_code   = (unsigned long) _etext;
diff --git a/init/main.c b/init/main.c
index 0ead83e86b5a..7e5e25d9fe42 100644
--- a/init/main.c
+++ b/init/main.c
@@ -827,7 +827,7 @@  void __init __weak arch_call_rest_init(void)
 	rest_init();
 }
 
-asmlinkage __visible void __init start_kernel(void)
+asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
 {
 	char *command_line;
 	char *after_dashes;