[PATCH] include: sbi: fix illegal shift in sbi_domain.h: sbi_domain_memregion_is_subset

Anup Patel anup at brainfault.org
Mon Mar 9 01:59:03 PDT 2026


On Mon, Feb 23, 2026 at 5:21 AM Marcos Oduardo <marcos.oduardo at gmail.com> wrote:
>
> From: marcos <marcos.oduardo at gmail.com>
>
> In sbi_domain.h, when checking if a memory region is a subset of another,
> an undefined behavior arithmetic operation was caught when sanitizing with
> UBSan (shift exponent 64).

s/64/__riscv_xlen/

>
> This patch adds a check to handle the case where the region order is 64,

s/64/__riscv_xlen/

> avoiding the illegal shift and ensuring the operation remains defined.
>
> Please let me know if there’s any other most suitable solution for this bug.
>
> Signed-off-by: Marcos Oduardo <marcos.oduardo at gmail.com>
> ---
>  include/sbi/sbi_domain.h | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h
> index c8a6da99..6e6dd33a 100644
> --- a/include/sbi/sbi_domain.h
> +++ b/include/sbi/sbi_domain.h
> @@ -170,9 +170,11 @@ static inline bool sbi_domain_memregion_is_subset(
>                                 const struct sbi_domain_memregion *regB)
>  {
>         ulong regA_start = regA->base;
> -       ulong regA_end = regA->base + (BIT(regA->order) - 1);
> +       ulong regA_mask = (regA->order >= 64) ? ~0UL : (BIT(regA->order) - 1);
> +       ulong regA_end = regA_start + regA_mask;
>         ulong regB_start = regB->base;
> -       ulong regB_end = regB->base + (BIT(regB->order) - 1);
> +       ulong regB_mask = (regB->order >= 64) ? ~0UL : (BIT(regB->order) - 1);
> +       ulong regB_end = regB_start + regB_mask;

s/64/__riscv_xlen/

>
>         if ((regB_start <= regA_start) &&
>             (regA_start < regB_end) &&
> --
> 2.53.0
>
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi

Otherwise, LGTM.

Reviewed-by: Anup Patel <anup at brainfault.org>

I have taken care of the above comments at the time
of merging.

Applied this patch to the riscv/opensbi repo.

Regards,
Anup



More information about the opensbi mailing list