module: fix ddebug_remove_module()

ddebug_remove_module() use mod->name to find the ddebug_table of the
module and remove it. But dynamic_debug_setup() use the first
_ddebug->modname to create ddebug_table for the module. It's ok when
the _ddebug->modname is the same with the mod->name.

But livepatch module is special, it may contain _ddebugs of other
modules, the modname of which is different from the name of livepatch
module. So ddebug_remove_module() can't use mod->name to find the
right ddebug_table and remove it. It can cause kernel crash when we cat
the file <debugfs>/dynamic_debug/control.

Signed-off-by: Zhou Chengming <zhouchengming1@huawei.com>
Signed-off-by: Jessica Yu <jeyu@kernel.org>

authored by

Zhou Chengming and committed by
Jessica Yu
52796312 4fd3e4ef

+6 -6
+6 -6
kernel/module.c
··· 2707 2707 } 2708 2708 #endif /* CONFIG_KALLSYMS */ 2709 2709 2710 - static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num) 2710 + static void dynamic_debug_setup(struct module *mod, struct _ddebug *debug, unsigned int num) 2711 2711 { 2712 2712 if (!debug) 2713 2713 return; 2714 2714 #ifdef CONFIG_DYNAMIC_DEBUG 2715 - if (ddebug_add_module(debug, num, debug->modname)) 2715 + if (ddebug_add_module(debug, num, mod->name)) 2716 2716 pr_err("dynamic debug error adding module: %s\n", 2717 2717 debug->modname); 2718 2718 #endif 2719 2719 } 2720 2720 2721 - static void dynamic_debug_remove(struct _ddebug *debug) 2721 + static void dynamic_debug_remove(struct module *mod, struct _ddebug *debug) 2722 2722 { 2723 2723 if (debug) 2724 - ddebug_remove_module(debug->modname); 2724 + ddebug_remove_module(mod->name); 2725 2725 } 2726 2726 2727 2727 void * __weak module_alloc(unsigned long size) ··· 3715 3715 goto free_arch_cleanup; 3716 3716 } 3717 3717 3718 - dynamic_debug_setup(info->debug, info->num_debug); 3718 + dynamic_debug_setup(mod, info->debug, info->num_debug); 3719 3719 3720 3720 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */ 3721 3721 ftrace_module_init(mod); ··· 3779 3779 module_disable_nx(mod); 3780 3780 3781 3781 ddebug_cleanup: 3782 - dynamic_debug_remove(info->debug); 3782 + dynamic_debug_remove(mod, info->debug); 3783 3783 synchronize_sched(); 3784 3784 kfree(mod->args); 3785 3785 free_arch_cleanup: