You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "W-M-R (via GitHub)" <gi...@apache.org> on 2025/01/08 03:38:17 UTC

[PR] mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE [nuttx]

W-M-R opened a new pull request, #15461:
URL: https://github.com/apache/nuttx/pull/15461

   *Note: Please adhere to [Contributing Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).*
   
   ## Summary
   
       mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE
       
       1. Add mte_tags.c, which will call arm64_mte to implement tagging of memory blocks by operating registers
       2. please use arm64/mte, it default enable MM_KASAN_MTE_TAGS, run log:
       
   ```
       ➜  NX git:(mm) ✗ qemu-system-aarch64 -cpu max -nographic \
               -machine virt,virtualization=on,gic-version=3,mte=on \
               -chardev stdio,id=con,mux=on, -serial chardev:con \
               -mon chardev=con,mode=readline  -kernel ./nuttx/nuttx -s
       - Ready to Boot Primary CPU
       - Boot from EL2
       - Boot from EL1
       - Boot to C runtime for OS Initialize
       mm_initialize: Heap: name=Umem, start=0x403f2000 size=130080768
       mm_addregion: [Umem] Region 1: base=0x403f23a0 size=130079840
       mm_malloc: Allocated 0xf8000000403f23e0, size 144
       mm_malloc: Allocated 0xfe000000403f2470, size 80
       mm_malloc: Allocated 0xfe000000403f24c0, size 64
       mm_malloc: Allocated 0xfe000000403f2500, size 96
       mm_malloc: Allocated 0xff000000403f2560, size 96
       mm_malloc: Allocated 0xf7000000403f25c0, size 96
       mm_malloc: Allocated 0xff000000403f2620, size 96
       mm_malloc: Allocated 0xfe000000403f2680, size 96
       mm_malloc: Allocated 0xfe000000403f26e0, size 64
       mm_malloc: Allocated 0xf1000000403f2720, size 64
       mm_malloc: Allocated 0xf9000000403f2760, size 336
       mm_malloc: Allocated 0xf6000000403f28b0, size 8208
       mm_malloc: Allocated 0xf4000000403f48c0, size 1584
       mm_malloc: Allocated 0xfa000000403f4ef0, size 64
       mm_malloc: Allocated 0xf8000000403f4f30, size 64
       mm_malloc: Allocated 0xfe000000403f4f70, size 8208
       mm_malloc: Allocated 0xfe000000403f6f80, size 80
       mm_malloc: Allocated 0xfe000000403f6fd0, size 96
       mm_malloc: Allocated 0xf7000000403f7030, size 96
       mm_malloc: Allocated 0xf7000000403f7090, size 336
       mm_malloc: Allocated 0xfc000000403f71e0, size 96
       mm_malloc: Allocated 0xfd000000403f7240, size 912
       
       NuttShell (NSH)
       nsh>
       nsh> mtetest
       mm_malloc: Allocated 0xf4000000403f75d0, size 1584
       mm_malloc: Allocated 0xfd000000403f7c00, size 64
       mm_malloc: Allocated 0xff000000403f7c40, size 64
       mm_malloc: Allocated 0xfe000000403f7c80, size 8208
       Spawning process for test: mtetest1
       mm_malloc: Allocated 0xf4000000403f9c90, size 1584
       mm_malloc: Allocated 0xfb000000403fa2c0, size 64
       mm_malloc: Allocated 0xf5000000403fa300, size 64
       mm_malloc: Allocated 0xfd000000403fa340, size 8208
       Running test: mtetest1
       mm_free: Freeing 0xf5000000403fa300
       mm_free: Freeing 0xfb000000403fa2c0
       mm_free: Freeing 0xfd000000403fa340
       mm_free: Freeing 0xf4000000403f9c90
       Test 'mtetest1' completed
       Spawning process for test: mtetest2
       mm_malloc: Allocated 0xf9000000403f9c90, size 1584
       mm_malloc: Allocated 0xfd000000403fa2c0, size 64
       mm_malloc: Allocated 0xfd000000403fa300, size 64
       mm_malloc: Allocated 0xfb000000403fa340, size 8208
       Running test: mtetest2
       mm_free: Freeing 0xfd000000403fa300
       mm_free: Freeing 0xfd000000403fa2c0
       mm_free: Freeing 0xfb000000403fa340
       mm_free: Freeing 0xf9000000403f9c90
       Test 'mtetest2' completed
       Spawning process for test: mtetest3
       mm_malloc: Allocated 0xf5000000403f9c90, size 1584
       mm_malloc: Allocated 0xf7000000403fa2c0, size 64
       mm_malloc: Allocated 0xfd000000403fa300, size 64
       mm_malloc: Allocated 0xf4000000403fa340, size 8208
       Running test: mtetest3
       mm_free: Freeing 0xfd000000403fa300
       mm_free: Freeing 0xf7000000403fa2c0
       mm_free: Freeing 0xf4000000403fa340
       mm_free: Freeing 0xf5000000403f9c90
       Test 'mtetest3' completed
       Spawning process for test: mtetest4
       mm_malloc: Allocated 0xf8000000403f9c90, size 1584
       mm_malloc: Allocated 0xfb000000403fa2c0, size 64
       mm_malloc: Allocated 0xf4000000403fa300, size 64
       mm_malloc: Allocated 0xfe000000403fa340, size 8208
       Running test: mtetest4
       mm_free: Freeing 0xf4000000403fa300
       mm_free: Freeing 0xfb000000403fa2c0
       mm_free: Freeing 0xfe000000403fa340
       mm_free: Freeing 0xf8000000403f9c90
       Test 'mtetest4' completed
       Spawning process for test: mtetest5
       mm_malloc: Allocated 0xf2000000403f9c90, size 1584
       mm_malloc: Allocated 0xf5000000403fa2c0, size 64
       mm_malloc: Allocated 0xf8000000403fa300, size 64
       mm_malloc: Allocated 0xfb000000403fa340, size 8208
       Running test: mtetest5
       mm_free: Freeing 0xf8000000403fa300
       mm_free: Freeing 0xf5000000403fa2c0
       mm_free: Freeing 0xfb000000403fa340
       mm_free: Freeing 0xf2000000403f9c90
       Test 'mtetest5' completed
       Spawning process for test: Thread switch MTE test
       mm_malloc: Allocated 0xf4000000403f9c90, size 1584
       mm_malloc: Allocated 0xff000000403fa2c0, size 64
       mm_malloc: Allocated 0xfe000000403fa300, size 64
       mm_malloc: Allocated 0xfb000000403fa340, size 8208
       Running test: Thread switch MTE test
       mm_malloc: Allocated 0xf2000000403fc350, size 352
       mm_malloc: Allocated 0xf4000000403fc4b0, size 8208
       mm_malloc: Allocated 0xf4000000403fe4c0, size 352
       mm_malloc: Allocated 0xfa000000403fe620, size 8208
       Process 1 holding lock
       Process 2 holding lock
       Process 1 holding lock again
       default_fatal_handler: (IFSC/DFSC) for Data/Instruction aborts: synchronous tag check fault
       arm64_exception_handler: CurrentEL: MODE_EL1
       arm64_exception_handler: ESR_ELn: 0x96000011
       arm64_exception_handler: FAR_ELn: 0x6000000403ee2f0
       arm64_exception_handler: ELR_ELn: 0x402b3e98
       print_ec_cause: DABT (current EL)
       print_ec_cause: Data Abort taken without a change in Exception level
   ```
   
   ## Impact
   
   *Update this section, where applicable, on how change affects users,
    build process, hardware, documentation, security, compatibility, etc.*
   
   ## Testing
   
   *Update this section with details on how did you verify the change,
    what Host was used for build (OS, CPU, compiler, ..), what Target was
    used for verification (arch, board:config, ..), etc. Providing build
    and runtime logs from before and after change is highly appreciated.*
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE [nuttx]

