coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
asan.c File Reference
#include <console/console.h>
#include <symbols.h>
#include <assert.h>
#include <arch/symbols.h>
#include <asan.h>
Include dependency graph for asan.c:

Go to the source code of this file.

Macros

#define DEFINE_ASAN_LOAD_STORE(size)
 
#define DEFINE_ASAN_SET_SHADOW(byte)
 
#define DEFINE_ASAN_REPORT_LOAD(size)
 
#define DEFINE_ASAN_REPORT_STORE(size)
 

Functions

static voidasan_mem_to_shadow (const void *addr)
 
static const voidasan_shadow_to_mem (const void *shadow_addr)
 
static void asan_poison_shadow (const void *address, size_t size, u8 value)
 
void asan_unpoison_shadow (const void *address, size_t size)
 
static __always_inline bool memory_is_poisoned_1 (unsigned long addr)
 
static __always_inline bool memory_is_poisoned_2_4_8 (unsigned long addr, unsigned long size)
 
static __always_inline bool memory_is_poisoned_16 (unsigned long addr)
 
static __always_inline unsigned long bytes_is_nonzero (const u8 *start, size_t size)
 
static __always_inline unsigned long memory_is_nonzero (const void *start, const void *end)
 
static __always_inline bool memory_is_poisoned_n (unsigned long addr, size_t size)
 
static __always_inline bool memory_is_poisoned (unsigned long addr, size_t size)
 
static const voidfind_first_bad_addr (const void *addr, size_t size)
 
static const char * get_shadow_bug_type (const void *addr, size_t size)
 
void asan_report (unsigned long addr, size_t size, bool is_write, unsigned long ip)
 
static __always_inline void check_memory_region_inline (unsigned long addr, size_t size, bool write, unsigned long ret_ip)
 
void check_memory_region (unsigned long addr, size_t size, bool write, unsigned long ret_ip)
 
uintptr_t __asan_shadow_offset (uintptr_t addr)
 
static void register_global (struct asan_global *global)
 
void __asan_register_globals (struct asan_global *globals, size_t size)
 
void __asan_unregister_globals (struct asan_global *globals, size_t size)
 
void asan_init (void)
 
void __asan_poison_stack_memory (const void *addr, size_t size)
 
void __asan_unpoison_stack_memory (const void *addr, size_t size)
 
 DEFINE_ASAN_LOAD_STORE (1)
 
 DEFINE_ASAN_LOAD_STORE (2)
 
 DEFINE_ASAN_LOAD_STORE (4)
 
 DEFINE_ASAN_LOAD_STORE (8)
 
 DEFINE_ASAN_LOAD_STORE (16)
 
void __asan_loadN (unsigned long addr, size_t size)
 
void __asan_storeN (unsigned long addr, size_t size)
 
void __asan_loadN_noabort (unsigned long addr, size_t size)
 
void __asan_storeN_noabort (unsigned long addr, size_t size)
 
void __asan_handle_no_return (void)
 
 DEFINE_ASAN_SET_SHADOW (00)
 
 DEFINE_ASAN_SET_SHADOW (f1)
 
 DEFINE_ASAN_SET_SHADOW (f2)
 
 DEFINE_ASAN_SET_SHADOW (f3)
 
 DEFINE_ASAN_SET_SHADOW (f5)
 
 DEFINE_ASAN_SET_SHADOW (f8)
 
 DEFINE_ASAN_REPORT_LOAD (1)
 
 DEFINE_ASAN_REPORT_LOAD (2)
 
 DEFINE_ASAN_REPORT_LOAD (4)
 
 DEFINE_ASAN_REPORT_LOAD (8)
 
 DEFINE_ASAN_REPORT_LOAD (16)
 
 DEFINE_ASAN_REPORT_STORE (1)
 
 DEFINE_ASAN_REPORT_STORE (2)
 
 DEFINE_ASAN_REPORT_STORE (4)
 
 DEFINE_ASAN_REPORT_STORE (8)
 
 DEFINE_ASAN_REPORT_STORE (16)
 
void __asan_report_load_n_noabort (unsigned long addr, size_t size)
 
void __asan_report_store_n_noabort (unsigned long addr, size_t size)
 

Macro Definition Documentation

◆ DEFINE_ASAN_LOAD_STORE

