sync patch from master to openEuler-22.03-LTS-Next

Signed-off-by: Bin Hu <hubin73@huawei.com>
This commit is contained in:
Bin Hu 2022-07-12 17:02:55 +08:00
parent 3c7c8d0fac
commit 7ed7b12d3b
14 changed files with 410 additions and 8 deletions

View File

@ -0,0 +1,27 @@
From 5b34dae2eaf57c33beb5cd4e3972a4580259a5fc Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:26:25 +0800
Subject: [PATCH] livepatch-patch-hook: disable HAVE_SIMPLE_ENABLE to keep
register and unregister step of hotpatch
Signed-off-by: Bin Hu <hubin73@huawei.com>
---
kmod/patch/livepatch-patch-hook.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/kmod/patch/livepatch-patch-hook.c b/kmod/patch/livepatch-patch-hook.c
index 9e56fe3..b565a6a 100644
--- a/kmod/patch/livepatch-patch-hook.c
+++ b/kmod/patch/livepatch-patch-hook.c
@@ -70,8 +70,6 @@
RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(8, 2)
# define HAVE_SIMPLE_ENABLE
# endif
-#elif LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0)
-# define HAVE_SIMPLE_ENABLE
#endif
#ifdef RHEL_RELEASE_CODE
--
2.31.0.windows.1

View File

@ -0,0 +1,51 @@
From f435e99fc2652cd6263f3a2fe02b0947a5279a82 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:27:28 +0800
Subject: [PATCH 2/9] kpatch-build: add KBUILD_MODPOST_WARN=1 to avoid modpost
undefined error
Signed-off-by: hubin <hubin73@huawei.com>
---
kpatch-build/kpatch-build | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index 6a9e818..ba33a3e 100644
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -1030,9 +1030,9 @@ fi
# $TARGETS used as list, no quotes.
# shellcheck disable=SC2086
if [[ -z "$USERMODBUILDDIR" ]]; then
- make "${MAKEVARS[@]}" "-j$CPUS" $TARGETS 2>&1 | logger || die
+ KBUILD_MODPOST_WARN=1 make "${MAKEVARS[@]}" "-j$CPUS" $TARGETS 2>&1 | logger || die
else
- make "${MAKEVARS[@]}" -C "$USERMODBUILDDIR" M="$USERMODBUILDDIR" $USERMODFLAGS "-j$CPUS" $TARGETS 2>&1 | logger || die
+ KBUILD_MODPOST_WARN=1 make "${MAKEVARS[@]}" -C "$USERMODBUILDDIR" M="$USERMODBUILDDIR" $USERMODFLAGS "-j$CPUS" $TARGETS 2>&1 | logger || die
fi
# Save original module symvers
@@ -1175,9 +1175,9 @@ for i in $FILES; do
remove_patches
cd "$SRCDIR" || die
if [ -z "$USERMODBUILDDIR" ];then
- make "-j$CPUS" $TARGETS 2>&1 | logger || die
+ KBUILD_MODPOST_WARN=1 make "-j$CPUS" $TARGETS 2>&1 | logger || die
else
- make -C "$USERMODBUILDDIR" M="$USERMODBUILDDIR" $USERMODFLAGS "-j$CPUS" $TARGETS 2>&1 | logger || die
+ KBUILD_MODPOST_WARN=1 make -C "$USERMODBUILDDIR" M="$USERMODBUILDDIR" $USERMODFLAGS "-j$CPUS" $TARGETS 2>&1 | logger || die
fi
cp ${KOBJFILE} ${KOBJFILE_PATH}
apply_patches
@@ -1297,7 +1297,7 @@ KBUILD_EXTRA_SYMBOLS="$KBUILD_EXTRA_SYMBOLS" \
KPATCH_LDFLAGS="$KPATCH_LDFLAGS"
save_env
-make "${MAKEVARS[@]}" 2>&1 | logger || die
+KBUILD_MODPOST_WARN=1 make "${MAKEVARS[@]}" 2>&1 | logger || die
strip -g "$TEMPDIR/patch/$MODNAME.ko"
if [[ "$USE_KLP" -eq 1 ]]; then
--
2.31.0.windows.1

