Skip to content

Commit f2c21b1

Browse files
W-M-Rxiaoxiang781216
authored andcommitted
kasantest: Add a test set for global variable out of bounds detection
Signed-off-by: wangmingrong1 <[email protected]>
1 parent 277c968 commit f2c21b1

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

testing/kasantest/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
2929

3030
CFLAGS += -Wno-error -Wno-use-after-free
3131
CFLAGS += -Wno-array-bounds -Wno-free-nonheap-object
32+
CFLAGS += -Wno-stringop-overflow
3233

3334
include $(APPDIR)/Application.mk

testing/kasantest/kasantest.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ static bool test_heap_memset(FAR struct mm_heap_s *heap, size_t size);
7272
static bool test_heap_memcpy(FAR struct mm_heap_s *heap, size_t size);
7373
static bool test_heap_memmove(FAR struct mm_heap_s *heap, size_t size);
7474

75+
#ifdef CONFIG_MM_KASAN_GLOBAL
76+
static bool test_global_underflow(FAR struct mm_heap_s *heap, size_t size);
77+
static bool test_global_overflow(FAR struct mm_heap_s *heap, size_t size);
78+
#endif
79+
7580
/****************************************************************************
7681
* Private Data
7782
****************************************************************************/
@@ -87,11 +92,19 @@ const static testcase_t g_kasan_test[] =
8792
{test_heap_unpoison, "heap unpoison"},
8893
{test_heap_memset, "heap memset"},
8994
{test_heap_memcpy, "heap memcpy"},
90-
{test_heap_memmove, "heap memmove"}
95+
{test_heap_memmove, "heap memmove"},
96+
#ifdef CONFIG_MM_KASAN_GLOBAL
97+
{test_global_underflow, "globals underflow"},
98+
{test_global_overflow, "globals overflow"},
99+
#endif
91100
};
92101

93102
static char g_kasan_heap[65536] aligned_data(8);
94103

104+
#ifdef CONFIG_MM_KASAN_GLOBAL
105+
static char g_kasan_globals[32];
106+
#endif
107+
95108
/****************************************************************************
96109
* Private Functions
97110
****************************************************************************/
@@ -210,6 +223,20 @@ static bool test_heap_memmove(FAR struct mm_heap_s *heap, size_t size)
210223
return false;
211224
}
212225

226+
#ifdef CONFIG_MM_KASAN_GLOBAL
227+
static bool test_global_underflow(FAR struct mm_heap_s *heap, size_t size)
228+
{
229+
memset(g_kasan_globals - 31, 0x12, sizeof(g_kasan_globals));
230+
return false;
231+
}
232+
233+
static bool test_global_overflow(FAR struct mm_heap_s *heap, size_t size)
234+
{
235+
memset(g_kasan_globals, 0xef, sizeof(g_kasan_globals) + 31);
236+
return false;
237+
}
238+
#endif
239+
213240
static int run_test(FAR const testcase_t *test)
214241
{
215242
size_t heap_size = 65536;

0 commit comments

Comments
 (0)