Skip to content

Commit 43cace6

Browse files
00xcavpatel
authored andcommitted
lib: sbi: check result of pmp_get() in is_pmp_entry_mapped()
pmp_get() may return an error if the given entry, given by the caller of is_pmp_entry_mapped(), is invalid. This results in the output parameters for pmp_get() being uninitialized. To avoid using garbage values, check the result and return early if necessary. This issue is not being hit because at the moment is_pmp_entry_mapped() is only being called from a single site with a valid hardcoded value. Signed-off-by: Carlos López <[email protected]> Reviewed-by: Anup Patel <[email protected]>
1 parent cb0f475 commit 43cace6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/sbi/riscv_asm.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ int is_pmp_entry_mapped(unsigned long entry)
291291
unsigned long addr;
292292
unsigned long log2len;
293293

294-
pmp_get(entry, &prot, &addr, &log2len);
294+
if (pmp_get(entry, &prot, &addr, &log2len) != 0)
295+
return false;
295296

296297
/* If address matching bits are non-zero, the entry is enable */
297298
if (prot & PMP_A)

0 commit comments

Comments
 (0)