riscv_pmp.c: Check that size is power of two for NAPOT

The size must be power-of-two according to the the PMP spec.

Signed-off-by: Jani Paalijarvi <jani.paalijarvi@unikie.com>
This commit is contained in:
Jani Paalijarvi 2024-05-23 10:43:33 +03:00 committed by Xiang Xiao
parent b3513c0811
commit 9d4bd915eb

View File

@ -134,9 +134,9 @@ static bool pmp_check_region_attrs(uintptr_t base, uintptr_t size,
case PMPCFG_A_NAPOT:
{
/* For NAPOT, both base and size must be properly aligned */
/* For NAPOT, Naturally aligned power-of-two region, >= 8 bytes */
if ((base & 0x07) != 0 || size < 8)
if ((base & 0x07) != 0 || size < 8 || (size & (size - 1)) != 0)
{
return false;
}