Skip to content

Commit ae646f0

Browse files
Jeffrey Hugotorvalds
authored andcommitted
init: fix false positives in W+X checking
load_module() creates W+X mappings via __vmalloc_node_range() (from layout_and_allocate()->move_module()->module_alloc()) by using PAGE_KERNEL_EXEC. These mappings are later cleaned up via "call_rcu_sched(&freeinit->rcu, do_free_init)" from do_init_module(). This is a problem because call_rcu_sched() queues work, which can be run after debug_checkwx() is run, resulting in a race condition. If hit, the race results in a nasty splat about insecure W+X mappings, which results in a poor user experience as these are not the mappings that debug_checkwx() is intended to catch. This issue is observed on multiple arm64 platforms, and has been artificially triggered on an x86 platform. Address the race by flushing the queued work before running the arch-defined mark_rodata_ro() which then calls debug_checkwx(). Link: http://lkml.kernel.org/r/1525103946-29526-1-git-send-email-jhugo@codeaurora.org Fixes: e1a5832 ("x86/mm: Warn on W^X mappings") Signed-off-by: Jeffrey Hugo <jhugo@codeaurora.org> Reported-by: Timur Tabi <timur@codeaurora.org> Reported-by: Jan Glauber <jan.glauber@caviumnetworks.com> Acked-by: Kees Cook <keescook@chromium.org> Acked-by: Ingo Molnar <mingo@kernel.org> Acked-by: Will Deacon <will.deacon@arm.com> Acked-by: Laura Abbott <labbott@redhat.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Stephen Smalley <sds@tycho.nsa.gov> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 4ba281d commit ae646f0

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎init/main.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,13 @@ __setup("rodata=", set_debug_rodata);
10341034
static void mark_readonly(void)
10351035
{
10361036
if (rodata_enabled) {
1037+
/*
1038+
* load_module() results in W+X mappings, which are cleaned up
1039+
* with call_rcu_sched(). Let's make sure that queued work is
1040+
* flushed so that we don't hit false positives looking for
1041+
* insecure pages which are W+X.
1042+
*/
1043+
rcu_barrier_sched();
10371044
mark_rodata_ro();
10381045
rodata_test();
10391046
} else

‎kernel/module.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3517,6 +3517,11 @@ static noinline int do_init_module(struct module *mod)
35173517
* walking this with preempt disabled. In all the failure paths, we
35183518
* call synchronize_sched(), but we don't want to slow down the success
35193519
* path, so use actual RCU here.
3520+
* Note that module_alloc() on most architectures creates W+X page
3521+
* mappings which won't be cleaned up until do_free_init() runs. Any
3522+
* code such as mark_rodata_ro() which depends on those mappings to
3523+
* be cleaned up needs to sync with the queued work - ie
3524+
* rcu_barrier_sched()
35203525
*/
35213526
call_rcu_sched(&freeinit->rcu, do_free_init);
35223527
mutex_unlock(&module_mutex);

0 commit comments

Comments
 (0)