View File

@ -0,0 +1,29 @@
From f1de68ea87426e7ed65dc615a46f5ce1d15df994 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:27:52 +0800
Subject: [PATCH 3/9] kpatch-build: update find_parent_obj to avoid error that
two parent match same object
Signed-off-by: hubin <hubin73@huawei.com>
---
kpatch-build/kpatch-build | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index ba33a3e..ce163e5 100644
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -527,8 +527,8 @@ find_parent_obj() {
[[ "$num" -eq 1 ]] && last_deep_find="$(dirname "$parent")"
fi
if [[ "$num" -eq 0 ]]; then
- parent="$(find $USERMODBUILDDIR -name ".*.cmd" -print0 | xargs -0 grep -l "$grepname" | grep -Fv "$pdir/.${file}.cmd" | head -n1)"
- num="$(find $USERMODBUILDDIR -name ".*.cmd" -print0 | xargs -0 grep -l "$grepname" | grep -Fvc "$pdir/.${file}.cmd")"
+ parent="$(find $USERMODBUILDDIR -name ".*.cmd" -print0 | xargs -0 grep -l "$grepname" | filter_parent_obj "$pdir" "${file}" | head -n1)"
+ num="$(find $USERMODBUILDDIR -name ".*.cmd" -print0 | xargs -0 grep -l "$grepname" | filter_parent_obj "$pdir" "${file}" | wc -l)"
[[ "$num" -eq 1 ]] && last_deep_find="$(dirname "$parent")"
fi
else
--
2.31.0.windows.1

View File

@ -0,0 +1,34 @@
From b1be16f5c42bae41f15a2579cb6ce39406648e19 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:28:00 +0800
Subject: [PATCH 4/9] create-diff-object: fix segment fault when using
KPATCH_FORCE_UNSAFE
Signed-off-by: hubin <hubin73@huawei.com>
---
kpatch-build/create-diff-object.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index bbb40ed..2cca6f3 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -1969,9 +1969,14 @@ static void kpatch_include_force_elements(struct kpatch_elf *kelf)
continue;
}
/* .rela.kpatch.force */
- list_for_each_entry(rela, &sec->relas, list)
+ list_for_each_entry(rela, &sec->relas, list) {
+ if (rela->sym->status != CHANGED) {
+ ERROR("function '%s' marked with KPATCH_FORCE_UNSAFE, but not changed! check your patch.\n",
+ rela->sym->name);
+ }
log_normal("function '%s' marked with KPATCH_FORCE_UNSAFE!\n",
rela->sym->name);
+ }
}
}
--
2.31.0.windows.1

View File

