Skip to content

Commit e30db2d

Browse files
ycsindkalowsk
authored andcommitted
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: Yong Cong Sin <[email protected]> Signed-off-by: Yong Cong Sin <[email protected]>
1 parent de3a845 commit e30db2d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

arch/riscv/core/isr.S

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ SECTION_FUNC(exception.entry, _isr_wrapper)
163163
lr t0, ___cpu_t_current_OFFSET(s0)
164164
lr tp, _thread_offset_to_tls(t0)
165165

166+
/* Make sure global pointer is sane */
167+
#ifdef CONFIG_RISCV_GP
168+
.option push
169+
.option norelax
170+
la gp, __global_pointer$
171+
.option pop
172+
#endif /* CONFIG_RISCV_GP */
173+
166174
/* Clear our per-thread usermode flag */
167175
lui t0, %tprel_hi(is_user_mode)
168176
add t0, t0, tp, %tprel_add(is_user_mode)

0 commit comments

Comments
 (0)