Commit 7b449a04 authored by Andrey Konovalov's avatar Andrey Konovalov Committed by Stephen Rothwell
Browse files

kasan: shadow declarations only for software modes

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

Group shadow-related KASAN function declarations and only define them for
the two existing software modes.

No functional changes for software modes.

Link: https://lkml.kernel.org/r/e88d94eff94db883a65dca52e1736d80d28dd9bc.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: default avatarMarco Elver <elver@google.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: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Evgenii Stepanov <eugenis@google.com>
Cc: Kevin Brodsky <kevin.brodsky@arm.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 f6352101
...@@ -11,7 +11,6 @@ struct task_struct; ...@@ -11,7 +11,6 @@ struct task_struct;
#ifdef CONFIG_KASAN #ifdef CONFIG_KASAN
#include <linux/pgtable.h>
#include <asm/kasan.h> #include <asm/kasan.h>
/* kasan_data struct is used in KUnit tests for KASAN expected failures */ /* kasan_data struct is used in KUnit tests for KASAN expected failures */
...@@ -20,6 +19,20 @@ struct kunit_kasan_expectation { ...@@ -20,6 +19,20 @@ struct kunit_kasan_expectation {
bool report_found; bool report_found;
}; };
#endif
#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
#include <linux/pgtable.h>
/* Software KASAN implementations use shadow memory. */
#ifdef CONFIG_KASAN_SW_TAGS
#define KASAN_SHADOW_INIT 0xFF
#else
#define KASAN_SHADOW_INIT 0
#endif
extern unsigned char kasan_early_shadow_page[PAGE_SIZE]; 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];
extern pmd_t kasan_early_shadow_pmd[PTRS_PER_PMD]; extern pmd_t kasan_early_shadow_pmd[PTRS_PER_PMD];
...@@ -35,6 +48,23 @@ static inline void *kasan_mem_to_shadow(const void *addr) ...@@ -35,6 +48,23 @@ static inline void *kasan_mem_to_shadow(const void *addr)
+ KASAN_SHADOW_OFFSET; + KASAN_SHADOW_OFFSET;
} }
int kasan_add_zero_shadow(void *start, unsigned long size);
void kasan_remove_zero_shadow(void *start, unsigned long size);
#else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */
static inline int kasan_add_zero_shadow(void *start, unsigned long size)
{
return 0;
}
static inline void kasan_remove_zero_shadow(void *start,
unsigned long size)
{}
#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */
#ifdef CONFIG_KASAN
/* Enable reporting bugs after kasan_disable_current() */ /* Enable reporting bugs after kasan_disable_current() */
extern void kasan_enable_current(void); extern void kasan_enable_current(void);
...@@ -75,9 +105,6 @@ struct kasan_cache { ...@@ -75,9 +105,6 @@ struct kasan_cache {
int free_meta_offset; int free_meta_offset;
}; };
int kasan_add_zero_shadow(void *start, unsigned long size);
void kasan_remove_zero_shadow(void *start, unsigned long size);
size_t __ksize(const void *); size_t __ksize(const void *);
static inline void kasan_unpoison_slab(const void *ptr) static inline void kasan_unpoison_slab(const void *ptr)
{ {
...@@ -143,14 +170,6 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, ...@@ -143,14 +170,6 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object,
return false; return false;
} }
static inline int kasan_add_zero_shadow(void *start, unsigned long size)
{
return 0;
}
static inline void kasan_remove_zero_shadow(void *start,
unsigned long size)
{}
static inline void kasan_unpoison_slab(const void *ptr) { } static inline void kasan_unpoison_slab(const void *ptr) { }
static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; }
...@@ -158,8 +177,6 @@ static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } ...@@ -158,8 +177,6 @@ static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; }
#ifdef CONFIG_KASAN_GENERIC #ifdef CONFIG_KASAN_GENERIC
#define KASAN_SHADOW_INIT 0
void kasan_cache_shrink(struct kmem_cache *cache); void kasan_cache_shrink(struct kmem_cache *cache);
void kasan_cache_shutdown(struct kmem_cache *cache); void kasan_cache_shutdown(struct kmem_cache *cache);
void kasan_record_aux_stack(void *ptr); void kasan_record_aux_stack(void *ptr);
...@@ -174,8 +191,6 @@ static inline void kasan_record_aux_stack(void *ptr) {} ...@@ -174,8 +191,6 @@ static inline void kasan_record_aux_stack(void *ptr) {}
#ifdef CONFIG_KASAN_SW_TAGS #ifdef CONFIG_KASAN_SW_TAGS
#define KASAN_SHADOW_INIT 0xFF
void kasan_init_tags(void); void kasan_init_tags(void);
void *kasan_reset_tag(const void *addr); void *kasan_reset_tag(const void *addr);
......
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