@ -0,0 +1,27 @@
From 83b98afd69c8be39587bfcd2260f03b2b3082a94 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:28:17 +0800
Subject: [PATCH 5/9] kpatch-macros: replace __section with __kpatch_section in
kpatch macro definition
Signed-off-by: hubin <hubin73@huawei.com>
---
kmod/patch/kpatch-macros.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kmod/patch/kpatch-macros.h b/kmod/patch/kpatch-macros.h
index ee455d2..c20b061 100644
--- a/kmod/patch/kpatch-macros.h
+++ b/kmod/patch/kpatch-macros.h
@@ -13,7 +13,7 @@
#endif
#define KPATCH_IGNORE_STATIC(_static) \
- char *__UNIQUE_ID(kpatch_ignore_static_) __section(.kpatch.ignore.statics) = _static;
+ char *__UNIQUE_ID(kpatch_ignore_static_) __kpatch_section(.kpatch.ignore.statics) = _static;
/*
--
2.31.0.windows.1

View File

@ -0,0 +1,35 @@
From 41334ab046ad2c89324b61f76b262228a6bc36ad Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:28:26 +0800
Subject: [PATCH 6/9] create-diff-object: ignore changed of section
__patchable_function_entries
Linux 5.10 aarch64 uses -fpatchable-function-entry=N to generate N NOPs at the
beginning of each function, Section __patchable_function_entries is generated
to record the starting address of these NOPs.
Section __patchable_function_entries will change if the number of functions
changed during making hotpatch, here we just ignore the change of this section.
Signed-off-by: hubin <hubin73@huawei.com>
---
kpatch-build/create-diff-object.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 2cca6f3..8d3f377 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -3062,7 +3062,8 @@ static void kpatch_process_special_sections(struct kpatch_elf *kelf,
list_for_each_entry(sec, &kelf->sections, list) {
if (strcmp(sec->name, "__tracepoints") &&
strcmp(sec->name, "__tracepoints_ptrs") &&
- strcmp(sec->name, "__tracepoints_strings"))
+ strcmp(sec->name, "__tracepoints_strings") &&
+ strcmp(sec->name, "__patchable_function_entries"))
continue;
sec->status = SAME;
--
2.31.0.windows.1

View File

@ -0,0 +1,27 @@
From e1b12b68efc7de9e3e3db52ceda2c1b713dc7cb7 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:28:34 +0800
Subject: [PATCH 7/9] create-diff-object: fix null pointer dereference in
kpatch_ignore_debug_section
Signed-off-by: hubin <hubin73@huawei.com>
---
kpatch-build/create-diff-object.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 8d3f377..03c877e 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -2796,7 +2796,7 @@ static void kpatch_ignore_debug_sections(struct kpatch_elf *kelf)
if (is_debug_section(sec)) {
sec->include = 0;
sec->status = SAME;
- if (!is_rela_section(sec)) {
+ if (!is_rela_section(sec) && sec->secsym) {
sec->secsym->include = 0;
sec->secsym->status = SAME;
}
--
2.31.0.windows.1

View File

@ -0,0 +1,36 @@
From de34b86536bde114f481a73fdbf2f58b643c3e48 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:28:46 +0800
Subject: [PATCH 8/9] create-diff-object: ignore .note.gnu.property section
Linux GABI introduced new .note.gnu.property section which contains a program
property note which describes special handling requirements for linker and run-time loader.
Linux GABI specifies 2 types of entries:
GNU_PROPERTY_STACK_SIZE and GNU_PROPERTY_NO_COPY_ON_PROTECTED
These entries should not take effect when using live-patching, thus, ignore the change of
this section
Signed-off-by: hubin <hubin73@huawei.com>
---
kpatch-build/create-diff-object.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 03c877e..c2ecefa 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -3063,7 +3063,8 @@ static void kpatch_process_special_sections(struct kpatch_elf *kelf,
if (strcmp(sec->name, "__tracepoints") &&
strcmp(sec->name, "__tracepoints_ptrs") &&
strcmp(sec->name, "__tracepoints_strings") &&
- strcmp(sec->name, "__patchable_function_entries"))
+ strcmp(sec->name, "__patchable_function_entries") &&
+ strcmp(sec->name, ".note.gnu.property"))
continue;
sec->status = SAME;
--
2.31.0.windows.1

View File

@ -0,0 +1,27 @@
From 19b6926284ad2811f6de0ec29e0b45f3ae8b09dd Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 15:28:55 +0800
Subject: [PATCH 9/9] create-diff-object: skip creating .kpatch.arch section
for sections with empty secsym
Signed-off-by: hubin <hubin73@huawei.com>
---
kpatch-build/create-diff-object.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index c2ecefa..6b46e1f 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -2952,7 +2952,7 @@ static void kpatch_create_kpatch_arch_section(struct kpatch_elf *kelf, char *obj
continue;
sec = find_section_by_name(&kelf->sections, special->name);
- if (!sec)
+ if (!sec || !sec->secsym)
continue;
/* entries[index].sec */
--
2.31.0.windows.1

View File

@ -0,0 +1,27 @@
From 72d80c02e16d7558bea6512116bac2b9461bf879 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Tue, 10 May 2022 16:12:29 +0800
Subject: [PATCH] kpatch-build: do not copy linux scripts when building OOT
module hotpatch
Signed-off-by: hubin <hubin73@huawei.com>
---
kpatch-build/kpatch-build | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index ce163e5..dc5f5a5 100644
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -955,7 +955,7 @@ grep -q "CONFIG_GCC_PLUGIN_RANDSTRUCT=y" "$CONFIGFILE" && die "kernel option 'CO
# support extended ELF sections. Disable the BTF typeinfo generation in
# link-vmlinux.sh and Makefile.modfinal since kpatch doesn't care about
# that anyway.
-if grep -q "CONFIG_DEBUG_INFO_BTF=y" "$CONFIGFILE" ; then
+if grep -q "CONFIG_DEBUG_INFO_BTF=y" "$CONFIGFILE" && [[ -z "$OOT_MODULE" ]] ; then
cp -f "$SRCDIR/scripts/link-vmlinux.sh" "$TEMPDIR/link-vmlinux.sh" || die
sed -i 's/CONFIG_DEBUG_INFO_BTF/DISABLED_FOR_KPATCH_BUILD/g' "$SRCDIR"/scripts/link-vmlinux.sh || die
--
2.31.0.windows.1

View File

@ -0,0 +1,37 @@
From ff93b567f3cff56e3f0c668258499acb1d511865 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Mon, 23 May 2022 17:00:37 +0800
Subject: [PATCH] create-diff-object: ignore change of certain special sections
Signed-off-by: hubin <hubin73@huawei.com>
---
kpatch-build/create-diff-object.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 6b46e1f..7fabf4d 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -3076,6 +3076,19 @@ static void kpatch_process_special_sections(struct kpatch_elf *kelf,
}
}
+ list_for_each_entry(sec, &kelf->sections, list) {
+ if (strcmp(sec->name, "__patchable_function_entries") &&
+ strcmp(sec->name, ".note.gnu.property"))
+ continue;
+
+ sec->status = SAME;
+ sec->include = 0;
+ if (sec->rela) {
+ sec->rela->status = SAME;
+ sec->rela->include = 0;
+ }
+ }
+
kpatch_regenerate_orc_sections(kelf);
}
--
2.31.0.windows.1

View File

@ -0,0 +1,27 @@
From 556db3ad9deab83942621e56accc711427224ca5 Mon Sep 17 00:00:00 2001
From: hubin <hubin73@huawei.com>
Date: Mon, 23 May 2022 17:08:50 +0800
Subject: [PATCH] create-diff-object: allow __jump_table section change for
module hotpatch
Signed-off-by: hubin <hubin73@huawei.com>
---
kpatch-build/create-diff-object.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 7fabf4d..d7a6789 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -3493,7 +3493,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
* special section init code (e.g., apply_paravirt)
* runs due to late module patching.
*/
- if (!KLP_ARCH && !vmlinux && special)
+ if (!KLP_ARCH && !vmlinux && special && strcmp(sec->base->name, "__jump_table"))
ERROR("unsupported dynrela reference to symbol '%s' in module-specific special section '%s'",
rela->sym->name, sec->base->name);
--
2.31.0.windows.1

View File

@ -1,7 +1,7 @@
Name: kpatch
Epoch: 1
Version: 0.9.5
Release: 5
Release: 6
Summary: A Linux dynamic kernel patching infrastructure
License: GPLv2
@ -41,6 +41,18 @@ Patch0025:0025-create-diff-object-update-for-__already_done.patch
Patch0026:0026-kpatch-build-Add-missing-allocation-failure-checks.patch
Patch0027:0027-create-diff-object-add-support-for-.retpoline_sites-.patch
Patch0028:0028-Fix-sym-type-condition-in-locals_match.patch
Patch0029:0029-livepatch-patch-hook-disable-HAVE_SIMPLE_ENABLE-to-k.patch
Patch0030:0030-kpatch-build-add-KBUILD_MODPOST_WARN-1-to-avoid-modp.patch
Patch0031:0031-kpatch-build-update-find_parent_obj-to-avoid-error-t.patch
Patch0032:0032-create-diff-object-fix-segment-fault-when-using-KPAT.patch
Patch0033:0033-kpatch-macros-replace-__section-with-__kpatch_sectio.patch
Patch0034:0034-create-diff-object-ignore-changed-of-section-__patch.patch
Patch0035:0035-create-diff-object-fix-null-pointer-dereference-in-k.patch
Patch0036:0036-create-diff-object-ignore-.note.gnu.property-section.patch
Patch0037:0037-create-diff-object-skip-creating-.kpatch.arch-sectio.patch
Patch0038:0038-kpatch-build-do-not-copy-linux-scripts-when.patch
Patch0039:0039-create-diff-object-ignore-change-of-certain.patch
Patch0040:0040-create-diff-object-allow-__jump_table-section.patch
BuildRequires: gcc elfutils-libelf-devel kernel-devel git
Requires: bc make gcc patch bison flex openssl-devel
@ -101,6 +113,12 @@ popd
%{_mandir}/man1/*.1.gz
%changelog
* Mon Jul 11 2022 Bin Hu<hubin73@huawei.com> -1:0.9.5-6
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:sync patch from master to openEuler-22.03-LTS-Next
* Wed Mar 30 2022 Zhipeng Xie<xiezhipeng1@huawei.com> -1:0.9.5-5
- Type:clean code
- ID:NA

View File

@ -196,8 +196,8 @@ function fn_check_jobs()
#########################################################
function fn_check_patch(){
local l_patch=$1
if [ ! -f $1 ];then
echo "error:patch file $1 not exist"
if [ ! -f "$1" ];then
echo "error:patch file $1 does not exist"
return 1
fi
G_PATCHFILE=$l_patch
@ -232,7 +232,7 @@ function fn_check_kernelsrc()
local l_kernelsrc=$1
if [ ! -d "$l_kernelsrc" ];then
echo "error: kernel src $l_kernelsrc is not exist, check kernel src failed"
echo "error: kernel src $l_kernelsrc does not exist, check kernel src failed"
return 1
fi
G_KERNEL_SRC=$l_kernelsrc
@ -250,7 +250,7 @@ function fn_check_modulesrc()
local l_modulesrc=$1
if [ ! -d "$l_modulesrc" ];then
echo "error: module src $l_modulesrc is not exist, check module src failed"
echo "error: module src $l_modulesrc does not exist, check module src failed"
return 1
fi
echo "$l_modulesrc" | grep -q ^/
@ -272,7 +272,7 @@ function fn_check_makefile()
local l_module_makefile=$1
if [ ! -f "$l_module_makefile" ] && [ "$(basename $l_module_makefile)" = "Makefile" ];then
echo "error: module makefile $l_module_makefile is not exist or makefile name is not Makefile, check module makefile failed"
echo "error: module makefile $l_module_makefile does not exist or makefile name is not Makefile, check module makefile failed"
return 1
fi
echo "$l_module_makefile" | grep -q ^/
@ -294,7 +294,7 @@ function fn_check_extra_flags()
local l_extra_flags=$1
if [ ! -f "$l_extra_flags" ];then
echo "error: extra flags file $l_extra_flags is not exist, check extra flags failed"
echo "error: extra flags file $l_extra_flags does not exist, check extra flags failed"
return 1
fi
G_EXT_FLAGS="`readlink -f ${l_extra_flags}`"
@ -508,7 +508,7 @@ function fn_makepatch()
echo "error: do not modify the header file"
return 1
fi
if [ -f $G_PATCHFILE ];then
if [ -f "$G_PATCHFILE" ];then
echo "make patch $G_PATCHFILE"
else
echo "no change detected"