arch: riscv: userspace: potential security risk when CONFIG_RISCV_GP=y
#81372
Labels
area: RISCV
RISCV Architecture (32-bit & 64-bit)
area: Security
Security
bug
The issue is a bug, or the PR is fixing a bug
Describe the bug
When the Global Pointer (GP) relative addressing is enabled (
CONFIG_RISCV_GP=y
), thegp
reg points at 0x800 bytes past the start of the.sdata
section which is then used by the linker to relax accesses to global symbols.zephyr/include/zephyr/arch/riscv/common/linker.ld
Lines 305 to 319 in c0a0e6a
However, the
gp
reg is not protected against write from userspace, this means that a rogue userspace can corrupt thegp
reg, and cause the compiled instruction to access random addresses.To Reproduce
Steps to reproduce the behavior:
qemu_riscv64
board with userspace andCONFIG_RISCV_GP
enabledgp
registergp
reg from one userspace threadgp
reg is now changedExpected behavior
The
gp
register should remain a constant.Impact
A rogue thread can corrupt the
gp
reg and cause the entire system to hard fault at best, at worst, it can potentially trick the system to access another set of random global symbols.Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: