lib: sbi: Fix possible buffer overrun in counter validation
authorAtish Patra <atishp@rivosinc.com>
Wed, 20 Jul 2022 21:50:34 +0000 (14:50 -0700)
committerAnup Patel <anup@brainfault.org>
Sat, 30 Jul 2022 05:55:48 +0000 (11:25 +0530)
commit860a376817f687db31b586ec7bcf9a1db1bce7b3
treef967f0e5423218d4e879257fa05500670f15ede0
parent83db3af5f93dbbffb599af41c58e26a24b1abc1c
lib: sbi: Fix possible buffer overrun in counter validation

The active_events array is accessed with counter ID passed from the supervisor
software before the counter ID bound check. This may cause a buffer overrun
if a supervisor passes an invalid counter ID.

Fix this by moving the access part after the bound check.

Reported-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Signed-off-by: Atish Patra <atishp@rivosinc.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
lib/sbi/sbi_pmu.c