hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I9R2TB
--------------------------------
When run into arch_klp_check_activeness_func(), func_node corresponding to func->old_func has been stored in func->func_node and it must be valid, So no need to find func_node again or validate it again. __klp_enable_patch() klp_mem_prepare() func_node_alloc // 1. Alloc func->func_node for func->old_func klp_try_enable_patch() klp_check_calltrace() arch_klp_check_activeness_func() // 2. Access func_node found by func->old_func klp_breakpoint_optimize() klp_breakpoint_enable_patch() ... arch_klp_check_activeness_func() // 3. Access func_node found by func->old_func
Signed-off-by: Zheng Yejian zhengyejian1@huawei.com --- arch/powerpc/kernel/livepatch_64.c | 7 +++---- include/linux/livepatch.h | 1 - kernel/livepatch/core.c | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/arch/powerpc/kernel/livepatch_64.c b/arch/powerpc/kernel/livepatch_64.c index dd84bd767658..79921c0bacc8 100644 --- a/arch/powerpc/kernel/livepatch_64.c +++ b/arch/powerpc/kernel/livepatch_64.c @@ -85,7 +85,7 @@ int arch_klp_check_activeness_func(struct klp_func *func, int enable, unsigned long func_addr, func_size; struct klp_func_node *func_node = NULL;
- func_node = klp_find_func_node(func->old_func); + func_node = func->func_node; /* Check func address in stack */ if (enable) { if (func->patched || func->force == KLP_ENFORCEMENT) @@ -94,7 +94,7 @@ int arch_klp_check_activeness_func(struct klp_func *func, int enable, * When enable, checking the currently * active functions. */ - if (!func_node || list_empty(&func_node->func_stack)) { + if (list_empty(&func_node->func_stack)) { /* * No patched on this function * [ the origin one ] @@ -169,8 +169,7 @@ int arch_klp_check_activeness_func(struct klp_func *func, int enable, return ret; #endif
- if (func_node == NULL || - func_node->arch_data.trampoline.magic != BRANCH_TRAMPOLINE_MAGIC) + if (func_node->arch_data.trampoline.magic != BRANCH_TRAMPOLINE_MAGIC) return 0;
func_addr = (unsigned long)&func_node->arch_data.trampoline; diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h index 427485f73793..38d707b9b4e1 100644 --- a/include/linux/livepatch.h +++ b/include/linux/livepatch.h @@ -239,7 +239,6 @@ struct klp_func_node { void *brk_func; };
-struct klp_func_node *klp_find_func_node(const void *old_func); void klp_add_func_node(struct klp_func_node *func_node); void klp_del_func_node(struct klp_func_node *func_node); void *klp_get_brk_func(void *addr); diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index 9284f5076858..2ccd00113085 100644 --- a/kernel/livepatch/core.c +++ b/kernel/livepatch/core.c @@ -1359,7 +1359,7 @@ int __weak arch_klp_check_activeness_func(struct klp_func *func, int enable, struct klp_func_node *func_node = NULL; unsigned long old_func = (unsigned long)func->old_func;
- func_node = klp_find_func_node(func->old_func); + func_node = func->func_node; /* Check func address in stack */ if (enable) { if (func->patched || func->force == KLP_ENFORCEMENT) @@ -1551,7 +1551,7 @@ static LIST_HEAD(klp_func_list); * The caller must ensure that the klp_mutex lock is held or is in the rcu read * critical area. */ -struct klp_func_node *klp_find_func_node(const void *old_func) +static struct klp_func_node *klp_find_func_node(const void *old_func) { struct klp_func_node *func_node;