Skip to content

Commit eb736a5

Browse files
xypronavpatel
authored andcommitted
lib: sbi_pmu: Avoid out of bounds access
On a misconfigured system we could access phs->active_events[] out of bounds. Check that num_hw_ctrs is less or equal SBI_PMU_HW_CTR_MAX. Addresses-Coverity-ID: 1566113 ("Out-of-bounds read") Addresses-Coverity-ID: 1566114 ("Out-of-bounds write") Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
1 parent 0907de3 commit eb736a5

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

lib/sbi/sbi_pmu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,8 @@ int sbi_pmu_init(struct sbi_scratch *scratch, bool cold_boot)
933933

934934
/* mcycle & minstret is available always */
935935
num_hw_ctrs = sbi_hart_mhpm_count(scratch) + 3;
936+
if (num_hw_ctrs > SBI_PMU_HW_CTR_MAX)
937+
return SBI_EINVAL;
936938
total_ctrs = num_hw_ctrs + SBI_PMU_FW_CTR_MAX;
937939
}
938940

0 commit comments

Comments
 (0)