Skip to content

Conversation

fsammoura1980
Copy link
Contributor

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 particularly critical for systems transitioning between different execution stages, such as jumping from Read-Only (RO) firmware to Read-Write (RW) firmware, where each stage may define its own set of PMP entries.

Without clearing, stale configurations from the RO stage could persist after transitioning to the RW stage. While the presence of a catch-all PMP entry might render this change somewhat cosmetic in terms of security, explicitly clearing unused trailing entries ensures a cleaner PMP state. This not only helps prevent subtle functional bugs due to unexpected lingering permissions but also significantly improves clarity during visual debugging of the PMP register settings.

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 particularly critical for systems
transitioning between different execution stages, such as jumping from
Read-Only (RO) firmware to Read-Write (RW) firmware, where each stage
may define its own set of PMP entries.

Without clearing, stale configurations from the RO stage could persist
after transitioning to the RW stage. While the presence of a catch-all
PMP entry might render this change somewhat cosmetic in terms of security,
explicitly clearing unused trailing entries ensures a cleaner PMP state.
This not only helps prevent subtle functional bugs due to unexpected
lingering permissions but also significantly improves clarity during
visual debugging of the PMP register settings.

Signed-off-by: Firas Sammoura <[email protected]>
@zephyrbot zephyrbot added size: XS A PR changing only a single line of code area: RISCV RISCV Architecture (32-bit & 64-bit) labels Oct 9, 2025
Copy link

sonarqubecloud bot commented Oct 9, 2025

@fkokosinski
Copy link
Member

Not sure if this is the right approach, since this will add an unnecessary overhead on every context switch for the vast majority of platforms.

If we have a special need to clear PMP entries from a previous stage, can we implement a conditionally executed routine (configured with Kconfig) to clear said PMP entries?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: RISCV RISCV Architecture (32-bit & 64-bit) size: XS A PR changing only a single line of code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants