[PATCH 0/2] lib: sbi: fix two hart hangs reachable through the temporary PMP mapping
liutong
liutong at iscas.ac.cn
Thu Nov 19 07:55:09 PST 2026
On a build with Smepmp, supervisor software can stop a hart for good
with a single ecall, in two different ways.
sbi_hart_smepmp_temp_map_range() rounds a request up to a NAPOT block,
aligned down, and programs it into PMP entry 0 with the shared-data
encoding, which grants execute permission to no mode. Entry 0 has the
highest priority, so a block that reaches the firmware takes M-mode's
execute permission on its own text away. mtvec is in that text, so the
trap entry faults too and nothing is printed.
The backend also declines when no block fits at all, and no caller
looks at the return value, so the access goes ahead regardless and
faults the same way.
Patch 1 makes the 13 call sites check. Patch 2 rejects a block that
reaches outside the range the caller validated. Each is needed:
neither alone fixes both paths, and in that order every commit is safe
to stop at.
Patch 1 is the check described here:
https://lore.kernel.org/opensbi/20261012022033.1165060-1-sebasjosue84@gmail.com/
Measured on qemu virt, -m 1G, -smp 1, fw_jump, over 61f1973b, with
sbi_debug_console_write():
num_bytes=0x200001 base=0x80200000, block rounds to
[0x80000000, 0x807fffff]
before no output, hart gone, killed at 90s
patch 1 only no output, hart gone
both SBI_ERR_INVALID_PARAM
num_bytes=2^63, no block fits
before no output, hart gone
patch 1 only SBI_ERR_INVALID_PARAM
both SBI_ERR_INVALID_PARAM
num_bytes=0x200001 base=0x80400000, block misses the firmware
2 MB written, unchanged
-cpu rv64, no Smepmp, no temporary mapping is programmed
2 MB written, unchanged
Built for generic RV64 and RV32.
liutong (2):
lib: sbi: check the result of sbi_hart_protection_temp_map_range()
lib: sbi: pmp: do not grant a NAPOT block outside the caller's range
lib/sbi/sbi_dbtr.c | 18 +++++++++++++-----
lib/sbi/sbi_ecall_dbcn.c | 3 ++-
lib/sbi/sbi_hart_pmp.c | 19 +++++++++++++++++--
lib/sbi/sbi_mpxy.c | 24 ++++++++++++++++++------
lib/sbi/sbi_pmu.c | 3 ++-
lib/sbi/sbi_sse.c | 10 ++++++++--
6 files changed, 60 insertions(+), 17 deletions(-)
base-commit: 61f1973bd50338b36c52dc34006f76d464ca4f34
--
2.34.1
More information about the opensbi
mailing list