Rrooach opened a new issue, #12855:
URL: https://github.com/apache/nuttx/issues/12855

   ### Description / Steps to reproduce the issue
   
   
   I'm encountering an illegal memory read error when running NuttX kernel 
built with (ASAN) for full image instrumentation. The kernel fails to run due 
to this error.
   
   
   **Steps to Reproduce:**
   1. Build NuttX with ASAN enabled.
   2. Start the kernel using QEMU with the following command:
       ```bash
       qemu-system-riscv64 -semihosting -M virt,aclint=on -cpu rv64 -smp 8 
-bios none -kernel /path/to/nuttx/build_t/nuttx -nographic
       ```
   3. the console output with 
       ```bash
       kasan_report: kasan detected a read access error, address at 0x81f81580, 
size is 8, return address: 0x80006ec2
       ```
    
   **GDB Debugging Session:**
   1. Connect to QEMU using GDB:
       ```bash
       gdb /path/to/nuttx/build_t/nuttx
       (gdb) target remote :1234
       ```
   2. Set breakpoints and continue execution:
       ```gdb
       (gdb) b *0x81f81580
       Breakpoint 2 at 0x81f81580
       (gdb) b *0x80006ec2
       Breakpoint 3 at 0x80006ec2: file /path/to/nuttx/mm/kasan/kasan.c, line 
110.
       (gdb) c
       Continuing.
       ```
   3. Backtrace upon hitting the breakpoint:
       ```gdb
       Thread 1 hit Breakpoint 3, 0x0000000080006ec2 in kasan_mem_to_shadow 
(ptr=ptr@entry=0x81f81587,
           bit=bit@entry=0x80055afc <waiter_state>, size=1)
           at /path/to/nuttx/mm/kasan/kasan.c:110
       (gdb) bt
       #0  0x0000000080006ec2 in kasan_mem_to_shadow (ptr=ptr@entry=0x81f81587,
           bit=bit@entry=0x80055afc <waiter_state>, size=1)
           at /path/to/nuttx/mm/kasan/kasan.c:110
       #1  0x0000000080007078 in kasan_is_poisoned (size=8, addr=0x81f81580)
           at /path/to/nuttx/mm/kasan/kasan.c:162
       ...
       #49 0x0000000080015700 in mm_addregion (heap=heap@entry=0x80056340,
           heapstart=heapstart@entry=0x800565e8, heapsize=<optimized out>, 
heapsize@entry=33200664)
           at /path/to/nuttx/mm/mm_heap/mm_initialize.c:140
       #50 0x000000008001584e in mm_initialize (name=name@entry=0x8003d990 
"Umem", heapstart=0x800565e8,
           heapstart@entry=0x80056340, heapsize=33200664, 
heapsize@entry=33201344)
           at /path/to/nuttx/mm/mm_heap/mm_initialize.c:279
       #51 0x0000000080015638 in umm_initialize (heap_start=0x80056340, 
heap_size=33201344)
           at /path/to/nuttx/mm/umm_heap/umm_initialize.c:89
       #52 0x0000000080008d58 in nx_start () at 
/path/to/nuttx/sched/init/nx_start.c:584
       #53 0x00000000800005ee in qemu_rv_start (mhartid=<optimized out>, 
dtb=0x87e00000 "\320\r\376\355")
           at /path/to/nuttx/arch/risc-v/src/qemu-rv/qemu_rv_start.c:171
       #54 0x000000008000004c in _stext ()
           at /path/to/nuttx/arch/risc-v/src/qemu-rv/qemu_rv_head.S:74
       ```
       
    It appears that there is an illegal memory read operation in the nx_start() 
function, which is causing the kernel to fail. The error is detected by KASAN, 
and further investigation using GDB points to the kasan_mem_to_shadow function 
in kasan.c.
       
   Do you have any idea what might cause this error?
   
   ### On which OS does this issue occur?
   
   [Linux]
   
   ### What is the version of your OS?
   
   Ubuntu
   
   ### NuttX Version
   
   masrer / git version 4197b5aec87705844c7e4c17128338c215c40b54
   
   ### Issue Architecture
   
   [risc-v]
   
   ### Issue Area
   
   [Kernel], [Memory Management]
   
   ### Verification
   
   - [X] I have verified before submitting the report.


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to