blob: 492e0bc76ff551e28e0191f82232f60b56e5b150 [file] [log] [blame]
Bo Lv72d0e902023-01-02 14:27:34 +00001/* SPDX-License-Identifier: (GPL-2.0+ OR MIT) */
2/*
3 * Copyright (c) 2019 Amlogic, Inc. All rights reserved.
4 */
5
6#ifndef __AML_UASAN_H__
7#define __AML_UASAN_H__
8
9/* for red zone between each section */
10#define SECTION_RED_ZONE_NUM 8
11#define MEM_SECTION_RED_ZONE_SIZE 256
12#define MEM_SECTION_RED_ZONE_MASK 0xff
13
14#define UASAN_SHADOW_SCALE_SHIFT 3
15
16#define UASAN_SHADOW_SCALE_SIZE (1UL << UASAN_SHADOW_SCALE_SHIFT)
17#define UASAN_SHADOW_MASK (UASAN_SHADOW_SCALE_SIZE - 1)
18
19#define UASAN_FREE_PAGE 0xFF /* page was freed */
20#define UASAN_PAGE_REDZONE 0xFE /* redzone for kmalloc_large allocations */
21#define UASAN_MALLOC_REDZONE 0xFC /* redzone inside slub object */
22#define UASAN_MALLOC_FREE 0xFB /* object was freed (kmem_cache_free/kfree) */
23#define UASAN_GLOBAL_REDZONE 0xFA /* redzone for global variable */
24
25/*
26 * Stack redzone shadow values
27 * (Those are compiler's ABI, don't change them)
28 */
29#define UASAN_STACK_LEFT 0xF1
30#define UASAN_STACK_MID 0xF2
31#define UASAN_STACK_RIGHT 0xF3
32#define UASAN_STACK_PARTIAL 0xF4
33#define UASAN_USE_AFTER_SCOPE 0xF8
34
35/*
36 * alloca redzone shadow values
37 */
38#define UASAN_ALLOCA_LEFT 0xCA
39#define UASAN_ALLOCA_RIGHT 0xCB
40
41#define UASAN_ALLOCA_REDZONE_SIZE 32
42
Bo Lv96a66d02023-05-12 19:18:22 +080043#define UASAN_STACK_SIZE (256 * 1024)
Bo Lv72d0e902023-01-02 14:27:34 +000044
45#define UASAN_UBOOT_SIZE (256 * 1024 * 1024UL)
46
47#ifndef __ASSEMBLY__
48
49struct uasan_report_info {
50 const void *access_addr;
51 const void *first_bad_addr;
52 size_t access_size;
53 bool is_write;
54 unsigned long ip;
55};
56
57/* The layout of struct dictated by compiler */
58struct uasan_source_location {
59 const char *filename;
60 int line_no;
61 int column_no;
62};
63
64/* The layout of struct dictated by compiler */
65struct uasan_global {
66 /* Address of the beginning of the global variable. */
67 const void *beg;
68 /* Size of the global variable. */
69 size_t size;
70 /* Size of the variable + size of the red zone. 32 bytes aligned */
71 size_t size_with_redzone;
72 const void *name;
73 /* Name of the module where the global variable is declared. */
74 const void *module_name;
75 unsigned long has_dynamic_init; /* This needed for C++ */
76#if KASAN_ABI_VERSION >= 4
77 struct uasan_source_location *location;
78#endif
79#if KASAN_ABI_VERSION >= 5
80 char *odr_indicator;
81#endif
82};
83
84/* Used for constructor calls. */
85typedef void (*ctor_fn_t)(void);
86
87unsigned long mem_to_shadow(const void *mem_addr);
88void uasan_poison_object(unsigned long addr, unsigned long size, unsigned tag);
89
90extern const char __init_array_start[];
91extern const char __init_array_end[];
92void uasan_alloc(void *ptr, unsigned long size);
93void uasan_free(void *ptr, unsigned long size);
94
95#endif
96
97#endif