[RFC PATCH 12/23] lib: sbi: dbcn: handle temporary buffer map and unmap errors
Yu-Chien Peter Lin
peter.lin at sifive.com
Mon Nov 30 02:11:36 PST 2026
The console read and write calls access the S-mode buffer between
sbi_hart_protection_temp_map_range() and
sbi_hart_protection_temp_unmap_range() but ignore both return values.
With Smepmp the temporary mapping is verified and can fail, and M-mode
must not read or write the buffer without a valid mapping.
Return SBI_ERR_FAILED without accessing the buffer when the mapping
fails, and report a failed unmap instead of returning success.
Signed-off-by: Yu-Chien Peter Lin <peter.lin at sifive.com>
---
lib/sbi/sbi_ecall_dbcn.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/sbi/sbi_ecall_dbcn.c b/lib/sbi/sbi_ecall_dbcn.c
index 76837737..6728e9b3 100644
--- a/lib/sbi/sbi_ecall_dbcn.c
+++ b/lib/sbi/sbi_ecall_dbcn.c
@@ -46,12 +46,14 @@ static int sbi_ecall_dbcn_handler(unsigned long extid, unsigned long funcid,
regs->a1, regs->a0, smode,
SBI_DOMAIN_READ|SBI_DOMAIN_WRITE))
return SBI_ERR_INVALID_PARAM;
- sbi_hart_protection_temp_map_range(regs->a1, regs->a0);
+ if (sbi_hart_protection_temp_map_range(regs->a1, regs->a0))
+ return SBI_ERR_FAILED;
if (funcid == SBI_EXT_DBCN_CONSOLE_WRITE)
out->value = sbi_nputs((const char *)regs->a1, regs->a0);
else
out->value = sbi_ngets((char *)regs->a1, regs->a0);
- sbi_hart_protection_temp_unmap_range(regs->a1, regs->a0);
+ if (sbi_hart_protection_temp_unmap_range(regs->a1, regs->a0))
+ return SBI_ERR_FAILED;
return 0;
case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE:
sbi_putc(regs->a0);
--
2.43.7
More information about the opensbi
mailing list