From dfcc710aef8d3d91358449827596ec822131d710 Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Mon, 13 May 2024 17:55:11 +0800 Subject: [PATCH] feat(cpu): add basic PMA protection for null access --- .../esp_hw_support/port/esp32c5/cpu_region_protect.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/esp_hw_support/port/esp32c5/cpu_region_protect.c b/components/esp_hw_support/port/esp32c5/cpu_region_protect.c index 17397207fa..6371b58e9f 100644 --- a/components/esp_hw_support/port/esp32c5/cpu_region_protect.c +++ b/components/esp_hw_support/port/esp32c5/cpu_region_protect.c @@ -70,7 +70,13 @@ static void esp_cpu_configure_invalid_regions(void) void esp_cpu_configure_region_protection(void) { // ROM has configured the MSPI region with RX permission, we should add W attribute for psram - PMA_ENTRY_SET_NAPOT(0, SOC_IROM_LOW, (SOC_IROM_HIGH - SOC_IROM_LOW), PMA_NAPOT | PMA_L | PMA_EN | PMA_R | PMA_W | PMA_X); + PMA_ENTRY_SET_NAPOT(0, SOC_IROM_LOW, (SOC_IROM_HIGH - SOC_IROM_LOW), PMA_NAPOT | PMA_EN | PMA_R | PMA_W | PMA_X); + + // Configure just the area around 0x0 for now so that we at least get exceptions for + // writes/reads to NULL pointers, as well as code that relies on writes to 0x0 + // to abort/assert + PMA_ENTRY_SET_NAPOT(1, 0, SOC_DEBUG_LOW, PMA_NAPOT | PMA_EN); + return; /* Notes on implementation: *