hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8MGE6
--------------------------------
Add arch_klp_module_check_calltrace to check whether stacks of all tasks are within the code segment of module.
Signed-off-by: Yang Jihong yangjihong1@huawei.com Signed-off-by: Zheng Yejian zhengyejian1@huawei.com --- arch/arm64/include/asm/livepatch.h | 1 + arch/arm64/kernel/livepatch.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+)
diff --git a/arch/arm64/include/asm/livepatch.h b/arch/arm64/include/asm/livepatch.h index 8594742abd57..af450bd081ed 100644 --- a/arch/arm64/include/asm/livepatch.h +++ b/arch/arm64/include/asm/livepatch.h @@ -50,6 +50,7 @@ bool arch_check_jump_insn(unsigned long func_addr); int arch_klp_check_calltrace(bool (*check_func)(void *, int *, unsigned long), void *data); int arch_klp_add_breakpoint(struct arch_klp_data *arch_data, void *old_func); void arch_klp_remove_breakpoint(struct arch_klp_data *arch_data, void *old_func); +int arch_klp_module_check_calltrace(void *data); #endif /* CONFIG_LIVEPATCH_WO_FTRACE */
#endif /* _ASM_ARM64_LIVEPATCH_H */ diff --git a/arch/arm64/kernel/livepatch.c b/arch/arm64/kernel/livepatch.c index 212358b0e72f..829c7f376ec6 100644 --- a/arch/arm64/kernel/livepatch.c +++ b/arch/arm64/kernel/livepatch.c @@ -120,6 +120,29 @@ int arch_klp_check_calltrace(bool (*check_func)(void *, int *, unsigned long), v return do_check_calltrace(&args, klp_check_jump_func); }
+static bool check_module_calltrace(void *ws_args, unsigned long pc) +{ + struct walk_stackframe_args *args = ws_args; + struct module *mod = args->data; + + if (within_module_core(pc, mod)) { + pr_err("module %s is in use!\n", mod->name); + args->ret = -EBUSY; + return false; + } + return true; +} + +int arch_klp_module_check_calltrace(void *data) +{ + struct walk_stackframe_args args = { + .data = data, + .ret = 0 + }; + + return do_check_calltrace(&args, check_module_calltrace); +} + int arch_klp_add_breakpoint(struct arch_klp_data *arch_data, void *old_func) { u32 insn = BRK64_OPCODE_KLP;