Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8802ec9d authored by Prasad Sodagudi's avatar Prasad Sodagudi Committed by Matt Wagantall
Browse files

arm: Add support for KERNEL_TEXT_RDONLY



When using FORCE_PAGES to allocate the kernel memory into pages,
provide an option to mark the the kernel text section as read only.
Since the kernel text pages are always mapped in the kernel, anyone
can write to the page if they have the address.
Enable this option to mark the kernel text pages as read only to
trigger a fault if any code attempts to write to a page that is
part of the kernel text section.

Change-Id: I27de98e2e82cf6dfe9370695239e1fae26ad0e97
Signed-off-by: default avatarPrasad Sodagudi <psodagud@codeaurora.org>
[imaund@codeaurora.org: Resolved trivial context conflicts.]
Signed-off-by: default avatarIan Maund <imaund@codeaurora.org>
parent 16cc1d6d
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -75,6 +75,19 @@ config DEBUG_USER
	      8 - SIGSEGV faults
	     16 - SIGBUS faults

config KERNEL_TEXT_RDONLY
	bool "Set kernel text section pages as read only"
	depends on FREE_PAGES_RDONLY
	help
	  The kernel text pages are always mapped in the kernel.
	  This means that anyone can write to the page if they have
	  the address. Enable this option to mark the kernel text pages
	  as read only to trigger a fault if any code attempts to write
	  to a page part of the kernel text section. This may have a
	  performance impact.

	  If unsure, say N.

# These options are only for real kernel hackers who want to get their hands dirty.
config DEBUG_LL
	bool "Kernel low-level debugging functions (read help!)"
+7 −0
Original line number Diff line number Diff line
@@ -510,4 +510,11 @@ int set_memory_nx(unsigned long addr, int numpages);

void flush_uprobe_xol_access(struct page *page, unsigned long uaddr,
			     void *kaddr, unsigned long len);

#ifdef CONFIG_KERNEL_TEXT_RDONLY
void set_kernel_text_ro(void);
#else
static inline void set_kernel_text_ro(void) { }
#endif

#endif
+11 −0
Original line number Diff line number Diff line
@@ -654,3 +654,14 @@ static int __init keepinitrd_setup(char *__unused)

__setup("keepinitrd", keepinitrd_setup);
#endif

#ifdef CONFIG_KERNEL_TEXT_RDONLY
void set_kernel_text_ro(void)
{
	unsigned long start = PFN_ALIGN(_stext);
	unsigned long end = PFN_ALIGN(_etext);

	/* Set the kernel identity mapping for text RO. */
	set_memory_ro(start, (end - start) >> PAGE_SHIFT);
}
#endif