forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kasan, arm64: implement HW_TAGS runtime
Provide implementation of KASAN functions required for the hardware tag-based mode. Those include core functions for memory and pointer tagging (tags_hw.c) and bug reporting (report_tags_hw.c). Also adapt common KASAN code to support the new mode. Link: https://lkml.kernel.org/r/cfd0fbede579a6b66755c98c88c108e54f9c56bf.1606161801.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov <[email protected]> Signed-off-by: Vincenzo Frascino <[email protected]> Acked-by: Catalin Marinas <[email protected]> Reviewed-by: Alexander Potapenko <[email protected]> Tested-by: Vincenzo Frascino <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Branislav Rankov <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Evgenii Stepanov <[email protected]> Cc: Kevin Brodsky <[email protected]> Cc: Marco Elver <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
- Loading branch information
Showing
14 changed files
with
178 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* This file contains core hardware tag-based KASAN code. | ||
* | ||
* Copyright (c) 2020 Google, Inc. | ||
* Author: Andrey Konovalov <[email protected]> | ||
*/ | ||
|
||
#define pr_fmt(fmt) "kasan: " fmt | ||
|
||
#include <linux/kasan.h> | ||
#include <linux/kernel.h> | ||
#include <linux/memory.h> | ||
#include <linux/mm.h> | ||
#include <linux/string.h> | ||
#include <linux/types.h> | ||
|
||
#include "kasan.h" | ||
|
||
/* kasan_init_hw_tags_cpu() is called for each CPU. */ | ||
void kasan_init_hw_tags_cpu(void) | ||
{ | ||
hw_init_tags(KASAN_TAG_MAX); | ||
hw_enable_tagging(); | ||
} | ||
|
||
/* kasan_init_hw_tags() is called once on boot CPU. */ | ||
void __init kasan_init_hw_tags(void) | ||
{ | ||
pr_info("KernelAddressSanitizer initialized\n"); | ||
} | ||
|
||
void *kasan_reset_tag(const void *addr) | ||
{ | ||
return reset_tag(addr); | ||
} | ||
|
||
void poison_range(const void *address, size_t size, u8 value) | ||
{ | ||
hw_set_mem_tag_range(reset_tag(address), | ||
round_up(size, KASAN_GRANULE_SIZE), value); | ||
} | ||
|
||
void unpoison_range(const void *address, size_t size) | ||
{ | ||
hw_set_mem_tag_range(reset_tag(address), | ||
round_up(size, KASAN_GRANULE_SIZE), get_tag(address)); | ||
} | ||
|
||
u8 random_tag(void) | ||
{ | ||
return hw_get_random_tag(); | ||
} | ||
|
||
bool check_invalid_free(void *addr) | ||
{ | ||
u8 ptr_tag = get_tag(addr); | ||
u8 mem_tag = hw_get_mem_tag(addr); | ||
|
||
return (mem_tag == KASAN_TAG_INVALID) || | ||
(ptr_tag != KASAN_TAG_KERNEL && ptr_tag != mem_tag); | ||
} | ||
|
||
void kasan_set_free_info(struct kmem_cache *cache, | ||
void *object, u8 tag) | ||
{ | ||
struct kasan_alloc_meta *alloc_meta; | ||
|
||
alloc_meta = get_alloc_info(cache, object); | ||
kasan_set_track(&alloc_meta->free_track[0], GFP_NOWAIT); | ||
} | ||
|
||
struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, | ||
void *object, u8 tag) | ||
{ | ||
struct kasan_alloc_meta *alloc_meta; | ||
|
||
alloc_meta = get_alloc_info(cache, object); | ||
return &alloc_meta->free_track[0]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* This file contains hardware tag-based KASAN specific error reporting code. | ||
* | ||
* Copyright (c) 2020 Google, Inc. | ||
* Author: Andrey Konovalov <[email protected]> | ||
*/ | ||
|
||
#include <linux/kasan.h> | ||
#include <linux/kernel.h> | ||
#include <linux/memory.h> | ||
#include <linux/mm.h> | ||
#include <linux/string.h> | ||
#include <linux/types.h> | ||
|
||
#include "kasan.h" | ||
|
||
const char *get_bug_type(struct kasan_access_info *info) | ||
{ | ||
return "invalid-access"; | ||
} | ||
|
||
void *find_first_bad_addr(void *addr, size_t size) | ||
{ | ||
return reset_tag(addr); | ||
} | ||
|
||
void metadata_fetch_row(char *buffer, void *row) | ||
{ | ||
int i; | ||
|
||
for (i = 0; i < META_BYTES_PER_ROW; i++) | ||
buffer[i] = hw_get_mem_tag(row + i * KASAN_GRANULE_SIZE); | ||
} | ||
|
||
void print_tags(u8 addr_tag, const void *addr) | ||
{ | ||
u8 memory_tag = hw_get_mem_tag((void *)addr); | ||
|
||
pr_err("Pointer tag: [%02x], memory tag: [%02x]\n", | ||
addr_tag, memory_tag); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* This file contains tag-based KASAN specific error reporting code. | ||
* This file contains software tag-based KASAN specific error reporting code. | ||
* | ||
* Copyright (c) 2014 Samsung Electronics Co., Ltd. | ||
* Author: Andrey Ryabinin <[email protected]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* This file contains core tag-based KASAN code. | ||
* This file contains core software tag-based KASAN code. | ||
* | ||
* Copyright (c) 2018 Google, Inc. | ||
* Author: Andrey Konovalov <[email protected]> | ||
|