Commit f45d5a1a authored by Zheng Yejian's avatar Zheng Yejian
Browse files

livepatch/core: Allow implementation without ftrace

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I8MGE6


CVE: NA

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

Currently livepatch implementation is based on ftrace, and coming
patches will introduce a new solution without ftrace which will
use config CONFIG_LIVEPATCH_WO_FTRACE.

Implements livepatch without ftrace by direct jump, we
directly modify the first few instructions(usually one,
but four for long jumps under ARM64) of the old function
as jump instructions by stop_machine, so it will jump to
the first address of the new function when livepatch enable

KERNEL/MODULE
call/bl A---------------old_A------------
                        | jump new_A----+--------|
                        |               |        |
                        |               |        |
                        -----------------        |
                                                 |
                                                 |
                                                 |
livepatch_module-------------                    |
|                           |                    |
|new_A <--------------------+--------------------|
|                           |
|                           |
|---------------------------|
| .plt                      |
| ......PLTS for livepatch  |
-----------------------------

Something we need to consider under different architectures:

1. jump instruction
2. partial relocation in new function requires for livepatch.
3. long jumps may be required if the jump address exceeds the
   offset. both for livepatch relocation and livepatch enable.

So isolate ftrace based codes with config CONFIG_LIVEPATCH_FTRACE,
then make livepatch solutions optional so that users can select
between solutions later.

Note that, in this patch, the new solution that without ftrace isn't
implemented, but just enable its config CONFIG_LIVEPATCH_WO_FTRACE on
x86_64 to ensure that there is no compile problems.

Signed-off-by: default avatarCheng Jian <cj.chengjian@huawei.com>
Signed-off-by: default avatarWang ShaoBo <bobo.shaobowang@huawei.com>
Signed-off-by: default avatarDong Kai <dongkai11@huawei.com>
Signed-off-by: default avatarYe Weihua <yeweihua4@huawei.com>
Signed-off-by: default avatarZheng Yejian <zhengyejian1@huawei.com>
parent 6d225089
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.
+2 −2
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ config 64BIT

config LIVEPATCH_64
	def_bool PPC64
	depends on LIVEPATCH
	depends on LIVEPATCH_FTRACE

config MMU
	bool
@@ -256,7 +256,7 @@ config PPC
	select HAVE_KPROBES_ON_FTRACE
	select HAVE_KRETPROBES
	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION if HAVE_OBJTOOL_MCOUNT && (!ARCH_USING_PATCHABLE_FUNCTION_ENTRY || (!CC_IS_GCC || GCC_VERSION >= 110100))
	select HAVE_LIVEPATCH			if HAVE_DYNAMIC_FTRACE_WITH_REGS
	select HAVE_LIVEPATCH_FTRACE		if HAVE_DYNAMIC_FTRACE_WITH_REGS
	select HAVE_MOD_ARCH_SPECIFIC
	select HAVE_NMI				if PERF_EVENTS || (PPC64 && PPC_BOOK3S)
	select HAVE_OPTPROBES
+1 −1
Original line number Diff line number Diff line
@@ -194,7 +194,7 @@ config S390
	select HAVE_KPROBES_ON_FTRACE
	select HAVE_KRETPROBES
	select HAVE_KVM
	select HAVE_LIVEPATCH
	select HAVE_LIVEPATCH_FTRACE
	select HAVE_MEMBLOCK_PHYS_MAP
	select HAVE_MOD_ARCH_SPECIFIC
	select HAVE_NMI
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ CONFIG_KEXEC_FILE=y
CONFIG_KEXEC_SIG=y
CONFIG_CRASH_DUMP=y
CONFIG_LIVEPATCH=y
CONFIG_LIVEPATCH_FTRACE=y
CONFIG_MARCH_ZEC12=y
CONFIG_TUNE_ZEC12=y
CONFIG_NR_CPUS=512
+1 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ CONFIG_KEXEC_FILE=y
CONFIG_KEXEC_SIG=y
CONFIG_CRASH_DUMP=y
CONFIG_LIVEPATCH=y
CONFIG_LIVEPATCH_FTRACE=y
CONFIG_MARCH_ZEC12=y
CONFIG_TUNE_ZEC12=y
CONFIG_NR_CPUS=512
Loading