[PATCH v2 1/2] lib: sbi_ecall_hsm: Reject oversized hart IDs
Shibo Zhu
3499129952 at qq.com
Thu Oct 29 20:05:02 PDT 2026
The HSM SBI interface passes hart IDs in XLEN-wide registers, while
OpenSBI's internal HSM APIs use u32 hart IDs. On RV64, values with upper
32 bits set are truncated before validation and can alias a valid hart.
Reject oversized target hart IDs at the ecall boundary for HART_START and
HART_GET_STATUS. RV32 behavior is unchanged.
Fixes: e3f69fc1e934 ("lib: Implement Hart State Management (HSM) SBI extension")
Signed-off-by: Shibo Zhu <3499129952 at qq.com>
---
lib/sbi/sbi_ecall_hsm.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/lib/sbi/sbi_ecall_hsm.c b/lib/sbi/sbi_ecall_hsm.c
index a6e83b05..404555ef 100644
--- a/lib/sbi/sbi_ecall_hsm.c
+++ b/lib/sbi/sbi_ecall_hsm.c
@@ -25,6 +25,11 @@ static int sbi_ecall_hsm_handler(unsigned long extid, unsigned long funcid,
ulong smode = (csr_read(CSR_MSTATUS) & MSTATUS_MPP) >>
MSTATUS_MPP_SHIFT;
+ if ((funcid == SBI_EXT_HSM_HART_START ||
+ funcid == SBI_EXT_HSM_HART_GET_STATUS) &&
+ (((u32)-1U) < ((u64)regs->a0)))
+ return SBI_EINVAL;
+
switch (funcid) {
case SBI_EXT_HSM_HART_START:
ret = sbi_hsm_hart_start(scratch, sbi_domain_thishart_ptr(),
--
2.43.0
More information about the opensbi
mailing list