#define DEFINE_ASAN_LOAD_STORE (   size)
Value:
void __asan_load##size(unsigned long addr) \
{ \
check_memory_region_inline(addr, size, false, _RET_IP_);\
} \
void __asan_load##size##_noabort(unsigned long addr) \
{ \
check_memory_region_inline(addr, size, false, _RET_IP_);\
} \
void __asan_store##size(unsigned long addr) \
{ \
check_memory_region_inline(addr, size, true, _RET_IP_); \
} \
void __asan_store##size##_noabort(unsigned long addr) \
{ \
check_memory_region_inline(addr, size, true, _RET_IP_); \
}
#define _RET_IP_
Definition: asan.h:20
static u32 addr
Definition: cirrus.c:14

Definition at line 347 of file asan.c.

◆ DEFINE_ASAN_REPORT_LOAD

#define DEFINE_ASAN_REPORT_LOAD (   size)
Value:
void __asan_report_load##size##_noabort(unsigned long addr) \
{ \
asan_report(addr, size, false, _RET_IP_); \
}

Definition at line 408 of file asan.c.

◆ DEFINE_ASAN_REPORT_STORE

#define DEFINE_ASAN_REPORT_STORE (   size)
Value:
void __asan_report_store##size##_noabort(unsigned long addr) \
{ \
asan_report(addr, size, true, _RET_IP_); \
}

Definition at line 414 of file asan.c.

◆ DEFINE_ASAN_SET_SHADOW

