Skip to content

Commit 7b222d1

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 229d668 commit 7b222d1

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
@@ -520,7 +520,7 @@ void z_riscv_pmp_stackguard_enable(struct k_thread *thread)
520520

521521
/* Write our m-mode MPP entries */
522522
write_pmp_entries(global_pmp_end_index, thread->arch.m_mode_pmp_end_index,
523-
false /* no need to clear to the end */,
523+
true,
524524
PMP_M_MODE(thread));
525525

526526
if (PMP_DEBUG_DUMP) {

0 commit comments

Comments
 (0)