mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-03-21 03:21:45 +00:00
lib: sbi: Fix undefined behavior in signed shifts in sbi_hart.c
UBSan detected undefined behavior in sbi_hart.c and sbi_fwft.c (in the case of sbi_fwft.c, the bug comes from a macro call defined at sbi_ecall_interface.h) caused by shifting a signed integer into the sign bit (1 << 31) This can be fixed by using the 1UL literal, ensuring defined arithmetic. Please let me know if there’s any other most suitable solution for this bug. Signed-off-by: Marcos Oduardo <marcos.oduardo@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20260223001202.284612-1-marcos.oduardo@gmail.com Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
committed by
Anup Patel
parent
3baca10015
commit
2727c43f8d
@@ -70,7 +70,7 @@ static void mstatus_init(struct sbi_scratch *scratch)
|
||||
*/
|
||||
mhpmevent_init_val |= (MHPMEVENT_OF | MHPMEVENT_MINH);
|
||||
for (cidx = 0; cidx <= 28; cidx++) {
|
||||
if (!(mhpm_mask & 1 << (cidx + 3)))
|
||||
if (!(mhpm_mask & 1UL << (cidx + 3)))
|
||||
continue;
|
||||
#if __riscv_xlen == 32
|
||||
csr_write_num(CSR_MHPMEVENT3 + cidx,
|
||||
|
||||
Reference in New Issue
Block a user