huojianchaoyy opened a new pull request, #21669: URL: https://github.com/apache/nuttx/pull/21669
*Note: Please adhere to [Contributing Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).* ## Summary `coredump_add_memory_region()` starts with `count = 1` for the end marker. When no region has been registered yet (`g_regions` is NULL, which is the case without `CONFIG_BOARD_MEMORY_RANGE`), the `memcpy()` of the old table reads one `struct memory_region_s` from address 0. The copied data is overwritten right after, but the read itself is a NULL pointer access: it faults on targets where address 0 is not mapped and UBSan reports it. `arm_coredump_add_region()` (armv6-m / armv7-m / armv8-m with `CONFIG_ARM_COREDUMP_REGION`) hits this at boot, as it is the first caller. The fix copies the old table only when there is one. ## Impact Only `coredump_add_memory_region()` in `sched/misc/coredump.c` changes. No API, Kconfig, build or documentation change. ## Testing Host: Ubuntu 22.04 x86_64, GCC 13.4.0 (sim), Arm GNU Toolchain 13.2.rel1 (arm), GCC 13.4.0 aarch64-none-elf, CMake 3.23 + Ninja. Runtime tests on QEMU 6.2 only. Builds: - `mps2-an500:nsh` with `CONFIG_COREDUMP=y CONFIG_BOARD_COREDUMP_SYSLOG=y CONFIG_ARM_COREDUMP_REGION=y CONFIG_NSH_DISABLE_MW=n` - `qemu-armv8a:nsh` with `CONFIG_COREDUMP=y CONFIG_BOARD_COREDUMP_SYSLOG=y` - `sim:nsh` `./tools/checkpatch.sh -c -u -m -g HEAD~1..HEAD` passes. Boot of `mps2-an500:nsh` on QEMU with the options above plus `CONFIG_MM_UBSAN=y` and `CONFIG_MM_UBSAN_OPTION="-fsanitize=null,nonnull-attribute"`: Before: ``` nx_start: Entry uart_register: Registering /dev/console uart_register: Registering /dev/ttyS0 ubsan_prologue: ================================================================================ ubsan_prologue: UBSAN: nonnull-arg in sched/misc/coredump.c:900:3 ubsan_epilogue: ================================================================================ ubsan_prologue: ================================================================================ ubsan_prologue: UBSAN: null-pointer-dereference in libs/libc/string/lib_memcpy.c:51:17 handle_null_ptr_deref: load of null pointer of type 'unsigned char' ubsan_epilogue: ================================================================================ work_start_highpri: Starting high-priority kernel worker thread(s) ``` After: ``` nx_start: Entry uart_register: Registering /dev/console uart_register: Registering /dev/ttyS0 work_start_highpri: Starting high-priority kernel worker thread(s) nxtask_activate: hpwork pid=1,TCB=0x6003e2c8 nxtask_activate: AppBringUp pid=2,TCB=0x6003f3b0 nx_start_application: Starting init thread ``` A bus fault triggered from nsh (without UBSan) still produces a complete core dump after the change: ``` nsh> mw 0xf0000000=1 arm_hardfault: Hard Fault escalation: arm_busfault: PANIC!!! Bus Fault: ... dump_assert_info: Assertion failed panic: at file: /arch/arm/src/armv7-m/arm_busfault.c:108 task: nsh_main process: nsh_main 0x18c59 ... coredump_dump_syslog: Start coredump: 7F454C4601010100000000000000000004002800010000000000000034000000000000000004000534002000060000000000000004000000F400000000000000 ... coredump_dump_syslog: Finish coredump. hex formatted ``` -- 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]