#define DEFINE_ASAN_SET_SHADOW (   byte)
Value:
void __asan_set_shadow_##byte(const void *addr, size_t size) \
{ \
__builtin_memset((void *)addr, 0x##byte, size); \
}
int x
Definition: edid.c:994

Definition at line 395 of file asan.c.

Function Documentation

◆ __asan_handle_no_return()

void __asan_handle_no_return ( void  )

Definition at line 391 of file asan.c.

◆ __asan_loadN()

void __asan_loadN ( unsigned long  addr,
size_t  size 
)

Definition at line 371 of file asan.c.

References _RET_IP_, addr, and check_memory_region().

Here is the call graph for this function:

◆ __asan_loadN_noabort()

void __asan_loadN_noabort ( unsigned long  addr,
size_t  size 
)

Definition at line 381 of file asan.c.

References _RET_IP_, addr, and check_memory_region().

Here is the call graph for this function:

◆ __asan_poison_stack_memory()

void __asan_poison_stack_memory ( const void addr,
size_t  size 
)

Definition at line 336 of file asan.c.

References addr, ALIGN_UP, asan_poison_shadow(), ASAN_SHADOW_SCALE_SIZE, and ASAN_USE_AFTER_SCOPE.

Here is the call graph for this function:

◆ __asan_register_globals()

void __asan_register_globals ( struct asan_global globals,
size_t  size 
)

Definition at line 292 of file asan.c.

References register_global().

Here is the call graph for this function:

◆ __asan_report_load_n_noabort()

void __asan_report_load_n_noabort ( unsigned long  addr,
size_t  size 
)

Definition at line 431 of file asan.c.

References _RET_IP_, addr, and asan_report().

Here is the call graph for this function:

◆ __asan_report_store_n_noabort()

void __asan_report_store_n_noabort ( unsigned long  addr,
size_t  size 
)

Definition at line 436 of file asan.c.

References _RET_IP_, addr, and asan_report().

Here is the call graph for this function:

◆ __asan_shadow_offset()

uintptr_t __asan_shadow_offset ( uintptr_t  addr)

Definition at line 270 of file asan.c.

References _car_region_start, and ASAN_SHADOW_SCALE_SHIFT.

◆ __asan_storeN()

void __asan_storeN ( unsigned long  addr,
size_t  size 
)

Definition at line 376 of file asan.c.

References _RET_IP_, addr, and check_memory_region().

Here is the call graph for this function:

◆ __asan_storeN_noabort()

void __asan_storeN_noabort ( unsigned long  addr,
size_t  size 
)

Definition at line 386 of file asan.c.

References _RET_IP_, addr, and check_memory_region().

Here is the call graph for this function:

◆ __asan_unpoison_stack_memory()

void __asan_unpoison_stack_memory ( const void addr,
size_t  size 
)

Definition at line 342 of file asan.c.

References addr, and asan_unpoison_shadow().

Here is the call graph for this function:

◆ __asan_unregister_globals()

void __asan_unregister_globals ( struct asan_global globals,
size_t  size 
)

Definition at line 300 of file asan.c.

◆ asan_init()

void asan_init ( void  )

Definition at line 324 of file asan.c.

References _car_region_start, _eheap, and asan_unpoison_shadow().

Here is the call graph for this function:

◆ asan_mem_to_shadow()

static void* asan_mem_to_shadow ( const void addr)
inlinestatic

◆ asan_poison_shadow()

static void asan_poison_shadow ( const void address,
size_t  size,
u8  value 
)
static

Definition at line 39 of file asan.c.

References address, asan_mem_to_shadow(), and value.

Referenced by __asan_poison_stack_memory(), asan_unpoison_shadow(), and register_global().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ asan_report()

void asan_report ( unsigned long  addr,
size_t  size,
bool  is_write,
unsigned long  ip 
)

Definition at line 224 of file asan.c.

References addr, BIOS_ERR, get_shadow_bug_type(), and printk.

Referenced by __asan_report_load_n_noabort(), __asan_report_store_n_noabort(), and check_memory_region_inline().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ asan_shadow_to_mem()

static const void* asan_shadow_to_mem ( const void shadow_addr)
inlinestatic

Definition at line 28 of file asan.c.

References _car_region_start, and ASAN_SHADOW_SCALE_SHIFT.

Referenced by check_memory_region_inline(), and get_shadow_bug_type().

Here is the caller graph for this function:

◆ asan_unpoison_shadow()

void asan_unpoison_shadow ( const void address,
size_t  size 
)

Definition at line 49 of file asan.c.

References address, asan_mem_to_shadow(), asan_poison_shadow(), and ASAN_SHADOW_MASK.

Referenced by __asan_unpoison_stack_memory(), asan_init(), and register_global().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bytes_is_nonzero()

static __always_inline unsigned long bytes_is_nonzero ( const u8 start,
size_t  size 
)
static

Definition at line 92 of file asan.c.

References unlikely.

Referenced by memory_is_nonzero().

Here is the caller graph for this function:

◆ check_memory_region()

void check_memory_region ( unsigned long  addr,
size_t  size,
bool  write,
unsigned long  ret_ip 
)

Definition at line 264 of file asan.c.

References addr, and check_memory_region_inline().

Referenced by __asan_loadN(), __asan_loadN_noabort(), __asan_storeN(), __asan_storeN_noabort(), memcpy(), memmove(), and memset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_memory_region_inline()

static __always_inline void check_memory_region_inline ( unsigned long  addr,
size_t  size,
bool  write,
unsigned long  ret_ip 
)
static

Definition at line 236 of file asan.c.

References _car_region_start, _eheap, addr, asan_report(), asan_shadow_to_mem(), likely, memory_is_poisoned(), and unlikely.

Referenced by check_memory_region().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DEFINE_ASAN_LOAD_STORE() [1/5]

DEFINE_ASAN_LOAD_STORE ( )

◆ DEFINE_ASAN_LOAD_STORE() [2/5]

DEFINE_ASAN_LOAD_STORE ( 16  )

◆ DEFINE_ASAN_LOAD_STORE() [3/5]

DEFINE_ASAN_LOAD_STORE ( )

◆ DEFINE_ASAN_LOAD_STORE() [4/5]

DEFINE_ASAN_LOAD_STORE ( )

◆ DEFINE_ASAN_LOAD_STORE() [5/5]

DEFINE_ASAN_LOAD_STORE ( )

◆ DEFINE_ASAN_REPORT_LOAD() [1/5]

DEFINE_ASAN_REPORT_LOAD ( )

◆ DEFINE_ASAN_REPORT_LOAD() [2/5]

DEFINE_ASAN_REPORT_LOAD ( 16  )

◆ DEFINE_ASAN_REPORT_LOAD() [3/5]

DEFINE_ASAN_REPORT_LOAD ( )

◆ DEFINE_ASAN_REPORT_LOAD() [4/5]

DEFINE_ASAN_REPORT_LOAD ( )

◆ DEFINE_ASAN_REPORT_LOAD() [5/5]

DEFINE_ASAN_REPORT_LOAD ( )

◆ DEFINE_ASAN_REPORT_STORE() [1/5]

DEFINE_ASAN_REPORT_STORE ( )

◆ DEFINE_ASAN_REPORT_STORE() [2/5]

DEFINE_ASAN_REPORT_STORE ( 16  )

◆ DEFINE_ASAN_REPORT_STORE() [3/5]

DEFINE_ASAN_REPORT_STORE ( )

◆ DEFINE_ASAN_REPORT_STORE() [4/5]

DEFINE_ASAN_REPORT_STORE ( )

◆ DEFINE_ASAN_REPORT_STORE() [5/5]

DEFINE_ASAN_REPORT_STORE ( )

◆ DEFINE_ASAN_SET_SHADOW() [1/6]

DEFINE_ASAN_SET_SHADOW ( 00  )

◆ DEFINE_ASAN_SET_SHADOW() [2/6]

DEFINE_ASAN_SET_SHADOW ( f1  )

◆ DEFINE_ASAN_SET_SHADOW() [3/6]

DEFINE_ASAN_SET_SHADOW ( f2  )

◆ DEFINE_ASAN_SET_SHADOW() [4/6]

DEFINE_ASAN_SET_SHADOW ( f3  )

◆ DEFINE_ASAN_SET_SHADOW() [5/6]

DEFINE_ASAN_SET_SHADOW ( f5  )

◆ DEFINE_ASAN_SET_SHADOW() [6/6]

DEFINE_ASAN_SET_SHADOW ( f8  )

◆ find_first_bad_addr()

static const void* find_first_bad_addr ( const void addr,
size_t  size 
)
static

Definition at line 173 of file asan.c.

References addr, asan_mem_to_shadow(), and ASAN_SHADOW_SCALE_SIZE.

Referenced by get_shadow_bug_type().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_shadow_bug_type()

static const char* get_shadow_bug_type ( const void addr,
size_t  size 
)
static

Definition at line 185 of file asan.c.

References addr, ASAN_GLOBAL_REDZONE, asan_mem_to_shadow(), ASAN_SHADOW_SCALE_SIZE, asan_shadow_to_mem(), ASAN_STACK_LEFT, ASAN_STACK_MID, ASAN_STACK_PARTIAL, ASAN_STACK_RIGHT, ASAN_USE_AFTER_SCOPE, and find_first_bad_addr().

Referenced by asan_report().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ memory_is_nonzero()

static __always_inline unsigned long memory_is_nonzero ( const void start,
const void end 
)
static

Definition at line 105 of file asan.c.

References bytes_is_nonzero(), and unlikely.

Referenced by memory_is_poisoned_n().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ memory_is_poisoned()

static __always_inline bool memory_is_poisoned ( unsigned long  addr,
size_t  size 
)
static

Definition at line 153 of file asan.c.

References addr, assert, memory_is_poisoned_1(), memory_is_poisoned_16(), memory_is_poisoned_2_4_8(), and memory_is_poisoned_n().

Referenced by check_memory_region_inline().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ memory_is_poisoned_1()

static __always_inline bool memory_is_poisoned_1 ( unsigned long  addr)
static

Definition at line 59 of file asan.c.

References addr, asan_mem_to_shadow(), ASAN_SHADOW_MASK, and unlikely.

Referenced by memory_is_poisoned(), memory_is_poisoned_16(), and memory_is_poisoned_2_4_8().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ memory_is_poisoned_16()

static __always_inline bool memory_is_poisoned_16 ( unsigned long  addr)
static

Definition at line 82 of file asan.c.

References addr, asan_mem_to_shadow(), ASAN_SHADOW_SCALE_SIZE, IS_ALIGNED, memory_is_poisoned_1(), and unlikely.

Referenced by memory_is_poisoned().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ memory_is_poisoned_2_4_8()

static __always_inline bool memory_is_poisoned_2_4_8 ( unsigned long  addr,
unsigned long  size 
)
static

Definition at line 71 of file asan.c.

References addr, asan_mem_to_shadow(), ASAN_SHADOW_MASK, memory_is_poisoned_1(), and unlikely.

Referenced by memory_is_poisoned().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ memory_is_poisoned_n()

static __always_inline bool memory_is_poisoned_n ( unsigned long  addr,
size_t  size 
)
static

Definition at line 134 of file asan.c.

References addr, asan_mem_to_shadow(), ASAN_SHADOW_MASK, memory_is_nonzero(), and unlikely.

Referenced by memory_is_poisoned().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_global()

static void register_global ( struct asan_global global)
static

Definition at line 281 of file asan.c.

References ALIGN_UP, ASAN_GLOBAL_REDZONE, asan_poison_shadow(), ASAN_SHADOW_SCALE_SIZE, asan_unpoison_shadow(), asan_global::beg, asan_global::size, and asan_global::size_with_redzone.

Referenced by __asan_register_globals().

Here is the call graph for this function:
Here is the caller graph for this function: