Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions arch/risc-v/src/common/riscv_pmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions arch/risc-v/src/mpfs/mpfs_mpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ int mpfs_mpu_set(uintptr_t reg, uintptr_t perm, uintptr_t base,
return -EACCES;
}

/* Base must be word aligned, minimum size is 4K */
/* Base must be word aligned,
* minimum size is 4K and it has to be power-of-two
*/

if ((base & 0x07) != 0 || size < 0x1000)
if ((base & 0x07) != 0 || size < 0x1000 || (size & (size - 1)) != 0)
{
return -EINVAL;
}
Expand Down
Loading