Skip to content

Commit 61618f3

Browse files
amlutogregkh
authored andcommitted
module: Clean up ro/nx after early module load failures
commit ff7e005 upstream. The commit 4982223 module: set nx before marking module MODULE_STATE_COMING. introduced a regression: if a module fails to parse its arguments or if mod_sysfs_setup fails, then the module's memory will be freed while still read-only. Anything that reuses that memory will crash as soon as it tries to write to it. Cc: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Andy Lutomirski <luto@amacapital.net> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c13c282 commit 61618f3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

kernel/module.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3308,6 +3308,11 @@ static int load_module(struct load_info *info, const char __user *uargs,
33083308
mutex_lock(&module_mutex);
33093309
module_bug_cleanup(mod);
33103310
mutex_unlock(&module_mutex);
3311+
3312+
/* we can't deallocate the module until we clear memory protection */
3313+
unset_module_init_ro_nx(mod);
3314+
unset_module_core_ro_nx(mod);
3315+
33113316
ddebug_cleanup:
33123317
dynamic_debug_remove(info->debug);
33133318
synchronize_sched();

0 commit comments

Comments
 (0)