Skip to content

Commit 61d3eef

Browse files
chunlinAnas Nashif
authored andcommitted
arm: core: mpu: Prevent updating unexpected region
The REGION bits (bit[3:0]) of MPU_RBAR register can specify the number of the region to update if the VALID bit (bit[4]) is also set. If the bit[3:0] of "region_addr" are not zero, might cause to update unexpected region. This could happen since we might not declare stack memory with specific alignment. This patch will mask the bit[4:0] of "region_addr" to prevent updating unexpected region. Signed-off-by: Chunlin Han <[email protected]>
1 parent 65b1859 commit 61d3eef

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

arch/arm/core/cortex_m/mpu/arm_mpu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ static void _region_init(u32_t index, u32_t region_addr,
6464
/* Select the region you want to access */
6565
ARM_MPU_DEV->rnr = index;
6666
/* Configure the region */
67-
ARM_MPU_DEV->rbar = region_addr | REGION_VALID | index;
67+
ARM_MPU_DEV->rbar = (region_addr & REGION_BASE_ADDR_MASK)
68+
| REGION_VALID | index;
6869
ARM_MPU_DEV->rasr = region_attr | REGION_ENABLE;
6970
}
7071

include/arch/arm/cortex_m/mpu/arm_mpu.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ struct arm_mpu {
4444
#define ARM_MPU_PRIVDEFENA (1 << 2)
4545

4646
#define REGION_VALID (1 << 4)
47+
/* ARM MPU RBAR Register */
48+
/* Region base address mask */
49+
#define REGION_BASE_ADDR_MASK 0xFFFFFFE0
4750

4851
/* eXecute Never */
4952
#define NOT_EXEC (0x1 << 28)

0 commit comments

Comments
 (0)