[BUG] Crash in setenv with Invalid Pointer #15401
Labels
Arch: risc-v
Issues related to the RISC-V (32-bit or 64-bit) architecture
Area: Kernel
Kernel issues
OS: Linux
Issues related to Linux (building system, etc)
Type: Bug
Something isn't working
Description / Steps to reproduce the issue
When using the
setenv
function in NuttX, I encountered a potential issue where the function crashes if an invalid or inaccessible pointer is passed to the value parameter. Specifically:When calling my_setenv(0x8001, 0x0, 0x9), the program runs without any issues. However, when calling my_setenv(0x7, 0x5, 0x8), the program crashes.
Use the following code:
Compile and run the program using:
cmake -B build_new4 -DBOARD_CONFIG=rv-virt:nsh64 -GNinja cmake --build build_new4 -t clean && cmake --build build_new4
run using
Then the program keeps crashing.
Using GDB, I traced the issue to the following line in setenv:
When
value=0x5
, the program attempts to dereference an inaccessible memory address, resulting in a crash. It seems the pointer is dereferenced without first checking whether it is valid or accessible.To handle such cases more robustly, the function could validate the accessibility of the value pointer before dereferencing it. For example, using access_ok() might help ensure the pointer is valid.
On which OS does this issue occur?
[OS: Linux]
What is the version of your OS?
Debian GNU/Linux 12 (bookworm)
NuttX Version
fc993539aa
Issue Architecture
[Arch: risc-v]
Issue Area
[Area: Kernel]
Verification
The text was updated successfully, but these errors were encountered: