Skip to content

Commit 0fea6e9

Browse files
xairytorvalds
authored andcommitted
kasan, arm64: expand CONFIG_KASAN checks
Some #ifdef CONFIG_KASAN checks are only relevant for software KASAN modes (either related to shadow memory or compiler instrumentation). Expand those into CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS. Link: https://lkml.kernel.org/r/e6971e432dbd72bb897ff14134ebb7e169bdcf0c.1606161801.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Reviewed-by: Alexander Potapenko <glider@google.com> Tested-by: Vincenzo 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: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8a49402 commit 0fea6e9

16 files changed

Lines changed: 36 additions & 25 deletions

File tree

‎arch/arm64/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ config BROKEN_GAS_INST
334334

335335
config KASAN_SHADOW_OFFSET
336336
hex
337-
depends on KASAN
337+
depends on KASAN_GENERIC || KASAN_SW_TAGS
338338
default 0xdfff800000000000 if (ARM64_VA_BITS_48 || ARM64_VA_BITS_52) && !KASAN_SW_TAGS
339339
default 0xdfffc00000000000 if ARM64_VA_BITS_47 && !KASAN_SW_TAGS
340340
default 0xdffffe0000000000 if ARM64_VA_BITS_42 && !KASAN_SW_TAGS

‎arch/arm64/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ head-y := arch/arm64/kernel/head.o
137137

138138
ifeq ($(CONFIG_KASAN_SW_TAGS), y)
139139
KASAN_SHADOW_SCALE_SHIFT := 4
140-
else
140+
else ifeq ($(CONFIG_KASAN_GENERIC), y)
141141
KASAN_SHADOW_SCALE_SHIFT := 3
142142
endif
143143

‎arch/arm64/include/asm/assembler.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ USER(\label, ic ivau, \tmp2) // invalidate I line PoU
473473
#define NOKPROBE(x)
474474
#endif
475475

476-
#ifdef CONFIG_KASAN
476+
#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
477477
#define EXPORT_SYMBOL_NOKASAN(name)
478478
#else
479479
#define EXPORT_SYMBOL_NOKASAN(name) EXPORT_SYMBOL(name)

‎arch/arm64/include/asm/memory.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
* address space for the shadow region respectively. They can bloat the stack
7373
* significantly, so double the (minimum) stack size when they are in use.
7474
*/
75-
#ifdef CONFIG_KASAN
75+
#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
7676
#define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL)
7777
#define KASAN_SHADOW_END ((UL(1) << (64 - KASAN_SHADOW_SCALE_SHIFT)) \
7878
+ KASAN_SHADOW_OFFSET)

‎arch/arm64/include/asm/string.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifndef __ASM_STRING_H
66
#define __ASM_STRING_H
77

8-
#ifndef CONFIG_KASAN
8+
#if !(defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS))
99
#define __HAVE_ARCH_STRRCHR
1010
extern char *strrchr(const char *, int c);
1111

@@ -48,7 +48,8 @@ extern void *__memset(void *, int, __kernel_size_t);
4848
void memcpy_flushcache(void *dst, const void *src, size_t cnt);
4949
#endif
5050

51-
#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)
51+
#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \
52+
!defined(__SANITIZE_ADDRESS__)
5253

5354
/*
5455
* For files that are not instrumented (e.g. mm/slub.c) we

‎arch/arm64/kernel/head.S‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ SYM_FUNC_START_LOCAL(__primary_switched)
433433
bl __pi_memset
434434
dsb ishst // Make zero page visible to PTW
435435

436-
#ifdef CONFIG_KASAN
436+
#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
437437
bl kasan_early_init
438438
#endif
439439
#ifdef CONFIG_RANDOMIZE_BASE

‎arch/arm64/kernel/image-vars.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ __efistub_strncmp = __pi_strncmp;
3737
__efistub_strrchr = __pi_strrchr;
3838
__efistub___clean_dcache_area_poc = __pi___clean_dcache_area_poc;
3939

40-
#ifdef CONFIG_KASAN
40+
#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
4141
__efistub___memcpy = __pi_memcpy;
4242
__efistub___memmove = __pi_memmove;
4343
__efistub___memset = __pi_memset;

‎arch/arm64/kernel/kaslr.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ u64 __init kaslr_early_init(u64 dt_phys)
161161
/* use the top 16 bits to randomize the linear region */
162162
memstart_offset_seed = seed >> 48;
163163

164-
if (IS_ENABLED(CONFIG_KASAN))
164+
if (IS_ENABLED(CONFIG_KASAN_GENERIC) ||
165+
IS_ENABLED(CONFIG_KASAN_SW_TAGS))
165166
/*
166167
* KASAN does not expect the module region to intersect the
167168
* vmalloc region, since shadow memory is allocated for each

‎arch/arm64/kernel/module.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ void *module_alloc(unsigned long size)
3030
if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS))
3131
gfp_mask |= __GFP_NOWARN;
3232

33-
if (IS_ENABLED(CONFIG_KASAN))
33+
if (IS_ENABLED(CONFIG_KASAN_GENERIC) ||
34+
IS_ENABLED(CONFIG_KASAN_SW_TAGS))
3435
/* don't exceed the static module region - see below */
3536
module_alloc_end = MODULES_END;
3637

@@ -39,7 +40,8 @@ void *module_alloc(unsigned long size)
3940
NUMA_NO_NODE, __builtin_return_address(0));
4041

4142
if (!p && IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) &&
42-
!IS_ENABLED(CONFIG_KASAN))
43+
!IS_ENABLED(CONFIG_KASAN_GENERIC) &&
44+
!IS_ENABLED(CONFIG_KASAN_SW_TAGS))
4345
/*
4446
* KASAN can only deal with module allocations being served
4547
* from the reserved module region, since the remainder of

‎arch/arm64/mm/ptdump.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
enum address_markers_idx {
3030
PAGE_OFFSET_NR = 0,
3131
PAGE_END_NR,
32-
#ifdef CONFIG_KASAN
32+
#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
3333
KASAN_START_NR,
3434
#endif
3535
};
3636

3737
static struct addr_marker address_markers[] = {
3838
{ PAGE_OFFSET, "Linear Mapping start" },
3939
{ 0 /* PAGE_END */, "Linear Mapping end" },
40-
#ifdef CONFIG_KASAN
40+
#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
4141
{ 0 /* KASAN_SHADOW_START */, "Kasan shadow start" },
4242
{ KASAN_SHADOW_END, "Kasan shadow end" },
4343
#endif
@@ -383,7 +383,7 @@ void ptdump_check_wx(void)
383383
static int ptdump_init(void)
384384
{
385385
address_markers[PAGE_END_NR].start_address = PAGE_END;
386-
#ifdef CONFIG_KASAN
386+
#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
387387
address_markers[KASAN_START_NR].start_address = KASAN_SHADOW_START;
388388
#endif
389389
ptdump_initialize();

0 commit comments

Comments
 (0)