This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 452524104cc89721735aed7b0e14fe701b61cd56
Author: wangmingrong1 <[email protected]>
AuthorDate: Mon Nov 2 18:59:58 2026 +0800

    mm/kasan: tolerate an empty slot in kasan_mem_to_shadow
    
    kasan_unregister() clears a slot and shifts the remaining entries while
    lookups walk g_region[] without holding g_lock, so an index below
    g_region_count can be read as NULL.  Check the slot before
    dereferencing it.
    
    Signed-off-by: wangmingrong1 <[email protected]>
---
 mm/kasan/generic.c | 3 ++-
 mm/kasan/sw_tags.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c
index de3baf41128..0a464e4a1f2 100644
--- a/mm/kasan/generic.c
+++ b/mm/kasan/generic.c
@@ -84,7 +84,8 @@ kasan_mem_to_shadow(FAR const void *ptr, size_t size,
 
   for (i = 0; i < count; i++)
     {
-      if (addr >= g_region[i]->begin && addr < g_region[i]->end)
+      if (g_region[i] &&
+          addr >= g_region[i]->begin && addr < g_region[i]->end)
         {
           DEBUGASSERT(addr + size <= g_region[i]->end);
           addr -= g_region[i]->begin;
diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c
index 52bb8056a93..b6c3202fab2 100644
--- a/mm/kasan/sw_tags.c
+++ b/mm/kasan/sw_tags.c
@@ -79,7 +79,8 @@ kasan_mem_to_shadow(FAR const void *ptr, size_t size)
 
   for (i = 0; i < count; i++)
     {
-      if (addr >= g_region[i]->begin && addr < g_region[i]->end)
+      if (g_region[i] &&
+          addr >= g_region[i]->begin && addr < g_region[i]->end)
         {
           DEBUGASSERT(addr + size <= g_region[i]->end);
           addr -= g_region[i]->begin;

Reply via email to