diff --git a/arch/um/kernel/dyn.lds.S b/arch/um/kernel/dyn.lds.S index 32b60272a4fa..31adf9451507 100644 --- a/arch/um/kernel/dyn.lds.S +++ b/arch/um/kernel/dyn.lds.S @@ -24,9 +24,8 @@ SECTIONS INIT_TEXT_SECTION(PAGE_SIZE) init.data : { INIT_DATA } - __init_end = .; - . = ALIGN(PAGE_SIZE); + __init_end = .; /* Read-only sections, merged into text segment: */ .hash : { *(.hash) } diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c index bc03bf3d114d..2219827ac3ad 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -83,12 +83,17 @@ void __init arch_zone_limits_init(unsigned long *max_zone_pfns) } /* - * This can't do anything because nothing in the kernel image can be freed - * since it's not in kernel physical memory. + * We could munmap() this instead, but then libc allocations could + * land in this area and stray initdata access could erroneously + * succeed - just mprotect() it to reliably catch bad accesses. */ - void free_initmem(void) { + unsigned long start = PAGE_ALIGN((unsigned long)__init_begin); + unsigned long end = round_down((unsigned long)__init_end, PAGE_SIZE); + + if (end > start) + os_protect_memory((void *)start, end - start, 0, 0, 0); } void *uml_kmalloc(int size, int flags) diff --git a/arch/um/kernel/uml.lds.S b/arch/um/kernel/uml.lds.S index 7a6de1c74d6d..4aabcb7faa38 100644 --- a/arch/um/kernel/uml.lds.S +++ b/arch/um/kernel/uml.lds.S @@ -32,6 +32,7 @@ SECTIONS INIT_TEXT_SECTION(0) init.data : { INIT_DATA } + . = ALIGN(PAGE_SIZE); __init_end = .; .text :