xref: /openbmc/linux/mm/kasan/report_hw_tags.c (revision 31e67366)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * This file contains hardware tag-based KASAN specific error reporting code.
4  *
5  * Copyright (c) 2020 Google, Inc.
6  * Author: Andrey Konovalov <andreyknvl@google.com>
7  */
8 
9 #include <linux/kasan.h>
10 #include <linux/kernel.h>
11 #include <linux/memory.h>
12 #include <linux/mm.h>
13 #include <linux/string.h>
14 #include <linux/types.h>
15 
16 #include "kasan.h"
17 
18 const char *kasan_get_bug_type(struct kasan_access_info *info)
19 {
20 	return "invalid-access";
21 }
22 
23 void *kasan_find_first_bad_addr(void *addr, size_t size)
24 {
25 	return kasan_reset_tag(addr);
26 }
27 
28 void kasan_metadata_fetch_row(char *buffer, void *row)
29 {
30 	int i;
31 
32 	for (i = 0; i < META_BYTES_PER_ROW; i++)
33 		buffer[i] = hw_get_mem_tag(row + i * KASAN_GRANULE_SIZE);
34 }
35 
36 void kasan_print_tags(u8 addr_tag, const void *addr)
37 {
38 	u8 memory_tag = hw_get_mem_tag((void *)addr);
39 
40 	pr_err("Pointer tag: [%02x], memory tag: [%02x]\n",
41 		addr_tag, memory_tag);
42 }
43