Skip to content

Commit 354254f

Browse files
manuarguecarlescufi
authored andcommitted
arch: arm: aarch32: mpu: fix is in region check
Buffer size must be decreased by one when non-zero to calculate the right end address, and this must be checked for overflows. Variables for region limit renamed for clarity since they may be understood as the raw register values. Signed-off-by: Manuel Arguelles <[email protected]>
1 parent 189caf3 commit 354254f

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

arch/arm/core/aarch32/mpu/arm_mpu_v8_internal.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <aarch32/cortex_m/cmse.h>
1212
#define LOG_LEVEL CONFIG_MPU_LOG_LEVEL
1313
#include <zephyr/logging/log.h>
14+
#include <zephyr/sys/math_extras.h>
1415

1516
/**
1617
* @brief internal structure holding information of
@@ -368,13 +369,19 @@ static inline int is_enabled_region(uint32_t index)
368369
*/
369370
static inline int is_in_region(uint32_t rnr, uint32_t start, uint32_t size)
370371
{
371-
uint32_t rbar;
372-
uint32_t rlar;
372+
uint32_t r_addr_start;
373+
uint32_t r_addr_end;
374+
uint32_t end;
373375

374-
rbar = mpu_region_get_base(rnr);
375-
rlar = mpu_region_get_last_addr(rnr);
376+
r_addr_start = mpu_region_get_base(rnr);
377+
r_addr_end = mpu_region_get_last_addr(rnr);
376378

377-
if ((start >= rbar) && ((start + size) <= rlar)) {
379+
size = size == 0U ? 0U : size - 1U;
380+
if (u32_add_overflow(start, size, &end)) {
381+
return 0;
382+
}
383+
384+
if ((start >= r_addr_start) && (end <= r_addr_end)) {
378385
return 1;
379386
}
380387

0 commit comments

Comments
 (0)