Skip to content

[ROM_EXT] Leave unverified flash region locked - #31352

Open
siemen11 wants to merge 1 commit into
lowRISC:earlgrey_1.0.0from
siemen11:epmp_lock_unverified_flash
Open

siemen11 wants to merge 1 commit into
lowRISC:earlgrey_1.0.0from
siemen11:epmp_lock_unverified_flash

Conversation

@siemen11

@siemen11 siemen11 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

The ROM_EXT calls epmp_clear_lock_bits before the jump to BL0. Leave the unverified part of flash locked throughout this jump.

@siemen11
siemen11 requested review from GillonB and sasdf September 16, 2026 21:53
@siemen11
siemen11 requested a review from a team as a code owner September 16, 2026 21:53
@siemen11 siemen11 added the CherryPick:master This PR should be cherry-picked to master label Sep 16, 2026
@siemen11
siemen11 requested review from moidx and removed request for a team September 16, 2026 21:53
@sasdf
sasdf requested a review from cfrantz September 17, 2026 01:32

@sasdf sasdf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect to leave all the lock bit (e.g. for regions like RAM / MMIO), and let the OwnerSw's M-mode to reconfigure, which will protect also the M-mode early boot code on the OwnerSw side.

But LGTM if we want to change the behavior incrementally.

@siemen11
siemen11 force-pushed the epmp_lock_unverified_flash branch from 58fe490 to 69564c1 Compare September 17, 2026 08:35
@siemen11

Copy link
Copy Markdown
Contributor Author

I would expect to leave all the lock bit (e.g. for regions like RAM / MMIO), and let the OwnerSw's M-mode to reconfigure, which will protect also the M-mode early boot code on the OwnerSw side.

But LGTM if we want to change the behavior incrementally.

Thanks @sasdf, that makes the change a bit nicer

@siemen11 siemen11 added the CI:Rerun Rerun failed CI jobs label Sep 17, 2026
@github-actions github-actions Bot removed the CI:Rerun Rerun failed CI jobs label Sep 17, 2026
@sasdf

sasdf commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Thanks, I'll try with our ownersw tomorrow to test its compatibility.

@siemen11 siemen11 added the CI:Rerun Rerun failed CI jobs label Sep 18, 2026
@github-actions github-actions Bot removed the CI:Rerun Rerun failed CI jobs label Sep 18, 2026
SEC_MMIO_WRITE_INCREMENT(kFlashCtrlSecMmioCreatorInfoPagesLockdown +
kOtpSecMmioCreatorSwCfgLockDown);

epmp_clear_lock_bits();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of deleting epmp_clear_lock_bits() entirely:

  • Disable Entry 11 (Stack Guard) before jumping to OwnerSw (OwnerSw has its own stack).
  • Clear lock bits on Entries 0..11, but preserve the lock bit on Entry 12 (pmpcfg3 byte 0).
--- a/sw/device/silicon_creator/rom_ext/rom_ext.c
+++ b/sw/device/silicon_creator/rom_ext/rom_ext.c
@@ -304,6 +304,11 @@ static rom_error_t rom_ext_boot(boot_data_t *boot_data, boot_log_t *boot_log,
   SEC_MMIO_WRITE_INCREMENT(kFlashCtrlSecMmioCreatorInfoPagesLockdown +
                            kOtpSecMmioCreatorSwCfgLockDown);
 
+  // Disable the ROM_EXT stack guard; OwnerSw manages its own stack.
+  epmp_clear(11);
+
+  // Clear lock bits on entries 0..11 only (pmpcfg0..2).
+  // Keep Entry 12 (physical flash) locked (L=1, RO) in pmpcfg3 to prevent
+  // M-mode execution on the inactive slot via fault injection on line 380.
+  CSR_CLEAR_BITS(CSR_REG_PMPCFG0, 0x80808080);
+  CSR_CLEAR_BITS(CSR_REG_PMPCFG1, 0x80808080);
+  CSR_CLEAR_BITS(CSR_REG_PMPCFG2, 0x80808080);
+
   // Configure address translation, compute the epmp regions and the entry
   // point for the virtual address in case the address translation is enabled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the help Vadim! I updated the commit already to reflect this. We can then test further to see whether this fits the bill

@vsukhoml

Copy link
Copy Markdown

Let ROM_EXT only lock Entry 12 (physical flash) and disable Entry 11 (stack guard), while clearing lock bits on Entries 0..11. This fixes the vulnerability immediately and does not break existing deployed OwnerSw images.

@siemen11
siemen11 force-pushed the epmp_lock_unverified_flash branch 3 times, most recently from de7be8a to 69714f3 Compare September 19, 2026 09:28
Previously, when entry_point was being jumped to, the unverified flash
regions by secure boot were set to executable.
In order to provide better protection, leave that region unexecutable.

Signed-off-by: Siemen Dhooghe <sdhooghe@google.com>
@siemen11
siemen11 force-pushed the epmp_lock_unverified_flash branch from 69714f3 to 61907fa Compare September 19, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CherryPick:master This PR should be cherry-picked to master

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants