提交 08ac533f 编写于 作者: C Cheng Jian 提交者: Xie XiuQi

livepatch/core: supprt load and unload hooks

euler inclusion
category: feature
Bugzilla: 5507
CVE: N/A

----------------------------------------

front-tools kpatch-build support load and unload hooks, but the
kernel does not fit this feature. just implement it.
Signed-off-by: NCheng Jian <cj.chengjian@huawei.com>
Reviewed-by: NLi Bin <huawei.libin@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 b3f3a1cc
......@@ -90,6 +90,12 @@ struct klp_func {
struct klp_object;
#ifdef CONFIG_LIVEPATCH_WO_FTRACE
struct klp_hook {
void (*hook)(void);
};
#endif
/**
* struct klp_callbacks - pre/post live-(un)patch callback structure
* @pre_patch: executed before code patching
......@@ -126,6 +132,10 @@ struct klp_object {
/* external */
const char *name;
struct klp_func *funcs;
#ifdef CONFIG_LIVEPATCH_WO_FTRACE
struct klp_hook *hooks_load;
struct klp_hook *hooks_unload;
#endif
struct klp_callbacks callbacks;
/* internal */
......
......@@ -1056,6 +1056,34 @@ static int klp_init_object(struct klp_patch *patch, struct klp_object *obj)
return ret;
}
#ifdef CONFIG_LIVEPATCH_WO_FTRACE
static inline int klp_load_hook(struct klp_object *obj)
{
struct klp_hook *hook;
if (!obj->hooks_load)
return 0;
for (hook = obj->hooks_load; hook->hook; hook++)
(*hook->hook)();
return 0;
}
static inline int klp_unload_hook(struct klp_object *obj)
{
struct klp_hook *hook;
if (!obj->hooks_unload)
return 0;
for (hook = obj->hooks_unload; hook->hook; hook++)
(*hook->hook)();
return 0;
}
#endif
static int klp_init_patch(struct klp_patch *patch)
{
struct klp_object *obj;
......@@ -1087,6 +1115,11 @@ static int klp_init_patch(struct klp_patch *patch)
goto free;
}
#ifdef CONFIG_LIVEPATCH_WO_FTRACE
klp_for_each_object(patch, obj)
klp_load_hook(obj);
#endif
list_add_tail(&patch->list, &klp_patches);
mutex_unlock(&klp_mutex);
......@@ -1115,6 +1148,9 @@ static int klp_init_patch(struct klp_patch *patch)
int klp_unregister_patch(struct klp_patch *patch)
{
int ret;
#ifdef CONFIG_LIVEPATCH_WO_FTRACE
struct klp_object *obj;
#endif
mutex_lock(&klp_mutex);
......@@ -1130,6 +1166,11 @@ int klp_unregister_patch(struct klp_patch *patch)
klp_free_patch(patch);
#ifdef CONFIG_LIVEPATCH_WO_FTRACE
klp_for_each_object(patch, obj)
klp_unload_hook(obj);
#endif
mutex_unlock(&klp_mutex);
kobject_put(&patch->kobj);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册