mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-11-19 18:21:41 +00:00
lib: sbi: dbtr: fix integer overflow in read_trig bounds check
In sbi_dbtr_read_trig(), the range check is:
if (trig_idx_base + trig_count >= hs->total_trigs)
When trig_idx_base and trig_count are both unsigned long values supplied
by S-mode, their sum can wrap past ULONG_MAX to a small value, making
the check pass. For example trig_idx_base=1, trig_count=ULONG_MAX wraps
to 0, which is less than total_trigs.
This allows the subsequent for_each_trig_entry loop to access trigger
entries far beyond the triggers[] array, corrupting M-mode heap memory
via CSR read-back writes and leaking M-mode internal state to S-mode
shared memory.
Rewrite the condition as trig_count >= total_trigs - trig_idx_base. The
subtraction is safe because the preceding check already guarantees
trig_idx_base < total_trigs.
Fixes: 97f234f15c ("lib: sbi: Introduce the SBI debug triggers extension support")
Signed-off-by: liutong <liutong@iscas.ac.cn>
Reviewed-by: Himanshu Chauhan <himanshu.chauhan@oss.qualcomm.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260910052629.3359493-2-liutong@iscas.ac.cn
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
1 parent
bcf587a987
commit
a14e4d24a1
1 file changed
+1
-1
+1
-1
@@ -649,7 +649,7 @@ int sbi_dbtr_read_trig(unsigned long smode,
|
|||||||
return SBI_ERR_FAILED;
|
return SBI_ERR_FAILED;
|
||||||
|
|
||||||
if (trig_idx_base >= hs->total_trigs ||
|
if (trig_idx_base >= hs->total_trigs ||
|
||||||
trig_idx_base + trig_count >= hs->total_trigs)
|
trig_count >= hs->total_trigs - trig_idx_base)
|
||||||
return SBI_ERR_BAD_RANGE;
|
return SBI_ERR_BAD_RANGE;
|
||||||
|
|
||||||
if (sbi_dbtr_shmem_disabled(hs))
|
if (sbi_dbtr_shmem_disabled(hs))
|
||||||
|
|||||||
Reference in new issue
Block a user