casaroli opened a new pull request, #20952: URL: https://github.com/apache/nuttx/pull/20952
## Summary Some `*_VEND` macros of the address environment are the first address after a region (`ARCH_TEXT_VEND`, `ARCH_DATA_VEND`, `ARCH_HEAP_VEND`), and some are the last address of a region (`ARCH_ADDRENV_VEND`, `ARCH_SHM_VEND`, `ARCH_KMAP_VEND`). Some users compared them the wrong way: - `riscv_fillpage()` (RISC-V, `CONFIG_PAGING`) compared the page address with `<= ARCH_TEXT_VEND` (and `.data`, heap). An access to the first page after a region did not fault: the kernel mapped a new page there with the flags of the region. - All users of the inclusive ends compared with `< VEND`, so the last byte of each region was outside it. The current callers pass page-aligned addresses and get the same result, but any other address in the last page was wrong. `ARCH_SCRATCH_VBASE` was the last byte of the shared memory region; nothing uses it. The fix of `riscv_fillpage()` showed a third problem. `up_addrenv_create()` on RISC-V and arm64 adds pages to the heap (the fix for #5811), and libelf asks for the whole heap region. With fixed regions the heap went past `ARCH_HEAP_VEND`: on `rv-virt:knsh64_paging` the end node of the heap was in the page after the region, and it worked only because of the wrong `<=`. On arm64 the pages after the region were mapped and could be read. With fixed regions the heap now stops at the end of its region on both arches. The first commit only adds three blank lines that nxstyle asks for in the touched files. ## Impact RISC-V and arm64 kernel builds with fixed regions: the user heap no longer goes past `ARCH_HEAP_VEND`. No arm64 defconfig uses fixed regions, so no arm64 board changes. RISC-V `CONFIG_PAGING`: an access after a region ends the program with `SIGSEGV`. The `<=` change gives the same result for page-aligned addresses. ## Testing Test program `rvend.c` on `rv-virt:knsh64_paging` (kernel build, QEMU) with `CONFIG_SCHED_CHILD_STATUS`: a child reads the last page of `.text`, `.data` and the heap, and the first page after each region. | Access | master | this PR | |---|---|---| | last page of `.text`, `.data`, heap | read | read | | page after `.text` (0xc0080000) | read: FAIL | `SIGSEGV`: PASS | | page after `.data` (0xc0180000) | read: FAIL | `SIGSEGV`: PASS | | page after the heap (0xc1000000) | read: FAIL | `SIGSEGV`: PASS | | `ostest` | `Exiting with status 0` | `Exiting with status 0` | The same test on `qemu-armv8a:knsh` (kernel, QEMU with HVF) with fixed regions (`ARCH_TEXT_VBASE=0xC0000000`, `ARCH_DATA_VBASE=0xC0400000`, `ARCH_HEAP_VBASE=0xC0800000`, `ARCH_HEAP_NPAGES=256`, `ARCH_PGPOOL_SIZE=16777216`): | Access | without the arm64 change | this PR | |---|---|---| | last page of the heap (0xc08ff000) | read | read | | page after the heap (0xc0900000) | read: FAIL | `SIGSEGV`: PASS | | `ostest` | `Exiting with status 0` | `Exiting with status 0` | `rv-virt:knsh64` (kernel, QEMU): `ostest` exits with status 0. `qemu-armv8a:knsh` (kernel) and `qemu-armv8a:nsh` (flat): `ostest` exits with status 0 (QEMU with HVF). `qemu-armv7a:knsh` (kernel, armv7-a), `rv-virt:nsh64` (flat) and `qemu-intel64:knsh_romfs` (kernel, x86_64) build. `tools/checkpatch.sh -c -u -m -g` passes. -- 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]