Posted by "W-M-R (via GitHub)" <gi...@apache.org>.
W-M-R commented on code in PR #15461:
URL: https://github.com/apache/nuttx/pull/15461#discussion_r1909835721


##########
mm/mm_heap/mm_free.c:
##########
@@ -49,6 +49,8 @@ static void add_delaylist(FAR struct mm_heap_s *heap, FAR void *mem)
 
   /* Delay the deallocation until a more appropriate time. */
 
+  kasan_hw_close();
+
   flags = up_irq_save();

Review Comment:
   ![image](https://github.com/user-attachments/assets/8df71078-ba52-4363-970c-52069ea0acd4)
   Here, kasan is turned off in the add_delaylist code, because the operation of add_delaylist is not locked.



##########
mm/mm_heap/mm_free.c:
##########
@@ -49,6 +49,8 @@ static void add_delaylist(FAR struct mm_heap_s *heap, FAR void *mem)
 
   /* Delay the deallocation until a more appropriate time. */
 
+  kasan_hw_close();
+
   flags = up_irq_save();

Review Comment:
   ![image](https://github.com/user-attachments/assets/8df71078-ba52-4363-970c-52069ea0acd4)
   Here, kasan is turned off in the add_delaylist code, because the operation of add_delaylist is not locked.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE [nuttx]

Posted by "W-M-R (via GitHub)" <gi...@apache.org>.
W-M-R commented on code in PR #15461:
URL: https://github.com/apache/nuttx/pull/15461#discussion_r1908139678


##########
mm/mm_heap/mm_initialize.c:
##########
@@ -209,6 +211,7 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
   sched_note_heap(NOTE_HEAP_ADD, heap, heapstart, heapsize,
                   heap->mm_curused);
   mm_unlock(heap);
+  kasan_hw_open();

Review Comment:
   This is a great decision.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE [nuttx]

Posted by "W-M-R (via GitHub)" <gi...@apache.org>.
W-M-R commented on code in PR #15461:
URL: https://github.com/apache/nuttx/pull/15461#discussion_r1909834708


##########
mm/kasan/mte_tags.c:
##########
@@ -0,0 +1,97 @@
+/****************************************************************************
+ * mm/kasan/mte_tags.c

Review Comment:
   This approach is to implement the mte operation implemented in arm64 in arch, but the kasan api should be implemented in mm/kasan, right? Instead of implementing the kasan api on arch/arm64?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE [nuttx]

Posted by "W-M-R (via GitHub)" <gi...@apache.org>.
W-M-R commented on code in PR #15461:
URL: https://github.com/apache/nuttx/pull/15461#discussion_r1924953690


##########
arch/arm64/include/memtag.h:
##########
@@ -41,18 +41,18 @@ void up_memtag_bypass(bool bypass);
 
 /* Set memory tags for a given memory range */
 
-void up_memtag_set_tag(const void *addr, size_t size);
+void up_memtag_set_tag(FAR const void *addr, size_t size);

Review Comment:
   FAR only needs to be added to the general code, right?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #15461:
URL: https://github.com/apache/nuttx/pull/15461#issuecomment-2585069029

   please fix the conflict


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE [nuttx]

Posted by "anchao (via GitHub)" <gi...@apache.org>.
anchao commented on code in PR #15461:
URL: https://github.com/apache/nuttx/pull/15461#discussion_r1907990997


##########
mm/kasan/mte_tags.c:
##########
@@ -0,0 +1,95 @@
+/****************************************************************************
+ * mm/kasan/mte_tags.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/mm/mm.h>
+#include <nuttx/mm/kasan.h>
+
+#include <arch/mte.h>
+
+#include <assert.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+static void *kasan_set_poison(FAR const void *addr, size_t size, uint8_t tag)
+{
+  FAR const void *tag_addr;
+
+  /* Get random labels and the addresses after labeling */
+
+  tag_addr = arm64_mte_get_tagged_addr(addr, tag);
+
+  /* Add MTE hardware label to memory block */
+
+  arm64_mte_set_tag(tag_addr, size);
+
+  return (void *)tag_addr;

Review Comment:
   FAR



##########
mm/mm_heap/mm_initialize.c:
##########
@@ -109,6 +109,8 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
 #if CONFIG_MM_REGIONS > 1
   int idx;
 
+  kasan_hw_close();

Review Comment:
   could be removed from initialize?



##########
mm/mm_heap/mm_initialize.c:
##########
@@ -209,6 +211,7 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
   sched_note_heap(NOTE_HEAP_ADD, heap, heapstart, heapsize,
                   heap->mm_curused);
   mm_unlock(heap);
+  kasan_hw_open();

Review Comment:
   why not move hw open/close into mm_lock/unlock?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE [nuttx]

Posted by "W-M-R (via GitHub)" <gi...@apache.org>.
W-M-R commented on code in PR #15461:
URL: https://github.com/apache/nuttx/pull/15461#discussion_r1924951610


##########
arch/arm64/include/memtag.h:
##########
@@ -41,18 +41,18 @@ void up_memtag_bypass(bool bypass);
 
 /* Set memory tags for a given memory range */
 
-void up_memtag_set_tag(const void *addr, size_t size);
+void up_memtag_set_tag(FAR const void *addr, size_t size);

Review Comment:
   Is it necessary to add FAR to the pointers of only universal code?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #15461:
URL: https://github.com/apache/nuttx/pull/15461#issuecomment-2611359413

   @W-M-R please fix conflict and the comment


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 closed pull request #15461: mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE
URL: https://github.com/apache/nuttx/pull/15461


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #15461:
URL: https://github.com/apache/nuttx/pull/15461#discussion_r1909403906


##########
mm/kasan/hook.c:
##########
@@ -123,6 +125,8 @@ static uint32_t g_region_init;
  * Private Functions
  ****************************************************************************/
 
+#ifndef CONFIG_MM_KASAN_MTE_TAGS

Review Comment:
   why need empty kasan_show_memory in MTE case



##########
mm/kasan/mte_tags.c:
##########
@@ -0,0 +1,97 @@
+/****************************************************************************
+ * mm/kasan/mte_tags.c

Review Comment:
   why not move the implentation to arch/arm64? like the custom heap manager for sim



##########
mm/kasan/hook.c:
##########
@@ -252,6 +256,10 @@ static inline void kasan_check_report(FAR const void *addr, size_t size,
 #  endif
 #endif
 }
+#else
+#define kasan_check_report(addr, size, is_write, return_address)
+#define kasan_report(addr, size, is_write, return_address)

Review Comment:
   ```
   #  define kasan_check_report(addr, size, is_write, return_address)
   #  define kasan_report(addr, size, is_write, return_address)
   ```



##########
include/nuttx/mm/kasan.h:
##########
@@ -201,6 +203,23 @@ void kasan_stop(void);
 
 int kasan_debugpoint(int type, FAR void *addr, size_t size);
 
+#ifndef CONFIG_MM_KASAN_MTE_TAGS
+#  define kasan_hw_open()

Review Comment:
   why add hw_ 



##########
mm/mm_heap/mm_free.c:
##########
@@ -49,6 +49,8 @@ static void add_delaylist(FAR struct mm_heap_s *heap, FAR void *mem)
 
   /* Delay the deallocation until a more appropriate time. */
 
+  kasan_hw_close();
+
   flags = up_irq_save();

Review Comment:
   let's extract mm_lock_irq/mm_unlock_irq



##########
include/nuttx/mm/kasan.h:
##########
@@ -201,6 +203,23 @@ void kasan_stop(void);
 
 int kasan_debugpoint(int type, FAR void *addr, size_t size);
 
+#ifndef CONFIG_MM_KASAN_MTE_TAGS
+#  define kasan_hw_open()
+#  define kasan_hw_close()
+#else
+/****************************************************************************
+ * Name: kasan_hw_open
+ ****************************************************************************/
+
+void kasan_hw_open(void);

Review Comment:
   kasaon_bypass(bool bypass);



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE [nuttx]

Posted by "nuttxpr (via GitHub)" <gi...@apache.org>.
nuttxpr commented on PR #15461:
URL: https://github.com/apache/nuttx/pull/15461#issuecomment-2576675863

   [**\[Experimental Bot, please feedback here\]**](https://github.com/search?q=repo%3Aapache%2Fnuttx+13552&type=issues)
   
   
   
   This PR summary does not adequately meet the NuttX requirements. Here's a breakdown and suggestions for improvement:
   
   **Weaknesses:**
   
   * **Summary is too brief and technical.** It assumes the reader understands KASAN and MTE.  It doesn't explain *why* this change is necessary. What problem does it solve? What benefits does it bring?  What are the goals?
   * **Functional change description is unclear.**  "call arm64_mte to implement tagging" is vague.  What does tagging mean in this context? How does it work at a high level?
   * **Log dump is excessive and unhelpful.**  The massive log dump doesn't highlight the relevant changes. It shows a crash, which isn't a good demonstration of functionality.  It should show specific examples of KASAN catching memory errors.
   * **Impact section is insufficient.** Simply referencing other PRs doesn't explain the impact of *this* PR.  Each PR should stand on its own.  The impact on users, build, hardware, documentation, security, and compatibility should be explicitly stated.
   * **Testing section lacks detail on the host system.**  It only mentions the target.  What OS, compiler version, and tools were used on the host build machine?
   * **No "before" and "after" comparison.** The testing logs are all "after." There's no demonstration of how behavior changed due to the PR.  Ideally, the logs should show a memory error being detected that wasn't detected before.
   
   
   **Suggestions for Improvement:**
   
   * **Expand the Summary:**
       * Explain the purpose of KASAN and MTE in simple terms. Why is memory protection important?
       * State the specific goal of this PR.  Is it to enable KASAN support? To improve existing KASAN functionality?
       * Summarize the implementation approach at a high level.
   * **Clarify the Functional Change:**
       * Describe how `mte_tags.c` interacts with `arm64_mte`.
       * Explain the tagging mechanism. What gets tagged, and how are tags used for error detection?
   * **Improve the Testing Section and Logs:**
       * Provide host build details (OS, compiler, etc.).
       * Show "before" logs where a memory error goes undetected (if possible).
       * Show "after" logs where the same error is caught by KASAN.
       * Focus on the relevant log entries.  Trim the excessive output.
       * Add a test case specifically designed to trigger and catch a memory error.
   * **Complete the Impact Section:**
       * Explain the impact independently of other PRs.  Even if it depends on other changes, describe how *this* PR affects the system.
       * Address all the impact points explicitly (user, build, hardware, documentation, security, compatibility).  Use "NO" or "YES" followed by a brief explanation.  Don't leave them blank.
   
   
   **Example of an Improved Summary:**
   
   This PR implements KASAN (Kernel Address Sanitizer) memory protection for ARM64 hardware using Memory Tagging Extension (MTE). KASAN helps detect memory errors like out-of-bounds accesses and use-after-free bugs. MTE provides hardware support for tagging memory allocations, enabling efficient error detection.
   
   This implementation adds `mte_tags.c`, which utilizes the `arm64_mte` functions to tag memory blocks during allocation and deallocation.  When a memory access occurs, the hardware compares the access tag with the memory tag. A mismatch indicates a memory error, triggering a fault. This PR enables KASAN by default when `MM_KASAN_MTE_TAGS` is defined for ARM64 MTE-enabled platforms.
   
   
   By making these improvements, the PR will be much clearer, easier to review, and more likely to be accepted. Remember to follow the contributing guidelines and provide a concise yet comprehensive description of your changes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE [nuttx]

Posted by "W-M-R (via GitHub)" <gi...@apache.org>.
W-M-R commented on code in PR #15461:
URL: https://github.com/apache/nuttx/pull/15461#discussion_r1924951610


##########
arch/arm64/include/memtag.h:
##########
@@ -41,18 +41,18 @@ void up_memtag_bypass(bool bypass);
 
 /* Set memory tags for a given memory range */
 
-void up_memtag_set_tag(const void *addr, size_t size);
+void up_memtag_set_tag(FAR const void *addr, size_t size);

Review Comment:
   Is it necessary to add FAR to the pointers of only universal code?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #15461:
URL: https://github.com/apache/nuttx/pull/15461#discussion_r1924999272


##########
arch/arm64/include/memtag.h:
##########
@@ -41,18 +41,18 @@ void up_memtag_bypass(bool bypass);
 
 /* Set memory tags for a given memory range */
 
-void up_memtag_set_tag(const void *addr, size_t size);
+void up_memtag_set_tag(FAR const void *addr, size_t size);

Review Comment:
   yes



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #15461:
URL: https://github.com/apache/nuttx/pull/15461#discussion_r1924946050


##########
arch/arm64/include/memtag.h:
##########
@@ -41,18 +41,18 @@ void up_memtag_bypass(bool bypass);
 
 /* Set memory tags for a given memory range */
 
-void up_memtag_set_tag(const void *addr, size_t size);
+void up_memtag_set_tag(FAR const void *addr, size_t size);

Review Comment:
   remove FAR, arm64 specific code should drop FAR



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #15461:
URL: https://github.com/apache/nuttx/pull/15461#discussion_r1925157486


##########
mm/mm_heap/mm_malloc_size.c:
##########
@@ -40,10 +41,14 @@
 size_t mm_malloc_size(FAR struct mm_heap_s *heap, FAR void *mem)
 {
   FAR struct mm_freenode_s *node;
+  size_t size;

Review Comment:
   why not squash to the previous patch



##########
arch/arm64/include/memtag.h:
##########
@@ -0,0 +1,58 @@
+/****************************************************************************
+ * arch/arm64/include/memtag.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef ___ARCH_ARM64_INCLUDE_MEMTAG_H
+#define ___ARCH_ARM64_INCLUDE_MEMTAG_H
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* Initialize MTE settings and enable memory tagging */

Review Comment:
   need move to arch.h



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org