]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/kernel-video.git/commit
ARM: allow the kernel text section to be made read-only
authorColin Cross <ccross@android.com>
Fri, 12 Aug 2011 00:15:24 +0000 (17:15 -0700)
committerArve Hjønnevåg <arve@android.com>
Tue, 19 Feb 2013 23:49:09 +0000 (15:49 -0800)
commit42eb87d910b18b8c07942622ea60bd9de51bdfa1
tree71f87800fd0705f3e19841d9ef51ba24fed92f35
parentf578bc010a194afab38abd4da1324dc0b0533408
ARM: allow the kernel text section to be made read-only

This patch implements CONFIG_DEBUG_RODATA, allowing
the kernel text section to be marked read-only in
order to catch bugs that write over the kernel.  This
requires mapping the kernel code, plus up to 4MB, using
pages instead of sections, which can increase TLB
pressure.

The kernel is normally mapped using 1MB section entries
in the first level page table, and the first level page
table is copied into every mm.  This prevents marking
the kernel text read-only, because the 1MB section
entries are too large granularity to separate the init
section, which is reused as read-write memory after
init, and the kernel text section.  Also, the top level
page table for every process would need to be updated,
which is not possible to do safely and efficiently on SMP.

To solve both problems, allow alloc_init_pte to overwrite
an existing section entry with a fully-populated second
level page table.  When CONFIG_DEBUG_RODATA is set, all
the section entries that overlap the kernel text section
will be replaced with page mappings.  The kernel always
uses a pair of 2MB-aligned 1MB sections, so up to 2MB
of memory before and after the kernel may end up page
mapped.

When the top level page tables are copied into each
process the second level page tables are not copied,
leaving a single second level page table that will
affect all processes on all cpus.  To mark a page
read-only, the second level page table is located using
the pointer in the first level page table for the
current process, and the supervisor RO bit is flipped
atomically.  Once all pages have been updated, all TLBs
are flushed to ensure the changes are visible on all
cpus.

If CONFIG_DEBUG_RODATA is not set, the kernel will be
mapped using the normal 1MB section entries.

Change-Id: I94fae337f882c2e123abaf8e1082c29cd5d483c6
Signed-off-by: Colin Cross <ccross@android.com>
arch/arm/Kconfig.debug
arch/arm/include/asm/cacheflush.h
arch/arm/include/asm/rodata.h [new file with mode: 0644]
arch/arm/kernel/ftrace.c
arch/arm/mm/Makefile
arch/arm/mm/mmu.c
arch/arm/mm/rodata.c [new file with mode: 0644]