[PATCH] ARM: OMAP: Fix SRAM W+X mapping

From: Tony Lindgren
Date: Thu Mar 08 2018 - 11:41:16 EST


We are still using custom SRAM code for some SoCs and are not marking
the PM code mapped to SRAM as read-only and executable after we're
done. With CONFIG_DEBUG_WX=y, we will get "Found insecure W+X mapping
at address" warning.

Let's fix this issue the same way as commit 728bbe75c82f ("misc: sram:
Introduce support code for protect-exec sram type") is doing for
drivers/misc/sram-exec.c.

Note that eventually we should be using sram-exec.c for all SoCs.

Cc: Dave Gerlach <d-gerlach@xxxxxx>
Reported-by: Pavel Machek <pavel@xxxxxx>
Signed-off-by: Tony Lindgren <tony@xxxxxxxxxxx>
---
arch/arm/plat-omap/sram.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)

diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
--- a/arch/arm/plat-omap/sram.c
+++ b/arch/arm/plat-omap/sram.c
@@ -23,6 +23,7 @@
#include <asm/fncpy.h>
#include <asm/tlb.h>
#include <asm/cacheflush.h>
+#include <asm/set_memory.h>

#include <asm/mach/map.h>

@@ -96,3 +97,21 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
memset_io(omap_sram_base + omap_sram_skip, 0,
omap_sram_size - omap_sram_skip);
}
+
+static int __init omap_sram_lock(void)
+{
+ unsigned long base;
+ int pages;
+
+ if (!omap_sram_base || !omap_sram_size)
+ return 0;
+
+ base = (unsigned long)omap_sram_base;
+ pages = PAGE_ALIGN(omap_sram_size) / PAGE_SIZE;
+
+ set_memory_ro((unsigned long)base, pages);
+ set_memory_x((unsigned long)base, pages);
+
+ return 0;
+}
+late_initcall(omap_sram_lock);
--
2.16.2