From eda47481b90116aaa47930bd2a51ca60e46c2e10 Mon Sep 17 00:00:00 2001 From: yezengruan Date: Wed, 15 Jun 2022 17:14:30 +0800 Subject: [PATCH] update libcareplus to version 1.0.0-12 kpatch_process: fix possible double free. ptrace: fix NULL pointer access problem fix patched process crashing when acccess the global var fix probably restore cc symbol link fail when kill patch building uncourteous optimize: Remove unnecessary comparison code Signed-off-by: yezengruan (cherry picked from commit f3d59711105eb667fa2f920958fcbdbb7068afd2) --- ...ector-instruction-in-str_do_gotpcrel.patch | 0 ...-add-align-while-FLAGS_PUSH_SECTION-.patch | 0 ...-for-LCOLD-LHOT-.cold.NUM-.init_arra.patch | 0 ...adderss-for-STT_NOTYPE-type-of-symbo.patch | 0 ...trip-adapt-to-new-gcc-version-10.3.1.patch | 0 ...tignore-ignore-some-tests-and-binary.patch | 0 ...ke-adapt-libcare-patch-make-to-meson.patch | 0 ...tible-with-older-versions-of-the-so-.patch | 0 ..._parse-fix-failed-to-recognize-.cold.patch | 0 ...09-help-modify-some-help-information.patch | 0 ...010-libcare-patch-make-fix-some-bugs.patch | 0 ...libcare-ctl-to-mprotect-qemu-process.patch | 0 ...libcare-dump-change-the-return-value.patch | 0 ...o-make-kpatch-for-RPM-based-packages.patch | 0 ...tch_process-fix-possible-double-free.patch | 24 +++ ...race-fix-NULL-pointer-access-problem.patch | 39 +++++ ...ess-crashing-when-acccess-the-global.patch | 156 ++++++++++++++++++ ...tore-cc-symbol-link-fail-when-kill-p.patch | 100 +++++++++++ ...e-Remove-unnecessary-comparison-code.patch | 39 +++++ ...bly-restore-cc-symbol-link-fail-when.patch | 101 ++++++++++++ ...tore-cc-symbol-link-fail-when-kill-p.patch | 26 +++ libcareplus.spec | 44 +++-- 22 files changed, 514 insertions(+), 15 deletions(-) rename gensrc-skip-vector-instruction-in-str_do_gotpcrel.patch => 0000-gensrc-skip-vector-instruction-in-str_do_gotpcrel.patch (100%) rename gensrc-we-should-add-align-while-FLAGS_PUSH_SECTION-.patch => 0001-gensrc-we-should-add-align-while-FLAGS_PUSH_SECTION-.patch (100%) rename fix-cblock-parse-for-LCOLD-LHOT-.cold.NUM-.init_arra.patch => 0002-fix-cblock-parse-for-LCOLD-LHOT-.cold.NUM-.init_arra.patch (100%) rename elf-add-section-adderss-for-STT_NOTYPE-type-of-symbo.patch => 0003-elf-add-section-adderss-for-STT_NOTYPE-type-of-symbo.patch (100%) rename elf-strip-adapt-to-new-gcc-version-10.3.1.patch => 0004-elf-strip-adapt-to-new-gcc-version-10.3.1.patch (100%) rename gitignore-ignore-some-tests-and-binary.patch => 0005-gitignore-ignore-some-tests-and-binary.patch (100%) rename libcare-patch-make-adapt-libcare-patch-make-to-meson.patch => 0006-libcare-patch-make-adapt-libcare-patch-make-to-meson.patch (100%) rename kpatch_elf-compatible-with-older-versions-of-the-so-.patch => 0007-kpatch_elf-compatible-with-older-versions-of-the-so-.patch (100%) rename kpatch_parse-fix-failed-to-recognize-.cold.patch => 0008-kpatch_parse-fix-failed-to-recognize-.cold.patch (100%) rename help-modify-some-help-information.patch => 0009-help-modify-some-help-information.patch (100%) rename libcare-patch-make-fix-some-bugs.patch => 0010-libcare-patch-make-fix-some-bugs.patch (100%) rename selinux-enable-libcare-ctl-to-mprotect-qemu-process.patch => 0011-selinux-enable-libcare-ctl-to-mprotect-qemu-process.patch (100%) rename libcare-dump-change-the-return-value.patch => 0012-libcare-dump-change-the-return-value.patch (100%) rename modify-pkgbuild-to-make-kpatch-for-RPM-based-packages.patch => 0013-modify-pkgbuild-to-make-kpatch-for-RPM-based-packages.patch (100%) create mode 100644 0014-kpatch_process-fix-possible-double-free.patch create mode 100644 0015-ptrace-fix-NULL-pointer-access-problem.patch create mode 100644 0016-fix-patched-process-crashing-when-acccess-the-global.patch create mode 100644 0017-fix-probably-restore-cc-symbol-link-fail-when-kill-p.patch create mode 100644 0018-optimize-Remove-unnecessary-comparison-code.patch create mode 100644 0019-Revert-fix-probably-restore-cc-symbol-link-fail-when.patch create mode 100644 0020-fix-probably-restore-cc-symbol-link-fail-when-kill-p.patch diff --git a/gensrc-skip-vector-instruction-in-str_do_gotpcrel.patch b/0000-gensrc-skip-vector-instruction-in-str_do_gotpcrel.patch similarity index 100% rename from gensrc-skip-vector-instruction-in-str_do_gotpcrel.patch rename to 0000-gensrc-skip-vector-instruction-in-str_do_gotpcrel.patch diff --git a/gensrc-we-should-add-align-while-FLAGS_PUSH_SECTION-.patch b/0001-gensrc-we-should-add-align-while-FLAGS_PUSH_SECTION-.patch similarity index 100% rename from gensrc-we-should-add-align-while-FLAGS_PUSH_SECTION-.patch rename to 0001-gensrc-we-should-add-align-while-FLAGS_PUSH_SECTION-.patch diff --git a/fix-cblock-parse-for-LCOLD-LHOT-.cold.NUM-.init_arra.patch b/0002-fix-cblock-parse-for-LCOLD-LHOT-.cold.NUM-.init_arra.patch similarity index 100% rename from fix-cblock-parse-for-LCOLD-LHOT-.cold.NUM-.init_arra.patch rename to 0002-fix-cblock-parse-for-LCOLD-LHOT-.cold.NUM-.init_arra.patch diff --git a/elf-add-section-adderss-for-STT_NOTYPE-type-of-symbo.patch b/0003-elf-add-section-adderss-for-STT_NOTYPE-type-of-symbo.patch similarity index 100% rename from elf-add-section-adderss-for-STT_NOTYPE-type-of-symbo.patch rename to 0003-elf-add-section-adderss-for-STT_NOTYPE-type-of-symbo.patch diff --git a/elf-strip-adapt-to-new-gcc-version-10.3.1.patch b/0004-elf-strip-adapt-to-new-gcc-version-10.3.1.patch similarity index 100% rename from elf-strip-adapt-to-new-gcc-version-10.3.1.patch rename to 0004-elf-strip-adapt-to-new-gcc-version-10.3.1.patch diff --git a/gitignore-ignore-some-tests-and-binary.patch b/0005-gitignore-ignore-some-tests-and-binary.patch similarity index 100% rename from gitignore-ignore-some-tests-and-binary.patch rename to 0005-gitignore-ignore-some-tests-and-binary.patch diff --git a/libcare-patch-make-adapt-libcare-patch-make-to-meson.patch b/0006-libcare-patch-make-adapt-libcare-patch-make-to-meson.patch similarity index 100% rename from libcare-patch-make-adapt-libcare-patch-make-to-meson.patch rename to 0006-libcare-patch-make-adapt-libcare-patch-make-to-meson.patch diff --git a/kpatch_elf-compatible-with-older-versions-of-the-so-.patch b/0007-kpatch_elf-compatible-with-older-versions-of-the-so-.patch similarity index 100% rename from kpatch_elf-compatible-with-older-versions-of-the-so-.patch rename to 0007-kpatch_elf-compatible-with-older-versions-of-the-so-.patch diff --git a/kpatch_parse-fix-failed-to-recognize-.cold.patch b/0008-kpatch_parse-fix-failed-to-recognize-.cold.patch similarity index 100% rename from kpatch_parse-fix-failed-to-recognize-.cold.patch rename to 0008-kpatch_parse-fix-failed-to-recognize-.cold.patch diff --git a/help-modify-some-help-information.patch b/0009-help-modify-some-help-information.patch similarity index 100% rename from help-modify-some-help-information.patch rename to 0009-help-modify-some-help-information.patch diff --git a/libcare-patch-make-fix-some-bugs.patch b/0010-libcare-patch-make-fix-some-bugs.patch similarity index 100% rename from libcare-patch-make-fix-some-bugs.patch rename to 0010-libcare-patch-make-fix-some-bugs.patch diff --git a/selinux-enable-libcare-ctl-to-mprotect-qemu-process.patch b/0011-selinux-enable-libcare-ctl-to-mprotect-qemu-process.patch similarity index 100% rename from selinux-enable-libcare-ctl-to-mprotect-qemu-process.patch rename to 0011-selinux-enable-libcare-ctl-to-mprotect-qemu-process.patch diff --git a/libcare-dump-change-the-return-value.patch b/0012-libcare-dump-change-the-return-value.patch similarity index 100% rename from libcare-dump-change-the-return-value.patch rename to 0012-libcare-dump-change-the-return-value.patch diff --git a/modify-pkgbuild-to-make-kpatch-for-RPM-based-packages.patch b/0013-modify-pkgbuild-to-make-kpatch-for-RPM-based-packages.patch similarity index 100% rename from modify-pkgbuild-to-make-kpatch-for-RPM-based-packages.patch rename to 0013-modify-pkgbuild-to-make-kpatch-for-RPM-based-packages.patch diff --git a/0014-kpatch_process-fix-possible-double-free.patch b/0014-kpatch_process-fix-possible-double-free.patch new file mode 100644 index 0000000..07350ac --- /dev/null +++ b/0014-kpatch_process-fix-possible-double-free.patch @@ -0,0 +1,24 @@ +From fdf172f68f2270306effda39211a4be5ca7e437e Mon Sep 17 00:00:00 2001 +From: wangcichen +Date: Tue, 17 May 2022 16:40:26 +0800 +Subject: [PATCH 1/5] kpatch_process: fix possible double free. + +--- + src/kpatch_process.c | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/src/kpatch_process.c b/src/kpatch_process.c +index 9d6daa4..a31f70c 100644 +--- a/src/kpatch_process.c ++++ b/src/kpatch_process.c +@@ -682,7 +682,6 @@ process_list_threads(kpatch_process_t *proc, + t = realloc(pids, *alloc * sizeof(*pids)); + if (t == NULL) { + kplogerror("Failed to (re)allocate memory for pids\n"); +- closedir(dir); + goto dealloc; + } + +-- +2.27.0 + diff --git a/0015-ptrace-fix-NULL-pointer-access-problem.patch b/0015-ptrace-fix-NULL-pointer-access-problem.patch new file mode 100644 index 0000000..1038db5 --- /dev/null +++ b/0015-ptrace-fix-NULL-pointer-access-problem.patch @@ -0,0 +1,39 @@ +From a45b9424cb7258c00211115191f74fbaf8f74285 Mon Sep 17 00:00:00 2001 +From: wangcichen +Date: Mon, 23 May 2022 10:18:57 +0800 +Subject: [PATCH 2/5] ptrace: fix NULL pointer access problem + +--- + src/arch/aarch64/arch_ptrace.c | 2 -- + src/arch/x86/arch_ptrace.c | 2 -- + 2 files changed, 4 deletions(-) + +diff --git a/src/arch/aarch64/arch_ptrace.c b/src/arch/aarch64/arch_ptrace.c +index 774dc21..2227e95 100644 +--- a/src/arch/aarch64/arch_ptrace.c ++++ b/src/arch/aarch64/arch_ptrace.c +@@ -465,8 +465,6 @@ kpatch_arch_ptrace_waitpid(kpatch_process_t *proc, + + /* TODO: fix the latter by SINGLESTEPping such a thread with + * the original instruction in place */ +- kperr("the thread ran out: %d, pc= %llx, expected = %lx\n", pid, +- regs.pc, pctx->execute_until); + errno = ESRCH; + return -1; + } +diff --git a/src/arch/x86/arch_ptrace.c b/src/arch/x86/arch_ptrace.c +index 9069484..9dede71 100644 +--- a/src/arch/x86/arch_ptrace.c ++++ b/src/arch/x86/arch_ptrace.c +@@ -492,8 +492,6 @@ int kpatch_arch_ptrace_waitpid(kpatch_process_t *proc, + + /* TODO: fix the latter by SINGLESTEPping such a thread with + * the original instruction in place */ +- kperr("the thread ran out: %d, rip = %llx, expected = %lx\n", pid, +- regs.rip, pctx->execute_until); + errno = ESRCH; + return -1; + } +-- +2.27.0 + diff --git a/0016-fix-patched-process-crashing-when-acccess-the-global.patch b/0016-fix-patched-process-crashing-when-acccess-the-global.patch new file mode 100644 index 0000000..3834903 --- /dev/null +++ b/0016-fix-patched-process-crashing-when-acccess-the-global.patch @@ -0,0 +1,156 @@ +From add4a57f47eb89acf4a471253654cc806aedaaf8 Mon Sep 17 00:00:00 2001 +From: ctyunsystem +Date: Wed, 11 May 2022 10:20:26 +0800 +Subject: [PATCH 3/5] fix patched process crashing when acccess the global var + which newly added + +--- + src/kpatch_gensrc.c | 20 +++++++++++++++++--- + src/kpatch_patch.c | 6 +++--- + tests/new_var/Makefile | 2 ++ + tests/new_var/desc | 1 + + tests/new_var/new_var.c | 23 +++++++++++++++++++++++ + tests/new_var/new_var.diff | 15 +++++++++++++++ + 6 files changed, 61 insertions(+), 6 deletions(-) + create mode 100644 tests/new_var/Makefile + create mode 100644 tests/new_var/desc + create mode 100644 tests/new_var/new_var.c + create mode 100644 tests/new_var/new_var.diff + +diff --git a/src/kpatch_gensrc.c b/src/kpatch_gensrc.c +index bf1832a..67254d7 100644 +--- a/src/kpatch_gensrc.c ++++ b/src/kpatch_gensrc.c +@@ -432,6 +432,20 @@ out: + + /* ------------------------------------------ helpers -------------------------------------------- */ + ++static inline int page_shift(int n) { ++ int res = -1; ++ ++ while(n) { ++ res++; ++ n >>= 1; ++ } ++ ++ return res; ++} ++ ++#define PAGE_SIZE getpagesize() ++#define PAGE_SHIFT page_shift(PAGE_SIZE) ++ + static void change_section(struct kp_file *fout, struct section_desc *sect, int flags) + { + static int init_data_section = 0; +@@ -448,15 +462,15 @@ static void change_section(struct kp_file *fout, struct section_desc *sect, int + s = ".kpatch.text,\"ax\",@progbits"; + else { + s = ".kpatch.data,\"aw\",@progbits"; +- if (!init_data_section && (flags & FLAG_PUSH_SECTION)) { ++ if (!init_data_section) { + init_data_section = 1; +- align = ".p2align\t12"; ++ align = ".p2align"; + } + } + + fprintf(fout->f, "\t.%ssection %s\n", (flags & FLAG_PUSH_SECTION) ? "push" : "", s); + if (align) +- fprintf(fout->f, "\t%s\n", align); ++ fprintf(fout->f, "\t%s\t%d\n", align, PAGE_SHIFT); + } + + void get_comm_args(struct kp_file *f, int l, kpstr_t *xname, int *sz, int *align) +diff --git a/src/kpatch_patch.c b/src/kpatch_patch.c +index d74299d..3b53a5a 100644 +--- a/src/kpatch_patch.c ++++ b/src/kpatch_patch.c +@@ -372,9 +372,9 @@ object_apply_patch(struct object_file *o) + kp->jmp_offset = sz; + kpdebug("Jump table %d bytes for %d syms at offset 0x%x\n", + o->jmp_table->size, undef, kp->jmp_offset); +- sz = ROUND_UP(sz + o->jmp_table->size, 4096); ++ sz = ROUND_UP(sz + o->jmp_table->size, PAGE_SIZE); + } +- sz = ROUND_UP(sz, 4096); ++ sz = ROUND_UP(sz, PAGE_SIZE); + + /* kpatch elf */ + kp->elf_offset = sz; +@@ -386,7 +386,7 @@ object_apply_patch(struct object_file *o) + kp->user_undo = sz; + sz = ROUND_UP(sz + HUNK_SIZE * o->ninfo, 16); + +- sz = ROUND_UP(sz, 4096); ++ sz = ROUND_UP(sz, PAGE_SIZE); + kp->kpatch_total_mem_sz = sz; + + /* +diff --git a/tests/new_var/Makefile b/tests/new_var/Makefile +new file mode 100644 +index 0000000..6dd4b69 +--- /dev/null ++++ b/tests/new_var/Makefile +@@ -0,0 +1,2 @@ ++ ++include ../makefile.inc +diff --git a/tests/new_var/desc b/tests/new_var/desc +new file mode 100644 +index 0000000..4f8cd31 +--- /dev/null ++++ b/tests/new_var/desc +@@ -0,0 +1 @@ ++patch adds a new var +diff --git a/tests/new_var/new_var.c b/tests/new_var/new_var.c +new file mode 100644 +index 0000000..3ed116a +--- /dev/null ++++ b/tests/new_var/new_var.c +@@ -0,0 +1,23 @@ ++#include ++#include ++ ++void print_greetings_patched(int var) ++{ ++ printf("Hello. This is a PATCHED version\n"); ++ printf("Hello. \n", var); ++} ++ ++void print_greetings(void) ++{ ++ printf("Hello. This is an UNPATCHED version\n"); ++} ++ ++int main() ++{ ++ while (1) { ++ print_greetings(); ++ sleep(1); ++ } ++ ++ return 0; ++} +diff --git a/tests/new_var/new_var.diff b/tests/new_var/new_var.diff +new file mode 100644 +index 0000000..c617535 +--- /dev/null ++++ b/tests/new_var/new_var.diff +@@ -0,0 +1,15 @@ ++--- ./new_var.c 2022-02-10 19:40:17.948981115 +0800 +++++ ./new_var.c 2022-02-10 20:02:38.774536002 +0800 ++@@ -7,9 +7,11 @@ ++ printf("Hello. \n", var); ++ } ++ +++int newly_added_var = 0x20220210; ++ void print_greetings(void) ++ { ++- printf("Hello. This is an UNPATCHED version\n"); +++ newly_added_var = 0x2022 << 16 | 0x2202; +++ print_greetings_patched(newly_added_var); ++ } ++ ++ int main() +-- +2.27.0 + diff --git a/0017-fix-probably-restore-cc-symbol-link-fail-when-kill-p.patch b/0017-fix-probably-restore-cc-symbol-link-fail-when-kill-p.patch new file mode 100644 index 0000000..6147dfc --- /dev/null +++ b/0017-fix-probably-restore-cc-symbol-link-fail-when-kill-p.patch @@ -0,0 +1,100 @@ +From c4f9d59c62454d255af4a5c3933eebf6942dbd99 Mon Sep 17 00:00:00 2001 +From: ctyunsystem +Date: Wed, 11 May 2022 10:32:45 +0800 +Subject: [PATCH 4/5] fix probably restore cc symbol link fail when kill patch + building uncourteous + +--- + src/libcare-patch-make | 45 ++++-------------------------------------- + 1 file changed, 4 insertions(+), 41 deletions(-) + +diff --git a/src/libcare-patch-make b/src/libcare-patch-make +index 03aa1d6..41e5926 100755 +--- a/src/libcare-patch-make ++++ b/src/libcare-patch-make +@@ -83,32 +83,6 @@ restore_origs() { + + trap "restore_origs" 0 + +-replace_qemu_ld_flags() { +- local qemu_ld_flags_old=$1 +- ret=$(echo $qemu_ld_flags_old | grep "\-Wl,-q") +- if [[ "$ret" == "" ]]; then +- local qemu_ld_flags="${qemu_ld_flags_old} -Wl,-q" +- echo "replace QEMU_LDFLAGS to '${qemu_ld_flags}'" +- sed -i "/^QEMU_LDFLAGS=/c\\${qemu_ld_flags}" config-host.mak +- fi +-} +- +-recover_qemu_ld_flags() { +- local qemu_ld_flags=$1 +- echo "recover QEMU_LDFLAGS to '${qemu_ld_flags}'" +- sed -i "/^QEMU_LDFLAGS=/c\\${qemu_ld_flags}" config-host.mak +-} +- +-replace_cc_symbolink() { +- unlink $SYMBOLINK_CC +- ln -s $LIBCARE_CC $SYMBOLINK_CC +-} +- +-recover_cc_symbolink() { +- unlink $SYMBOLINK_CC +- ln -s $REAL_CC $SYMBOLINK_CC +-} +- + build_objects() { + restore_origs + +@@ -124,7 +98,8 @@ build_objects() { + export KPCC_DBGFILTER_ARGS="" + + echo "${green}BUILDING ORIGINAL CODE${reset}" +- make $LPMAKEFILE $JOBS_MAKE >$MAKE_OUTPUT 2>&1 ++ local lp_make_env_original="CC=${CC}" ++ make $LPMAKEFILE $JOBS_MAKE ${lp_make_env_original} >$MAKE_OUTPUT 2>&1 + + echo "${green}INSTALLING ORIGINAL OBJECTS INTO $LPMAKE_ORIGINAL_DIR${reset}" + make $LPMAKEFILE $JOBS_MAKE install \ +@@ -149,20 +124,14 @@ build_objects() { + export KPATCH_STAGE=patched + export KPCC_APPEND_ARGS="-Wl,-q" + +- qemu_ld_flags_bak=$(grep "^QEMU_LDFLAGS=" config-host.mak) +- #add '-Wl,-q' to LD_FLAGS +- replace_qemu_ld_flags "$qemu_ld_flags_bak" +- + echo "${green}BUILDING PATCHED CODE${reset}" +- make $LPMAKEFILE $JOBS_MAKE >$MAKE_OUTPUT 2>&1 ++ local lp_make_env_patched="CC=${CC}" ++ make $LPMAKEFILE $JOBS_MAKE ${lp_make_env_patched} >$MAKE_OUTPUT 2>&1 + + echo "${green}INSTALLING PATCHED OBJECTS INTO $LPMAKE_PATCHED_DIR${reset}" + make $LPMAKEFILE $JOBS_MAKE install \ + "$destdir=$LPMAKE_PATCHED_DIR" \ + >$MAKE_OUTPUT 2>&1 +- +- # recover LD_FLAGS +- recover_qemu_ld_flags "$qemu_ld_flags_bak" + } + + build_kpatches() { +@@ -274,16 +243,10 @@ main() { + + prepare_env + +- # replace cc +- replace_cc_symbolink +- + if test -z "$only_update"; then + build_objects "$@" + fi + build_kpatches +- +- # recover cc +- recover_cc_symbolink + } + + main "$@" +-- +2.27.0 + diff --git a/0018-optimize-Remove-unnecessary-comparison-code.patch b/0018-optimize-Remove-unnecessary-comparison-code.patch new file mode 100644 index 0000000..2747e11 --- /dev/null +++ b/0018-optimize-Remove-unnecessary-comparison-code.patch @@ -0,0 +1,39 @@ +From 5667441f87ef702ed537aba7c677eee1b36f1ead Mon Sep 17 00:00:00 2001 +From: wangcichen +Date: Fri, 27 May 2022 17:08:28 +0800 +Subject: [PATCH 5/5] optimize: Remove unnecessary comparison code + +--- + src/arch/aarch64/arch_elf.c | 2 +- + src/arch/x86/arch_elf.c | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/arch/aarch64/arch_elf.c b/src/arch/aarch64/arch_elf.c +index 9ce586d..10399ee 100644 +--- a/src/arch/aarch64/arch_elf.c ++++ b/src/arch/aarch64/arch_elf.c +@@ -202,7 +202,7 @@ int kpatch_arch_apply_relocate_add(struct object_file *o, GElf_Shdr *relsec) + unsigned long val; + void *loc, *loc2; + +- if (r->r_offset < 0 || r->r_offset >= tshdr->sh_size) { ++ if (r->r_offset >= tshdr->sh_size) { + kperr("Relocation offset for section '%s'" + " is at 0x%lx beyond the section size 0x%lx\n", + scnname, r->r_offset, tshdr->sh_size); +diff --git a/src/arch/x86/arch_elf.c b/src/arch/x86/arch_elf.c +index 265fd37..f79a996 100644 +--- a/src/arch/x86/arch_elf.c ++++ b/src/arch/x86/arch_elf.c +@@ -56,7 +56,7 @@ int kpatch_arch_apply_relocate_add(struct object_file *o, GElf_Shdr *relsec) + unsigned long val; + void *loc, *loc2; + +- if (r->r_offset < 0 || r->r_offset >= tshdr->sh_size) { ++ if (r->r_offset >= tshdr->sh_size) { + kperr("Relocation offset for section '%s'" + " is at 0x%lx beyond the section size 0x%lx\n", + scnname, r->r_offset, tshdr->sh_size); +-- +2.27.0 + diff --git a/0019-Revert-fix-probably-restore-cc-symbol-link-fail-when.patch b/0019-Revert-fix-probably-restore-cc-symbol-link-fail-when.patch new file mode 100644 index 0000000..4788049 --- /dev/null +++ b/0019-Revert-fix-probably-restore-cc-symbol-link-fail-when.patch @@ -0,0 +1,101 @@ +From d86044aa709617186fa4eeb2dff9540395f77c8e Mon Sep 17 00:00:00 2001 +From: ctyunsystem +Date: Tue, 5 Jul 2022 10:13:15 +0800 +Subject: [PATCH 1/2] Revert "fix probably restore cc symbol link fail when + kill patch building uncourteous" ==> Revert "libcare-patch-make: fix some + bugs" + +--- + src/libcare-patch-make | 45 ++++++++++++++++++++++++++++++++++++++---- + 1 file changed, 41 insertions(+), 4 deletions(-) + +diff --git a/src/libcare-patch-make b/src/libcare-patch-make +index 41e5926..03aa1d6 100755 +--- a/src/libcare-patch-make ++++ b/src/libcare-patch-make +@@ -83,6 +83,32 @@ restore_origs() { + + trap "restore_origs" 0 + ++replace_qemu_ld_flags() { ++ local qemu_ld_flags_old=$1 ++ ret=$(echo $qemu_ld_flags_old | grep "\-Wl,-q") ++ if [[ "$ret" == "" ]]; then ++ local qemu_ld_flags="${qemu_ld_flags_old} -Wl,-q" ++ echo "replace QEMU_LDFLAGS to '${qemu_ld_flags}'" ++ sed -i "/^QEMU_LDFLAGS=/c\\${qemu_ld_flags}" config-host.mak ++ fi ++} ++ ++recover_qemu_ld_flags() { ++ local qemu_ld_flags=$1 ++ echo "recover QEMU_LDFLAGS to '${qemu_ld_flags}'" ++ sed -i "/^QEMU_LDFLAGS=/c\\${qemu_ld_flags}" config-host.mak ++} ++ ++replace_cc_symbolink() { ++ unlink $SYMBOLINK_CC ++ ln -s $LIBCARE_CC $SYMBOLINK_CC ++} ++ ++recover_cc_symbolink() { ++ unlink $SYMBOLINK_CC ++ ln -s $REAL_CC $SYMBOLINK_CC ++} ++ + build_objects() { + restore_origs + +@@ -98,8 +124,7 @@ build_objects() { + export KPCC_DBGFILTER_ARGS="" + + echo "${green}BUILDING ORIGINAL CODE${reset}" +- local lp_make_env_original="CC=${CC}" +- make $LPMAKEFILE $JOBS_MAKE ${lp_make_env_original} >$MAKE_OUTPUT 2>&1 ++ make $LPMAKEFILE $JOBS_MAKE >$MAKE_OUTPUT 2>&1 + + echo "${green}INSTALLING ORIGINAL OBJECTS INTO $LPMAKE_ORIGINAL_DIR${reset}" + make $LPMAKEFILE $JOBS_MAKE install \ +@@ -124,14 +149,20 @@ build_objects() { + export KPATCH_STAGE=patched + export KPCC_APPEND_ARGS="-Wl,-q" + ++ qemu_ld_flags_bak=$(grep "^QEMU_LDFLAGS=" config-host.mak) ++ #add '-Wl,-q' to LD_FLAGS ++ replace_qemu_ld_flags "$qemu_ld_flags_bak" ++ + echo "${green}BUILDING PATCHED CODE${reset}" +- local lp_make_env_patched="CC=${CC}" +- make $LPMAKEFILE $JOBS_MAKE ${lp_make_env_patched} >$MAKE_OUTPUT 2>&1 ++ make $LPMAKEFILE $JOBS_MAKE >$MAKE_OUTPUT 2>&1 + + echo "${green}INSTALLING PATCHED OBJECTS INTO $LPMAKE_PATCHED_DIR${reset}" + make $LPMAKEFILE $JOBS_MAKE install \ + "$destdir=$LPMAKE_PATCHED_DIR" \ + >$MAKE_OUTPUT 2>&1 ++ ++ # recover LD_FLAGS ++ recover_qemu_ld_flags "$qemu_ld_flags_bak" + } + + build_kpatches() { +@@ -243,10 +274,16 @@ main() { + + prepare_env + ++ # replace cc ++ replace_cc_symbolink ++ + if test -z "$only_update"; then + build_objects "$@" + fi + build_kpatches ++ ++ # recover cc ++ recover_cc_symbolink + } + + main "$@" +-- +2.27.0 + diff --git a/0020-fix-probably-restore-cc-symbol-link-fail-when-kill-p.patch b/0020-fix-probably-restore-cc-symbol-link-fail-when-kill-p.patch new file mode 100644 index 0000000..0465682 --- /dev/null +++ b/0020-fix-probably-restore-cc-symbol-link-fail-when-kill-p.patch @@ -0,0 +1,26 @@ +From 96362b54e9c2162fe10fd1cfe029bcc8e203b135 Mon Sep 17 00:00:00 2001 +From: ctyunsystem +Date: Tue, 5 Jul 2022 10:13:58 +0800 +Subject: [PATCH 2/2] fix probably restore cc symbol link fail when kill patch + building uncourteous + +--- + src/libcare-patch-make | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/src/libcare-patch-make b/src/libcare-patch-make +index 03aa1d6..3cd2fe9 100755 +--- a/src/libcare-patch-make ++++ b/src/libcare-patch-make +@@ -109,6 +109,8 @@ recover_cc_symbolink() { + ln -s $REAL_CC $SYMBOLINK_CC + } + ++trap "recover_cc_symbolink" SIGINT SIGTERM SIGQUIT ++ + build_objects() { + restore_origs + +-- +2.27.0 + diff --git a/libcareplus.spec b/libcareplus.spec index b0eba83..f4c4bef 100644 --- a/libcareplus.spec +++ b/libcareplus.spec @@ -3,26 +3,33 @@ Version: 1.0.0 Name: libcareplus Summary: LibcarePlus tools -Release: 11 +Release: 12 Group: Applications/System License: GPLv2 Url: https://gitee.com/openeuler/libcareplus Source0: %{name}-%{version}.tar.gz -Patch0001: fix-cblock-parse-for-LCOLD-LHOT-.cold.NUM-.init_arra.patch -Patch0002: gensrc-we-should-add-align-while-FLAGS_PUSH_SECTION-.patch -Patch0003: elf-add-section-adderss-for-STT_NOTYPE-type-of-symbo.patch -Patch0004: elf-strip-adapt-to-new-gcc-version-10.3.1.patch -Patch0005: gitignore-ignore-some-tests-and-binary.patch -Patch0006: libcare-patch-make-adapt-libcare-patch-make-to-meson.patch -Patch0007: kpatch_elf-compatible-with-older-versions-of-the-so-.patch -Patch0008: kpatch_parse-fix-failed-to-recognize-.cold.patch -Patch0009: help-modify-some-help-information.patch -Patch0010: libcare-patch-make-fix-some-bugs.patch -Patch0011: selinux-enable-libcare-ctl-to-mprotect-qemu-process.patch -Patch0012: libcare-dump-change-the-return-value.patch -Patch0013: gensrc-skip-vector-instruction-in-str_do_gotpcrel.patch -Patch0014: modify-pkgbuild-to-make-kpatch-for-RPM-based-packages.patch +Patch0000: 0000-gensrc-skip-vector-instruction-in-str_do_gotpcrel.patch +Patch0001: 0001-gensrc-we-should-add-align-while-FLAGS_PUSH_SECTION-.patch +Patch0002: 0002-fix-cblock-parse-for-LCOLD-LHOT-.cold.NUM-.init_arra.patch +Patch0003: 0003-elf-add-section-adderss-for-STT_NOTYPE-type-of-symbo.patch +Patch0004: 0004-elf-strip-adapt-to-new-gcc-version-10.3.1.patch +Patch0005: 0005-gitignore-ignore-some-tests-and-binary.patch +Patch0006: 0006-libcare-patch-make-adapt-libcare-patch-make-to-meson.patch +Patch0007: 0007-kpatch_elf-compatible-with-older-versions-of-the-so-.patch +Patch0008: 0008-kpatch_parse-fix-failed-to-recognize-.cold.patch +Patch0009: 0009-help-modify-some-help-information.patch +Patch0010: 0010-libcare-patch-make-fix-some-bugs.patch +Patch0011: 0011-selinux-enable-libcare-ctl-to-mprotect-qemu-process.patch +Patch0012: 0012-libcare-dump-change-the-return-value.patch +Patch0013: 0013-modify-pkgbuild-to-make-kpatch-for-RPM-based-packages.patch +Patch0014: 0014-kpatch_process-fix-possible-double-free.patch +Patch0015: 0015-ptrace-fix-NULL-pointer-access-problem.patch +Patch0016: 0016-fix-patched-process-crashing-when-acccess-the-global.patch +Patch0017: 0017-fix-probably-restore-cc-symbol-link-fail-when-kill-p.patch +Patch0018: 0018-optimize-Remove-unnecessary-comparison-code.patch +Patch0019: 0019-Revert-fix-probably-restore-cc-symbol-link-fail-when.patch +Patch0020: 0020-fix-probably-restore-cc-symbol-link-fail-when-kill-p.patch BuildRequires: elfutils-libelf-devel libunwind-devel gcc systemd @@ -160,6 +167,13 @@ exit 0 %endif %changelog +* Wed Jun 15 2022 yezengruan 1.0.0-12 +- kpatch_process: fix possible double free. +- ptrace: fix NULL pointer access problem +- fix patched process crashing when acccess the global var +- fix probably restore cc symbol link fail when kill patch building uncourteous +- optimize: Remove unnecessary comparison code + * Wed May 11 2022 Cichen Wang 1.0.0-11 - modify scripts/pkgbuild to make kpatch'es for the RPM-based packages