[PATCH] lib: sbi: Check DBCN buffer access permission
Surya
saisurya.musham11 at gmail.com
Sun Nov 29 10:06:42 PST 2026
The debug console write operation reads from the supervisor buffer,
whereas the debug console read operation writes to it.
Require only the access permission used by the requested operation.
This allows valid read-only buffers for console writes and write-only
buffers for console reads.
Signed-off-by: Surya <saisurya.musham11 at gmail.com>
---
lib/sbi/sbi_ecall_dbcn.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/lib/sbi/sbi_ecall_dbcn.c b/lib/sbi/sbi_ecall_dbcn.c
index 76837737..7610b8ec 100644
--- a/lib/sbi/sbi_ecall_dbcn.c
+++ b/lib/sbi/sbi_ecall_dbcn.c
@@ -22,6 +22,7 @@ static int sbi_ecall_dbcn_handler(unsigned long
extid, unsigned long funcid,
{
ulong smode = (csr_read(CSR_MSTATUS) & MSTATUS_MPP) >>
MSTATUS_MPP_SHIFT;
+ unsigned long access_flags;
switch (funcid) {
case SBI_EXT_DBCN_CONSOLE_WRITE:
@@ -42,9 +43,11 @@ static int sbi_ecall_dbcn_handler(unsigned long
extid, unsigned long funcid,
if (regs->a2)
return SBI_ERR_FAILED;
+ access_flags = (funcid == SBI_EXT_DBCN_CONSOLE_WRITE) ?
+ SBI_DOMAIN_READ : SBI_DOMAIN_WRITE;
if (!sbi_domain_check_addr_range(sbi_domain_thishart_ptr(),
- regs->a1, regs->a0, smode,
- SBI_DOMAIN_READ|SBI_DOMAIN_WRITE))
+ regs->a1, regs->a0, smode,
+ access_flags))
return SBI_ERR_INVALID_PARAM;
sbi_hart_protection_temp_map_range(regs->a1, regs->a0);
if (funcid == SBI_EXT_DBCN_CONSOLE_WRITE)
--
2.34.1
More information about the opensbi
mailing list