Add mpu_noexec_ram pseudomodule

This commit is contained in:
Sören Tempel 2020-02-16 18:13:00 +01:00
parent fc37d7bf81
commit 2c1a627118
3 changed files with 24 additions and 1 deletions

View File

@ -30,6 +30,10 @@ ifneq (,$(filter mpu_stack_guard,$(USEMODULE)))
FEATURES_REQUIRED += cortexm_mpu
endif
ifneq (,$(filter mpu_noexec_ram,$(USEMODULE)))
FEATURES_REQUIRED += cortexm_mpu
endif
ifneq (,$(filter auto_init_gnrc_netif,$(USEMODULE)))
USEMODULE += gnrc_netif_init_devs
endif

View File

@ -17,6 +17,7 @@
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Daniel Krebs <github@daniel-krebs.net>
* @author Joakim Gebart <joakim.gebart@eistec.se>
* @author Sören Tempel <tempel@uni-bremen.de>
*
* @}
*/
@ -139,8 +140,25 @@ void reset_handler_default(void)
}
#endif /* CPU_HAS_BACKUP_RAM */
#ifdef MODULE_MPU_STACK_GUARD
#if defined(MODULE_MPU_STACK_GUARD) || defined(MODULE_MPU_NOEXEC_RAM)
mpu_enable();
#endif
#ifdef MODULE_MPU_NOEXEC_RAM
/* Mark the RAM non executable. This is a protection mechanism which
* makes exploitation of buffer overflows significantly harder.
*
* This marks the memory region from 0x20000000 to 0x3FFFFFFF as non
* executable. This is the Cortex-M SRAM region used for on-chip RAM.
*/
mpu_configure(
2, /* Region 0 and 1 are used by mpu_stack_guard */
(uintptr_t)&_sram, /* RAM base address */
MPU_ATTR(1, AP_RW_RW, 0, 1, 0, 1, MPU_SIZE_512M) /* Allow read/write but no exec */
);
#endif
#ifdef MODULE_MPU_STACK_GUARD
if (((uintptr_t)&_sstack) != SRAM_BASE) {
mpu_configure(
0, /* MPU region 0 */

View File

@ -56,6 +56,7 @@ PSEUDOMODULES += log_printfnoformat
PSEUDOMODULES += log_color
PSEUDOMODULES += lora
PSEUDOMODULES += mpu_stack_guard
PSEUDOMODULES += mpu_noexec_ram
PSEUDOMODULES += nanocoap_%
PSEUDOMODULES += netdev_default
PSEUDOMODULES += netstats