Commit 12326136 authored by Zheng Yejian's avatar Zheng Yejian Committed by Zheng Zengkai
Browse files

livepatch/core: Fix where module get and put in different macro

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: c33e4283 ("livepatch/core: Allow implementation without ftrace")
Signed-off-by: default avatarZheng Yejian <zhengyejian1@huawei.com>
Reviewed-by: default avatarXu Kuohai <xukuohai@huawei.com>
Reviewed-by: default avatarCheng Jian <cj.chengjian@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent 70e6a87c
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -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);
@@ -137,6 +134,9 @@ static int klp_find_object_module(struct klp_object *obj)
		return -EINVAL;
	}

	obj->mod = mod;
#else
	if (mod && mod->klp_alive)
		obj->mod = mod;
#endif