-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13387 from nmeum/mpu_noexec_ram_ng
Add optional support for executable space protections
- Loading branch information
Showing
8 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include ../Makefile.tests_common | ||
|
||
USEMODULE += mpu_noexec_ram | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# mpu_noexec_ram | ||
|
||
Tests for the `mpu_noexec_ram` pseudomodule. As this module is currently | ||
only supported on Cortex M devices, the test case is a bit ARM specific. | ||
|
||
## Output | ||
|
||
With `USEMODULE += mpu_noexec_ram` in `Makefile` this application should | ||
execute a kernel panic from the `MEM MANAGE HANDLER`. Without this | ||
pseudomodule activated, it will run into a hard fault. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (C) 2020 Sören Tempel <tempel@uni-bremen.de> | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup tests | ||
* @{ | ||
* | ||
* @file | ||
* @brief Test application for the mpu_noexec_stack pseudo-module | ||
* | ||
* @author Sören Tempel <tempel@uni-bremen.de> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdint.h> | ||
|
||
#include "cpu.h" | ||
#include "mpu.h" | ||
|
||
/* RIOT's MPU headers gracefully fail when no MPU is present. | ||
* Use this to catch if RIOT's features are correctly gating MPU use. | ||
*/ | ||
#if !__MPU_PRESENT | ||
#error "(!__MPU_PRESENT)" | ||
#endif | ||
|
||
#define JMPBUF_SIZE 3 | ||
|
||
int main(void) | ||
{ | ||
uint32_t buf[JMPBUF_SIZE]; | ||
|
||
/* Fill the buffer with invalid instructions */ | ||
for (unsigned i = 0; i < JMPBUF_SIZE; i++) { | ||
buf[i] = UINT32_MAX; | ||
} | ||
|
||
puts("Attempting to jump to stack buffer ...\n"); | ||
__asm__ volatile ("BX %0" | ||
: /* no output operands */ | ||
: "r" ((uint8_t*)&buf + 1)); /* LSB must be set for thumb2 */ | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (C) 2020 Sören Tempel <tempel@uni-bremen.de> | ||
# | ||
# This file is subject to the terms and conditions of the GNU Lesser | ||
# General Public License v2.1. See the file LICENSE in the top level | ||
# directory for more details. | ||
|
||
import sys | ||
from testrunner import run | ||
|
||
|
||
def testfunc(child): | ||
child.expect_exact("MEM MANAGE HANDLER\r\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(run(testfunc, timeout=10)) |