kasantest: Add a test set for global variable out of bounds detection
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
This commit is contained in:
parent
277c968b6a
commit
f2c21b11d8
@ -29,5 +29,6 @@ STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
|
|||||||
|
|
||||||
CFLAGS += -Wno-error -Wno-use-after-free
|
CFLAGS += -Wno-error -Wno-use-after-free
|
||||||
CFLAGS += -Wno-array-bounds -Wno-free-nonheap-object
|
CFLAGS += -Wno-array-bounds -Wno-free-nonheap-object
|
||||||
|
CFLAGS += -Wno-stringop-overflow
|
||||||
|
|
||||||
include $(APPDIR)/Application.mk
|
include $(APPDIR)/Application.mk
|
||||||
|
@ -72,6 +72,11 @@ static bool test_heap_memset(FAR struct mm_heap_s *heap, size_t size);
|
|||||||
static bool test_heap_memcpy(FAR struct mm_heap_s *heap, size_t size);
|
static bool test_heap_memcpy(FAR struct mm_heap_s *heap, size_t size);
|
||||||
static bool test_heap_memmove(FAR struct mm_heap_s *heap, size_t size);
|
static bool test_heap_memmove(FAR struct mm_heap_s *heap, size_t size);
|
||||||
|
|
||||||
|
#ifdef CONFIG_MM_KASAN_GLOBAL
|
||||||
|
static bool test_global_underflow(FAR struct mm_heap_s *heap, size_t size);
|
||||||
|
static bool test_global_overflow(FAR struct mm_heap_s *heap, size_t size);
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Data
|
* Private Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -87,11 +92,19 @@ const static testcase_t g_kasan_test[] =
|
|||||||
{test_heap_unpoison, "heap unpoison"},
|
{test_heap_unpoison, "heap unpoison"},
|
||||||
{test_heap_memset, "heap memset"},
|
{test_heap_memset, "heap memset"},
|
||||||
{test_heap_memcpy, "heap memcpy"},
|
{test_heap_memcpy, "heap memcpy"},
|
||||||
{test_heap_memmove, "heap memmove"}
|
{test_heap_memmove, "heap memmove"},
|
||||||
|
#ifdef CONFIG_MM_KASAN_GLOBAL
|
||||||
|
{test_global_underflow, "globals underflow"},
|
||||||
|
{test_global_overflow, "globals overflow"},
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static char g_kasan_heap[65536] aligned_data(8);
|
static char g_kasan_heap[65536] aligned_data(8);
|
||||||
|
|
||||||
|
#ifdef CONFIG_MM_KASAN_GLOBAL
|
||||||
|
static char g_kasan_globals[32];
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -210,6 +223,20 @@ static bool test_heap_memmove(FAR struct mm_heap_s *heap, size_t size)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_MM_KASAN_GLOBAL
|
||||||
|
static bool test_global_underflow(FAR struct mm_heap_s *heap, size_t size)
|
||||||
|
{
|
||||||
|
memset(g_kasan_globals - 31, 0x12, sizeof(g_kasan_globals));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool test_global_overflow(FAR struct mm_heap_s *heap, size_t size)
|
||||||
|
{
|
||||||
|
memset(g_kasan_globals, 0xef, sizeof(g_kasan_globals) + 31);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int run_test(FAR const testcase_t *test)
|
static int run_test(FAR const testcase_t *test)
|
||||||
{
|
{
|
||||||
size_t heap_size = 65536;
|
size_t heap_size = 65536;
|
||||||
|
Loading…
Reference in New Issue
Block a user