Skip to content

Commit 94462ad

Browse files
committed
module: Move RO/NX module protection to after ftrace module update
The commit: 84e1c6b x86: Add RO/NX protection for loadable kernel modules Broke the function tracer with this output: ------------[ cut here ]------------ WARNING: at kernel/trace/ftrace.c:1014 ftrace_bug+0x114/0x171() Hardware name: Precision WorkStation 470 Modules linked in: i2c_core(+) Pid: 86, comm: modprobe Not tainted 2.6.37-rc2+ #68 Call Trace: [<ffffffff8104e957>] warn_slowpath_common+0x85/0x9d [<ffffffffa00026db>] ? __process_new_adapter+0x7/0x34 [i2c_core] [<ffffffffa00026db>] ? __process_new_adapter+0x7/0x34 [i2c_core] [<ffffffff8104e989>] warn_slowpath_null+0x1a/0x1c [<ffffffff810a9dfe>] ftrace_bug+0x114/0x171 [<ffffffffa00026db>] ? __process_new_adapter+0x7/0x34 [i2c_core] [<ffffffff810aa0db>] ftrace_process_locs+0x1ae/0x274 [<ffffffffa00026db>] ? __process_new_adapter+0x7/0x34 [i2c_core] [<ffffffff810aa29e>] ftrace_module_notify+0x39/0x44 [<ffffffff814405cf>] notifier_call_chain+0x37/0x63 [<ffffffff8106e054>] __blocking_notifier_call_chain+0x46/0x5b [<ffffffff8106e07d>] blocking_notifier_call_chain+0x14/0x16 [<ffffffff8107ffde>] sys_init_module+0x73/0x1f3 [<ffffffff8100acf2>] system_call_fastpath+0x16/0x1b ---[ end trace 2aff4f4ca53ec746 ]--- ftrace faulted on writing [<ffffffffa00026db>] __process_new_adapter+0x7/0x34 [i2c_core] The cause was that the module text was set to read only before ftrace could convert the calls to mcount to nops. Thus, the conversions failed due to not being able to write to the text locations. The simple fix is to move setting the module to read only after the module notifiers are called (where ftrace sets the module mcounts to nops). Reported-by: Peter Zijlstra <[email protected]> Acked-by: Rusty Russell <[email protected]> Signed-off-by: Steven Rostedt <[email protected]>
1 parent 26e20a1 commit 94462ad

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

kernel/module.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2816,18 +2816,6 @@ static struct module *load_module(void __user *umod,
28162816
kfree(info.strmap);
28172817
free_copy(&info);
28182818

2819-
/* Set RO and NX regions for core */
2820-
set_section_ro_nx(mod->module_core,
2821-
mod->core_text_size,
2822-
mod->core_ro_size,
2823-
mod->core_size);
2824-
2825-
/* Set RO and NX regions for init */
2826-
set_section_ro_nx(mod->module_init,
2827-
mod->init_text_size,
2828-
mod->init_ro_size,
2829-
mod->init_size);
2830-
28312819
/* Done! */
28322820
trace_module_load(mod);
28332821
return mod;
@@ -2888,6 +2876,18 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
28882876
blocking_notifier_call_chain(&module_notify_list,
28892877
MODULE_STATE_COMING, mod);
28902878

2879+
/* Set RO and NX regions for core */
2880+
set_section_ro_nx(mod->module_core,
2881+
mod->core_text_size,
2882+
mod->core_ro_size,
2883+
mod->core_size);
2884+
2885+
/* Set RO and NX regions for init */
2886+
set_section_ro_nx(mod->module_init,
2887+
mod->init_text_size,
2888+
mod->init_ro_size,
2889+
mod->init_size);
2890+
28912891
do_mod_ctors(mod);
28922892
/* Start the module */
28932893
if (mod->init != NULL)

0 commit comments

Comments
 (0)