From: Andrew Jones <ajones@ventanamicro.com>
To: opensbi@lists.infradead.org
Subject: [PATCH] lib: sbi: Add additional range checks for RV32
Date: Wed, 14 Aug 2024 14:30:00 +0200 [thread overview]
Message-ID: <20240814122959.49914-2-ajones@ventanamicro.com> (raw)
On RV32, M-mode can only access the first 4G of the physical
address space because M-mode does not have an MMU to access the
full 34-bit physical address space. While we already ensure
the "hi" registers of RV32 physical address inputs are zero we
need to also ensure that the low register plus the size does
not cross into 4G address space. The check added to
sbi_domain_check_addr_range() should be enough for both DBCN
and SSE, but DBCN returns a different error code for high
addresses, so we patch that check too.
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
---
Should the SSE functions return SBI_ERR_FAILED in this case like DBCN
does? We'd need to patch the SSE spec to call out SBI_ERR_FAILED as
"Failed to write due to I/O errors." like DBCN does too.
lib/sbi/sbi_domain.c | 3 +++
lib/sbi/sbi_ecall_dbcn.c | 2 +-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
index 374ac36b2f3e..5f6efe884952 100644
--- a/lib/sbi/sbi_domain.c
+++ b/lib/sbi/sbi_domain.c
@@ -412,6 +412,9 @@ bool sbi_domain_check_addr_range(const struct sbi_domain *dom,
if (!dom)
return false;
+ if (max < addr)
+ return false;
+
while (addr < max) {
reg = find_region(dom, addr);
if (!reg)
diff --git a/lib/sbi/sbi_ecall_dbcn.c b/lib/sbi/sbi_ecall_dbcn.c
index 49a7713f48bb..a3262ab9a90c 100644
--- a/lib/sbi/sbi_ecall_dbcn.c
+++ b/lib/sbi/sbi_ecall_dbcn.c
@@ -39,7 +39,7 @@ static int sbi_ecall_dbcn_handler(unsigned long extid, unsigned long funcid,
* physical address (i.e. a2 register) is non-zero on
* RV64.
*/
- if (regs->a2)
+ if (regs->a2 || regs->a1 + regs->a0 < regs->a1)
return SBI_ERR_FAILED;
if (!sbi_domain_check_addr_range(sbi_domain_thishart_ptr(),
--
2.45.2
next reply other threads:[~2024-08-14 12:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-14 12:30 Andrew Jones [this message]
2024-08-24 9:08 ` [PATCH] lib: sbi: Add additional range checks for RV32 Anup Patel
2024-08-26 11:00 ` Andrew Jones
2024-09-09 13:21 ` Andrew Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240814122959.49914-2-ajones@ventanamicro.com \
--to=ajones@ventanamicro.com \
--cc=opensbi@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.