From: Zheng Yejian zhengyejian1@huawei.com
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4SFHQ
--------------------------------
Refer to following function procedure, 'obj->mod' is got if not define CONFIG_LIVEPATCH_FTRACE, but it is put if define CONFIG_LIVEPATCH_STOP_MACHINE_CONSISTENCY. If enable state of these two macros changed, reference count of 'obj->mod' would be wrong.
klp_register_patch klp_init_patch klp_init_object klp_find_object_module try_module_get <-- !CONFIG_LIVEPATCH_FTRACE module_put <-- CONFIG_LIVEPATCH_STOP_MACHINE_CONSISTENCY klp_free_patch_start klp_free_objects __klp_free_objects module_put <-- CONFIG_LIVEPATCH_STOP_MACHINE_CONSISTENCY
So we use CONFIG_LIVEPATCH_STOP_MACHINE_CONSISTENCY uniformly.
Fixes: c33e42836a74 ("livepatch/core: Allow implementation without ftrace") Signed-off-by: Zheng Yejian zhengyejian1@huawei.com Reviewed-by: Xu Kuohai xukuohai@huawei.com Reviewed-by: Cheng Jian cj.chengjian@huawei.com Signed-off-by: Zheng Zengkai zhengzengkai@huawei.com --- kernel/livepatch/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index c9c76b440177..b46ef236424d 100644 --- a/kernel/livepatch/core.c +++ b/kernel/livepatch/core.c @@ -122,10 +122,7 @@ static int klp_find_object_module(struct klp_object *obj) * until mod->exit() finishes. This is especially important for * patches that modify semantic of the functions. */ -#ifdef CONFIG_LIVEPATCH_FTRACE - if (mod && mod->klp_alive) - obj->mod = mod; -#else +#ifdef CONFIG_LIVEPATCH_STOP_MACHINE_CONSISTENCY if (!mod) { pr_err("module '%s' not loaded\n", obj->name); mutex_unlock(&module_mutex); @@ -138,6 +135,9 @@ static int klp_find_object_module(struct klp_object *obj) }
obj->mod = mod; +#else + if (mod && mod->klp_alive) + obj->mod = mod; #endif
mutex_unlock(&module_mutex);