Skip to content

Commit 87b7bee

Browse files
ioannisggalak
authored andcommitted
arch: arm: mpu: fix _mpu_buffer_validate() implementation
In this commit we fix the implementation of internal function _mpu_buffer_validate(), so it can work in the presence of a security attribution unit (SAU, or IDAU). The fast validation based on the CMSE address range check intrinsic is performed first: if it fails, then a second, MPU-only check is performed for ARMV8-M platforms that have TEE capabilities (i.e. SAU/IDAU units). Signed-off-by: Ioannis Glaropoulos <[email protected]>
1 parent 4ffc37c commit 87b7bee

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,27 @@ static inline int _mpu_buffer_validate(void *addr, size_t size, int write)
260260
}
261261
}
262262

263+
#if defined(CONFIG_CPU_HAS_TEE)
264+
/*
265+
* Validation failure may be due to SAU/IDAU presence.
266+
* We re-check user accessibility based on MPU only.
267+
*/
268+
s32_t r_index_base = arm_cmse_mpu_region_get(_addr);
269+
s32_t r_index_last = arm_cmse_mpu_region_get(_addr + _size - 1);
270+
271+
if ((r_index_base != -EINVAL) && (r_index_base == r_index_last)) {
272+
/* Valid MPU region, check permissions on base address only. */
273+
if (write) {
274+
if (arm_cmse_addr_readwrite_ok(_addr, 1)) {
275+
return 0;
276+
}
277+
} else {
278+
if (arm_cmse_addr_read_ok(_addr, 1)) {
279+
return 0;
280+
}
281+
}
282+
}
283+
#endif /* CONFIG_CPU_HAS_TEE */
263284
return -EPERM;
264285
}
265286

0 commit comments

Comments
 (0)