This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 6b53b6387369bf6479ef109c9f48cffd4b9c1dd5 Author: wangmingrong1 <[email protected]> AuthorDate: Thu Jun 5 15:57:59 2025 +0800 kasantest: Add test cases for stack CONFIG_MM_KASAN_SIM builds the simulator with the host AddressSanitizer, which checks the global and the stack accesses too. Run the global tests with it as well, and add two tests that write just before and just after a stack array. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: wangmingrong1 <[email protected]> --- testing/mm/kasantest/kasantest.c | 45 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/testing/mm/kasantest/kasantest.c b/testing/mm/kasantest/kasantest.c index a43cce7a8..dc14d9f50 100644 --- a/testing/mm/kasantest/kasantest.c +++ b/testing/mm/kasantest/kasantest.c @@ -41,6 +41,18 @@ #include <nuttx/mm/mm.h> #include <nuttx/mm/kasan.h> +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#if defined(CONFIG_MM_KASAN_GLOBAL) || defined(CONFIG_MM_KASAN_SIM) +# define KASANTEST_GLOBAL +#endif + +#if defined(CONFIG_MM_KASAN_SIM) +# define KASANTEST_STACK +#endif + /**************************************************************************** * Private Types Prototypes ****************************************************************************/ @@ -115,11 +127,16 @@ static bool test_heap_legal_strrchr(FAR struct mm_heap_s *heap, size_t size); static bool test_insert_perf(FAR struct mm_heap_s *heap, size_t size); static bool test_algorithm_perf(FAR struct mm_heap_s *heap, size_t size); -#ifdef CONFIG_MM_KASAN_GLOBAL +#ifdef KASANTEST_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 +#ifdef KASANTEST_STACK +static bool test_stack_underflow(FAR struct mm_heap_s *heap, size_t size); +static bool test_stack_overflow(FAR struct mm_heap_s *heap, size_t size); +#endif + /**************************************************************************** * Private Data ****************************************************************************/ @@ -161,15 +178,19 @@ const static testcase_t g_kasan_test[] = {test_heap_legal_strrchr, true, "heap legal strrchr"}, {test_insert_perf, false, "Kasan insert performance"}, {test_algorithm_perf, false, "Kasan algorithm performance"}, -#ifdef CONFIG_MM_KASAN_GLOBAL +#ifdef KASANTEST_GLOBAL {test_global_underflow, true, "globals underflow"}, {test_global_overflow, true, "globals overflow"}, #endif +#ifdef KASANTEST_STACK + {test_stack_underflow, true, "stack underflow"}, + {test_stack_overflow, true, "stack overflow"}, +#endif }; static char g_kasan_heap[10240] aligned_data(8); -#ifdef CONFIG_MM_KASAN_GLOBAL +#ifdef KASANTEST_GLOBAL static char g_kasan_globals[32]; #endif @@ -598,7 +619,7 @@ static bool test_algorithm_perf(FAR struct mm_heap_s *heap, size_t size) return true; } -#ifdef CONFIG_MM_KASAN_GLOBAL +#ifdef KASANTEST_GLOBAL static bool test_global_underflow(FAR struct mm_heap_s *heap, size_t size) { memset(g_kasan_globals - 1, 0x12, sizeof(g_kasan_globals)); @@ -612,6 +633,22 @@ static bool test_global_overflow(FAR struct mm_heap_s *heap, size_t size) } #endif +#ifdef KASANTEST_STACK +static bool test_stack_underflow(FAR struct mm_heap_s *heap, size_t size) +{ + char stack[0]; + memset(stack - 16, 0xef, 16); + return false; +} + +static bool test_stack_overflow(FAR struct mm_heap_s *heap, size_t size) +{ + char stack[0]; + memset(stack, 0xef, 16); + return false; +} +#endif + static int run_test(FAR const testcase_t *test) { size_t heap_size = sizeof(g_kasan_heap) - sizeof(run_t);
