Skip to content

Commit c171cfd

Browse files
committed
riscv: pmp: Ensure trailing PMP entries are cleared
In `z_riscv_pmp_stackguard_enable`, the call to `write_pmp_entries` has been updated to set the `clear_trailing_entries` argument to `true`. This change ensures that any PMP entries beyond the ones being actively configured are disabled. This is critical for systems, such as firmwares transitioning between different execution stages (e.g., from a Read-Only (RO) phase to a Read-Write (RW) phase), which may have distinct PMP setups. Without clearing trailing entries, stale configurations from a previous stage could persist. These leftover entries could lead to incorrect memory access permissions, resulting in functional bugs or potential security vulnerabilities. This commit guarantees a clean PMP state after an update.
1 parent e11a310 commit c171cfd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/riscv/core/pmp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ void z_riscv_pmp_stackguard_enable(struct k_thread *thread)
522522

523523
/* Write our m-mode MPP entries */
524524
write_pmp_entries(global_pmp_end_index, thread->arch.m_mode_pmp_end_index,
525-
false /* no need to clear to the end */,
525+
true,
526526
PMP_M_MODE(thread));
527527

528528
if (PMP_DEBUG_DUMP) {

0 commit comments

Comments
 (0)