Unverified Commit b71995b9 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!3542 Support kernel livepatching

Merge Pull Request from: @ci-robot 
 
PR sync from: Zheng Yejian <zhengyejian1@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/62Z66QRLJLJFDXUPU4LI3FUNXFPAFOCZ/ 
Zheng Yejian (33):
  livepatch/core: Allow implementation without ftrace
  livepatch/core: Reuse common codes in the solution without ftrace
  Revert "x86/insn: Make insn_complete() static"
  livepatch/x86: Support livepatch without ftrace
  livepatch/core: Disable support for replacing
  livepatch/core: Restrict livepatch patched/unpatched when plant kprobe
  livepatch/core: Support load and unload hooks
  livepatch: samples: Adapt livepatch-sample for solution without ftrace
  livepatch/core: Support jump_label
  livepatch: Fix crash when access the global variable in hook
  livepatch: Fix patching functions which have static_call
  livepatch/core: Avoid conflict with static {call,key}
  livepatch/arm64: Support livepatch without ftrace
  livepatch/core: Revert module_enable_ro and module_disable_ro
  livepatch: Enable livepatch configs in openeuler_defconfig
  arm/module: Use plt section indices for relocations
  livepatch/core: Add support for arm for klp relocation
  livepatch/arm: Support livepatch without ftrace
  livepatch/ppc32: Support livepatch without ftrace
  livepatch: Use breakpoint exception to optimize enabling livepatch
  livepatch/x86: Support breakpoint exception optimization
  livepatch: Add arch_klp_init
  livepatch/arm64: Support breakpoint exception optimization
  livepatch/arm: Support breakpoint exception optimization
  livepatch: Add klp_module_delete_safety_check
  livepatch/x86: Add arch_klp_module_check_calltrace
  livepatch/arm64: Add arch_klp_module_check_calltrace
  livepatch/arm: Add arch_klp_module_check_calltrace
  livepatch: Bypass dead thread when check calltrace
  livepatch/ppc64: Implement livepatch without ftrace for ppc64be
  livepatch/ppc64: Sample testcase fix ppc64
  livepatch/powerpc: Support breakpoint exception optimization
  livepatch/powerpc: Add arch_klp_module_check_calltrace


-- 
2.25.1
 
https://gitee.com/openeuler/kernel/issues/I8MGE6 
 
Link:https://gitee.com/openeuler/kernel/pulls/3542

 

Reviewed-by: default avatarXu Kuohai <xukuohai@huawei.com>
Reviewed-by: default avatarZucheng Zheng <zhengzucheng@huawei.com>
Reviewed-by: default avatarZhang Jianhua <chris.zjh@huawei.com>
Reviewed-by: default avatarWeilong Chen <chenweilong@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parents 45c76c86 9478af9b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2111,7 +2111,7 @@ permissions on the task specified to change its timerslack_ns value.

3.11	/proc/<pid>/patch_state - Livepatch patch operation state
-----------------------------------------------------------------
When CONFIG_LIVEPATCH is enabled, this file displays the value of the
When CONFIG_LIVEPATCH_FTRACE is enabled, this file displays the value of the
patch state for the task.

A value of '-1' indicates that no patch is in transition.
+3 −0
Original line number Diff line number Diff line
@@ -139,6 +139,7 @@ config ARM
	select RTC_LIB
	select SPARSE_IRQ if !(ARCH_FOOTBRIDGE || ARCH_RPC)
	select SYS_SUPPORTS_APM_EMULATION
	select HAVE_LIVEPATCH_WO_FTRACE
	select THREAD_INFO_IN_TASK
	select TIMER_OF if OF
	select HAVE_ARCH_VMAP_STACK if MMU && ARM_HAS_GROUP_RELOCS
@@ -1828,3 +1829,5 @@ config ARCH_HIBERNATION_POSSIBLE
endmenu

source "arch/arm/Kconfig.assembler"

source "kernel/livepatch/Kconfig"
+61 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * livepatch.h - arm-specific Kernel Live Patching Core
 *
 * Copyright (C) 2018  Huawei Technologies Co., Ltd.
 * Copyright (C) 2023  Huawei Technologies Co., Ltd.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _ASM_ARM_LIVEPATCH_H
#define _ASM_ARM_LIVEPATCH_H

#ifdef CONFIG_LIVEPATCH_WO_FTRACE

#ifdef CONFIG_ARM_MODULE_PLTS
#define LJMP_INSN_SIZE	3
#else
#define LJMP_INSN_SIZE	1
#endif /* CONFIG_ARM_MODULE_PLTS */

#define KLP_ARM_BREAKPOINT_INSTRUCTION		0xe7f001f9

struct arch_klp_data {
	u32 old_insns[LJMP_INSN_SIZE];
	/*
	 * Saved opcode at the entry of the old func (which maybe replaced
	 * with breakpoint).
	 */
	u32 saved_opcode;
};

#define KLP_MAX_REPLACE_SIZE sizeof_field(struct arch_klp_data, old_insns)

struct klp_func;

/* kernel livepatch instruction barrier */
#define klp_smp_isb()  isb()
int arch_klp_patch_func(struct klp_func *func);
void arch_klp_unpatch_func(struct klp_func *func);
long arch_klp_save_old_code(struct arch_klp_data *arch_data, void *old_func);
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_ARM_LIVEPATCH_H */
+3 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ struct plt_entries {
struct mod_plt_sec {
	struct elf32_shdr	*plt;
	struct plt_entries	*plt_ent;
	int			plt_shndx;
	int			plt_count;
};

@@ -36,7 +37,8 @@ struct mod_arch_specific {
};

struct module;
u32 get_module_plt(struct module *mod, unsigned long loc, Elf32_Addr val);
u32 get_module_plt(struct module *mod, Elf32_Shdr *sechdrs,
		   unsigned long loc, Elf32_Addr val);
#ifdef CONFIG_ARM_MODULE_PLTS
bool in_module_plt(unsigned long loc);
#else
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ obj-$(CONFIG_ARM_ARCH_TIMER) += arch_timer.o
obj-$(CONFIG_FUNCTION_TRACER)	+= entry-ftrace.o
obj-$(CONFIG_DYNAMIC_FTRACE)	+= ftrace.o insn.o patch.o
obj-$(CONFIG_FUNCTION_GRAPH_TRACER)	+= ftrace.o insn.o patch.o
obj-$(CONFIG_LIVEPATCH_WO_FTRACE)	+= livepatch.o insn.o patch.o
obj-$(CONFIG_JUMP_LABEL)	+= jump_label.o insn.o patch.o
obj-$(CONFIG_KEXEC)		+= machine_kexec.o relocate_kernel.o
# Main staffs in KPROBES are in arch/arm/probes/ .
Loading