[PATCH v2 3/6] lib: sbi_dbtr: use range check for shared memory domain validation
Himanshu Chauhan
himanshu.chauhan at oss.qualcomm.com
Thu Sep 3 02:01:24 PDT 2026
On Fri, Jul 31, 2026 at 10:34:02AM +0000, liutong wrote:
> sbi_dbtr_setup_shmem() validates the shared memory address using
> sbi_domain_check_addr(), which only checks a single address. However,
> subsequent DBTR operations (install, read, update) access up to
> total_trigs * sizeof(sbi_dbtr_shmem_entry) bytes starting from that
> address.
>
> If the shared memory region spans a domain boundary, accesses beyond
> the first byte could violate domain isolation, allowing S-mode to
> read or write M-mode memory through DBTR operations.
>
> Replace the single-address check with sbi_domain_check_addr_range()
> to validate the entire shared memory region that DBTR operations
> will use.
>
> Fixes: 23b7badeee3c ("lib: sbi: check incoming dbtr shmem address")
> Signed-off-by: liutong <liutong at iscas.ac.cn>
> ---
>
> Previously sent as [PATCH v2].
> Changes in v2:
> - Added Fixes tag
> - Consolidated into patch series
>
> lib/sbi/sbi_dbtr.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/lib/sbi/sbi_dbtr.c b/lib/sbi/sbi_dbtr.c
> index 5cca0922..b0f1019d 100644
> --- a/lib/sbi/sbi_dbtr.c
> +++ b/lib/sbi/sbi_dbtr.c
> @@ -304,9 +304,10 @@ int sbi_dbtr_setup_shmem(const struct sbi_domain *dom, unsigned long smode,
> if (shmem_phys_hi)
> return SBI_EINVALID_ADDR;
>
> - if (dom && !sbi_domain_check_addr(dom,
> - DBTR_SHMEM_MAKE_PHYS(shmem_phys_hi, shmem_phys_lo), smode,
> - SBI_DOMAIN_READ | SBI_DOMAIN_WRITE))
> + if (dom && !sbi_domain_check_addr_range(dom,
> + DBTR_SHMEM_MAKE_PHYS(shmem_phys_hi, shmem_phys_lo),
> + hart_state->total_trigs * sizeof(union sbi_dbtr_shmem_entry),
> + smode, SBI_DOMAIN_READ | SBI_DOMAIN_WRITE))
> return SBI_ERR_INVALID_ADDRESS;
>
one nit pick: The dom && guard means the range check is skipped entirely if dom is NULL. Since you are
trying to close gaps, I would suggest that you add a check for dom.
Regards
Himanshu
> hart_state->shmem.phys_lo = shmem_phys_lo;
> --
> 2.34.1
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
More information about the opensbi
mailing list