[PATCH] include: sbi: fix illegal shift in sbi_domain.h: sbi_domain_memregion_is_subset
Marcos Oduardo
marcos.oduardo at gmail.com
Sun Feb 22 15:51:50 PST 2026
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).
This patch adds a check to handle the case where the region order is 64,
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;
if ((regB_start <= regA_start) &&
(regA_start < regB_end) &&
--
2.53.0
More information about the opensbi
mailing list