From ed70256dd22c09962d146e433834239825ef0616 Mon Sep 17 00:00:00 2001 From: Himanshu Chauhan Date: Sat, 7 Nov 2026 11:33:25 +0530 Subject: [PATCH] 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: a14e4d24a1f5 ("lib: sbi: dbtr: fix integer overflow in read_trig bounds check") Fixes: 97f234f15c96 ("lib: sbi: Introduce the SBI debug triggers extension support") Signed-off-by: Himanshu Chauhan Reviewed-by: Anup Patel Link: https://lore.kernel.org/r/20261107060325.1117887-1-himanshu.chauhan@oss.qualcomm.com Signed-off-by: Anup Patel --- lib/sbi/sbi_dbtr.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/sbi/sbi_dbtr.c b/lib/sbi/sbi_dbtr.c index 5f66b641..c97e625f 100644 --- a/lib/sbi/sbi_dbtr.c +++ b/lib/sbi/sbi_dbtr.c @@ -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; /*