Commit 1b85b468 authored by Andrey Konovalov's avatar Andrey Konovalov Committed by Stephen Rothwell
Browse files

kasan, arm64: only use kasan_depth for software modes

This is a preparatory commit for the upcoming addition of a new hardware
tag-based (MTE-based) KASAN mode.

Hardware tag-based KASAN won't use kasan_depth.  Only define and use it
when one of the software KASAN modes are enabled.

No functional changes for software modes.

Link: https://lkml.kernel.org/r/e16f15aeda90bc7fb4dfc2e243a14b74cc5c8219.1606161801.git.andreyknvl@google.com

Signed-off-by: default avatarAndrey Konovalov <andreyknvl@google.com>
Signed-off-by: Vincenzo Frascino's avatarVincenzo Frascino <vincenzo.frascino@arm.com>
Reviewed-by: Catalin Marinas's avatarCatalin Marinas <catalin.marinas@arm.com>
Reviewed-by: default avatarAlexander Potapenko <glider@google.com>
Tested-by: Vincenzo Frascino's avatarVincenzo Frascino <vincenzo.frascino@arm.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Branislav Rankov <Branislav.Rankov@arm.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Evgenii Stepanov <eugenis@google.com>
Cc: Kevin Brodsky <kevin.brodsky@arm.com>
Cc: Marco Elver <elver@google.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
parent 1a315c34
...@@ -273,17 +273,22 @@ static void __init kasan_init_shadow(void) ...@@ -273,17 +273,22 @@ static void __init kasan_init_shadow(void)
cpu_replace_ttbr1(lm_alias(swapper_pg_dir)); cpu_replace_ttbr1(lm_alias(swapper_pg_dir));
} }
static void __init kasan_init_depth(void)
{
init_task.kasan_depth = 0;
}
#else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) */ #else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) */
static inline void __init kasan_init_shadow(void) { } static inline void __init kasan_init_shadow(void) { }
static inline void __init kasan_init_depth(void) { }
#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */
void __init kasan_init(void) void __init kasan_init(void)
{ {
kasan_init_shadow(); kasan_init_shadow();
kasan_init_depth();
/* At this point kasan is fully initialized. Enable error messages */
init_task.kasan_depth = 0;
pr_info("KernelAddressSanitizer initialized\n"); pr_info("KernelAddressSanitizer initialized\n");
} }
...@@ -51,6 +51,12 @@ static inline void *kasan_mem_to_shadow(const void *addr) ...@@ -51,6 +51,12 @@ static inline void *kasan_mem_to_shadow(const void *addr)
int kasan_add_zero_shadow(void *start, unsigned long size); int kasan_add_zero_shadow(void *start, unsigned long size);
void kasan_remove_zero_shadow(void *start, unsigned long size); void kasan_remove_zero_shadow(void *start, unsigned long size);
/* Enable reporting bugs after kasan_disable_current() */
extern void kasan_enable_current(void);
/* Disable reporting bugs for current task */
extern void kasan_disable_current(void);
#else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ #else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */
static inline int kasan_add_zero_shadow(void *start, unsigned long size) static inline int kasan_add_zero_shadow(void *start, unsigned long size)
...@@ -61,16 +67,13 @@ static inline void kasan_remove_zero_shadow(void *start, ...@@ -61,16 +67,13 @@ static inline void kasan_remove_zero_shadow(void *start,
unsigned long size) unsigned long size)
{} {}
static inline void kasan_enable_current(void) {}
static inline void kasan_disable_current(void) {}
#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */
#ifdef CONFIG_KASAN #ifdef CONFIG_KASAN
/* Enable reporting bugs after kasan_disable_current() */
extern void kasan_enable_current(void);
/* Disable reporting bugs for current task */
extern void kasan_disable_current(void);
void kasan_unpoison_range(const void *address, size_t size); void kasan_unpoison_range(const void *address, size_t size);
void kasan_unpoison_task_stack(struct task_struct *task); void kasan_unpoison_task_stack(struct task_struct *task);
...@@ -121,9 +124,6 @@ static inline void kasan_unpoison_range(const void *address, size_t size) {} ...@@ -121,9 +124,6 @@ static inline void kasan_unpoison_range(const void *address, size_t size) {}
static inline void kasan_unpoison_task_stack(struct task_struct *task) {} static inline void kasan_unpoison_task_stack(struct task_struct *task) {}
static inline void kasan_enable_current(void) {}
static inline void kasan_disable_current(void) {}
static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} static inline void kasan_alloc_pages(struct page *page, unsigned int order) {}
static inline void kasan_free_pages(struct page *page, unsigned int order) {} static inline void kasan_free_pages(struct page *page, unsigned int order) {}
......
...@@ -1225,7 +1225,7 @@ struct task_struct { ...@@ -1225,7 +1225,7 @@ struct task_struct {
u64 timer_slack_ns; u64 timer_slack_ns;
u64 default_timer_slack_ns; u64 default_timer_slack_ns;
#ifdef CONFIG_KASAN #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
unsigned int kasan_depth; unsigned int kasan_depth;
#endif #endif
......
...@@ -176,7 +176,7 @@ struct task_struct init_task ...@@ -176,7 +176,7 @@ struct task_struct init_task
.numa_group = NULL, .numa_group = NULL,
.numa_faults = NULL, .numa_faults = NULL,
#endif #endif
#ifdef CONFIG_KASAN #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
.kasan_depth = 1, .kasan_depth = 1,
#endif #endif
#ifdef CONFIG_KCSAN #ifdef CONFIG_KCSAN
......
...@@ -47,6 +47,7 @@ void kasan_set_track(struct kasan_track *track, gfp_t flags) ...@@ -47,6 +47,7 @@ void kasan_set_track(struct kasan_track *track, gfp_t flags)
track->stack = kasan_save_stack(flags); track->stack = kasan_save_stack(flags);
} }
#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
void kasan_enable_current(void) void kasan_enable_current(void)
{ {
current->kasan_depth++; current->kasan_depth++;
...@@ -56,6 +57,7 @@ void kasan_disable_current(void) ...@@ -56,6 +57,7 @@ void kasan_disable_current(void)
{ {
current->kasan_depth--; current->kasan_depth--;
} }
#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */
void kasan_unpoison_range(const void *address, size_t size) void kasan_unpoison_range(const void *address, size_t size)
{ {
......
...@@ -292,8 +292,10 @@ static void print_shadow_for_address(const void *addr) ...@@ -292,8 +292,10 @@ static void print_shadow_for_address(const void *addr)
static bool report_enabled(void) static bool report_enabled(void)
{ {
#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
if (current->kasan_depth) if (current->kasan_depth)
return false; return false;
#endif
if (test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags)) if (test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags))
return true; return true;
return !test_and_set_bit(KASAN_BIT_REPORTED, &kasan_flags); return !test_and_set_bit(KASAN_BIT_REPORTED, &kasan_flags);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment