From 88ddce652cede79c7dbaa8dac6405c9120b8f974 Mon Sep 17 00:00:00 2001 From: Andrew Boie Date: Wed, 8 Jul 2020 21:21:10 -0700 Subject: [PATCH] mmu: add CONFIG_SRAM_REGION_PERMISSIONS If CONFIG_MMU is active, choose whether to separate text, rodata, and ram into their own page-aligned regions so that they have have different MMU permissions applied. If disabled, all RAM pages will have RWX permission to supervisor mode, but some memory may be saved due to lack of page alignment padding between these regions. This used to always happen. This patch adds the Kconfig, linker script changes to come in a subsequent patch. Signed-off-by: Andrew Boie --- arch/Kconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 8e19565fdfd..d473262e5cf 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -208,6 +208,7 @@ config USERSPACE bool "User mode threads" depends on ARCH_HAS_USERSPACE depends on RUNTIME_ERROR_CHECKS + select SRAM_REGION_PERMISSIONS if MMU help When enabled, threads may be created or dropped down to user mode, which has significantly restricted permissions and must interact @@ -507,6 +508,17 @@ config MMU_PAGE_SIZE Size of memory pages. Varies per MMU but 4K is common. For MMUs that support multiple page sizes, put the smallest one here. +config SRAM_REGION_PERMISSIONS + bool "Assign appropriate permissions to kernel areas in SRAM" + depends on MMU + default y + help + If enabled, the program text, rodata, and data parts of the kernel in + the permanent mappings created at build time will have appropriate + permissions set. Uses extra memory due to page-alignment constraints. + If not enabled, all SRAM mappings will allow supervisor mode to + read, write, and execute. User mode support requires this. + config MEMORY_PROTECTION bool help