Skip to content

Commit

Permalink
lib: sbi: check result of pmp_get() in is_pmp_entry_mapped()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
00xc authored and avpatel committed Aug 2, 2024
1 parent cb0f475 commit 43cace6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/sbi/riscv_asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ int is_pmp_entry_mapped(unsigned long entry)
unsigned long addr;
unsigned long log2len;

pmp_get(entry, &prot, &addr, &log2len);
if (pmp_get(entry, &prot, &addr, &log2len) != 0)
return false;

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

0 comments on commit 43cace6

Please sign in to comment.