lib: sbi: fix trigger read/update/install range check

sbi_dbtr_read_trig() rejects ranges ending exactly at total_trigs
because it treats trig_idx_base + trig_count == total_trigs as
out of range. This breaks the corner case where supervisor
software reads the last trigger by asking for base total_trigs - 1
and count 1.

Validate the base first, then compare trig_count against
total_trigs - trig_idx_base. This permits exact-end ranges and avoids
relying on unsigned addition that could overflow for a bad count.

On similar lines, the trig_count parameter of sbi_dbtr_install_trig()
and sbi_dbtr_update_trig() can be equal to total_trigs.

Fixes: a14e4d24a1 ("lib: sbi: dbtr: fix integer overflow in read_trig bounds check")
Fixes: 97f234f15c ("lib: sbi: Introduce the SBI debug triggers extension support")
Signed-off-by: Himanshu Chauhan <himanshu.chauhan@oss.qualcomm.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20261107060325.1117887-1-himanshu.chauhan@oss.qualcomm.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Himanshu Chauhan authored and Anup Patel committed 2026-11-10 13:59:44 +05:30
1 parent 332798211e
commit ed70256dd2
1 file changed
+5 -2
+5 -2
View File
@@ -649,7 +649,7 @@ int sbi_dbtr_read_trig(unsigned long smode,
return SBI_ERR_FAILED;
if (trig_idx_base >= hs->total_trigs ||
trig_count >= hs->total_trigs - trig_idx_base)
trig_count > hs->total_trigs - trig_idx_base)
return SBI_ERR_BAD_RANGE;
if (sbi_dbtr_shmem_disabled(hs))
@@ -695,6 +695,9 @@ int sbi_dbtr_install_trig(unsigned long smode,
if (!hs)
return SBI_ERR_FAILED;
if (trig_count > hs->total_trigs)
return SBI_ERR_BAD_RANGE;
if (sbi_dbtr_shmem_disabled(hs))
return SBI_ERR_NO_SHMEM;
@@ -869,7 +872,7 @@ int sbi_dbtr_update_trig(unsigned long smode,
shmem_base = hart_shmem_base(hs);
if (trig_count >= hs->total_trigs)
if (trig_count > hs->total_trigs)
return SBI_ERR_BAD_RANGE;
/*