Commit e30db2d5 authored by Yong Cong Sin's avatar Yong Cong Sin Committed by Dan Kalowsky
Browse files

arch: riscv: reset global pointer on exception

Reset the gp on exception entry from u-mode to protect the kernel
against a possible rogue user thread.

Signed-off-by: default avatarYong Cong Sin <yongcong.sin@gmail.com>
Signed-off-by: default avatarYong Cong Sin <ycsin@meta.com>
parent de3a8456
Loading
Loading
Loading
Loading
+8 −0
Changes for arch/riscv/core/isr.S: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -163,6 +163,14 @@ SECTION_FUNC(exception.entry, _isr_wrapper)
	lr t0, ___cpu_t_current_OFFSET(s0)
	lr tp, _thread_offset_to_tls(t0)

	/* Make sure global pointer is sane */
#ifdef CONFIG_RISCV_GP
	.option push
	.option norelax
	la gp, __global_pointer$
	.option pop
#endif /* CONFIG_RISCV_GP */

	/* Clear our per-thread usermode flag */
	lui t0, %tprel_hi(is_user_mode)
	add t0, t0, tp, %tprel_add(is_user_mode)