include: sbi: fix illegal shift in sbi_domain.h: sbi_domain_memregion_is_subset
PATCH 1/1 include: sbi: fix illegal shift in sbi_domain.h: sbi_domain_memregion_is_subset
From: marcos <[email protected]>
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.
--- include/sbi/sbi_domain.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
include/sbi/sbi_domain.h +4 -2
@@ -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) &&
Signature · 7 lines
2.53.0 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
Quoted 6 lines · Marcos Oduardo
From: marcos <[email protected]>
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/
Quoted 2 lines
This patch adds a check to handle the case where the region order is 64,
s/64/__riscv_xlen/
Quoted 14 lines
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 <[email protected]>--- include/sbi/sbi_domain.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)include/sbi/sbi_domain.h +0
-0
include/sbi/sbi_domain.h static inline bool sbi_domain_memregion_is_subset( · line 177
Quoted 10 lines
include/sbi/sbi_domain.h +4
-2@@ -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/
Quoted 11 lines
include/sbi/sbi_domain.h +0
-1if ((regB_start <= regA_start) && (regA_start < regB_end) && --2.53.0
--
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Otherwise, LGTM.
I have taken care of the above comments at the time of merging.
Applied this patch to the riscv/opensbi repo.
Regards,
Anup
Signature · 3 lines
opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi