diff --git a/0001-support-compile-kpatch-on-aarch64.patch b/0001-support-compile-kpatch-on-aarch64.patch index ae5e4e88946e561f2ee73810f81cdcd4b751c7c7..2df9a326d7386506c122404ceb699ec2a311ec79 100644 --- a/0001-support-compile-kpatch-on-aarch64.patch +++ b/0001-support-compile-kpatch-on-aarch64.patch @@ -1,7 +1,7 @@ -From 1281e03a115ee04e8ddea9f88d0e4e16b2e5ce57 Mon Sep 17 00:00:00 2001 +From 0de9a5da0cc278973caabfb9929dc58514c73639 Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Thu, 20 Dec 2018 04:55:38 +0000 -Subject: [PATCH 01/21] support compile kpatch on aarch64 +Subject: [PATCH 01/23] support compile kpatch on aarch64 delete __x86_64__ to support compile kpatch on aarch64. @@ -109,3 +109,4 @@ index aedd07d..2707cdb 100644 .name = "__ftr_fixup", -- 2.18.1 + diff --git a/0002-kpatch-build-support-build-patch-for-aarch64.patch b/0002-kpatch-build-support-build-patch-for-aarch64.patch index 0e986dd2089ce17a7334c25dfc67f376f25f92e1..9e9d0ed05f301d699e1359c10e53442a133e20c7 100644 --- a/0002-kpatch-build-support-build-patch-for-aarch64.patch +++ b/0002-kpatch-build-support-build-patch-for-aarch64.patch @@ -1,7 +1,7 @@ -From 92bb331ce71cfc33d933ebeabdbe9b5721c0ec75 Mon Sep 17 00:00:00 2001 +From d3665b019100715e41b75493d31d51d602ca056a Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Wed, 26 Feb 2020 07:09:50 -0500 -Subject: [PATCH 02/21] kpatch-build: support build patch for aarch64 +Subject: [PATCH 02/23] kpatch-build: support build patch for aarch64 use R_AARCH64_ABS64 for aarch64 @@ -16,17 +16,17 @@ support cross compile for aarch64 Signed-off-by: Zhipeng Xie --- - kpatch-build/create-diff-object.c | 191 +++++++++++++++++++++++++--- - kpatch-build/create-kpatch-module.c | 24 +++- - kpatch-build/kpatch-build | 116 ++++++++++++++++- + kpatch-build/create-diff-object.c | 276 ++++++++++++++++++++++------ + kpatch-build/create-kpatch-module.c | 25 ++- + kpatch-build/kpatch-build | 116 +++++++++++- kpatch-build/kpatch-gcc | 4 +- - 4 files changed, 306 insertions(+), 29 deletions(-) + 4 files changed, 352 insertions(+), 69 deletions(-) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c -index 2707cdb..7a27b58 100644 +index 2707cdb..b161fee 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c -@@ -76,6 +76,31 @@ enum subsection { +@@ -76,6 +76,32 @@ enum subsection { enum loglevel loglevel = NORMAL; @@ -50,6 +50,7 @@ index 2707cdb..7a27b58 100644 +static unsigned int arch_of_elf(Elf *elf) +{ + GElf_Ehdr eh; ++ + if (!gelf_getehdr(elf, &eh)) + ERROR("gelf_getehdr"); + return eh.e_machine; @@ -58,7 +59,7 @@ index 2707cdb..7a27b58 100644 /******************* * Data structures * ****************/ -@@ -652,6 +677,67 @@ static int kpatch_line_macro_change_only(struct section *sec) +@@ -652,6 +678,67 @@ static int kpatch_line_macro_change_only(struct section *sec) return 1; } #endif @@ -126,7 +127,7 @@ index 2707cdb..7a27b58 100644 static void kpatch_compare_sections(struct list_head *seclist) { -@@ -667,7 +753,16 @@ static void kpatch_compare_sections(struct list_head *seclist) +@@ -667,7 +754,16 @@ static void kpatch_compare_sections(struct list_head *seclist) /* exclude WARN-only, might_sleep changes */ list_for_each_entry(sec, seclist, list) { @@ -144,7 +145,7 @@ index 2707cdb..7a27b58 100644 log_debug("reverting macro / line number section %s status to SAME\n", sec->name); sec->status = SAME; -@@ -727,6 +822,8 @@ static void kpatch_compare_correlated_symbol(struct symbol *sym) +@@ -727,6 +823,8 @@ static void kpatch_compare_correlated_symbol(struct symbol *sym) if ((sym2->sec->twin && sym2->sec->twin->ignore) || kpatch_subsection_changed(sym1->sec, sym2->sec)) sym->status = CHANGED; @@ -153,27 +154,45 @@ index 2707cdb..7a27b58 100644 else DIFF_FATAL("symbol changed sections: %s", sym1->name); } -@@ -1302,9 +1399,8 @@ static void kpatch_replace_sections_syms(struct kpatch_elf *kelf) +@@ -1302,22 +1400,22 @@ static void kpatch_replace_sections_syms(struct kpatch_elf *kelf) continue; } -#ifdef __powerpc64__ add_off = 0; -#else -+ if (arch == EM_X86_64) { - if (rela->type == R_X86_64_PC32 || - rela->type == R_X86_64_PLT32) { - struct insn insn; -@@ -1317,7 +1413,7 @@ static void kpatch_replace_sections_syms(struct kpatch_elf *kelf) - add_off = 0; - else - continue; +- if (rela->type == R_X86_64_PC32 || +- rela->type == R_X86_64_PLT32) { +- struct insn insn; +- rela_insn(sec, rela, &insn); +- add_off = (unsigned int)((long)insn.next_byte - +- (long)sec->base->data->d_buf - +- rela->offset); +- } else if (rela->type == R_X86_64_64 || +- rela->type == R_X86_64_32S) +- add_off = 0; +- else +- continue; -#endif ++ if (arch == EM_X86_64) { ++ if (rela->type == R_X86_64_PC32 || ++ rela->type == R_X86_64_PLT32) { ++ struct insn insn; ++ ++ rela_insn(sec, rela, &insn); ++ add_off = (unsigned int)((long)insn.next_byte - ++ (long)sec->base->data->d_buf - ++ rela->offset); ++ } else if (rela->type == R_X86_64_64 || ++ rela->type == R_X86_64_32S) ++ add_off = 0; ++ else ++ continue; + } /* * Attempt to replace references to unbundled sections -@@ -2415,7 +2511,7 @@ static void kpatch_create_kpatch_arch_section(struct kpatch_elf *kelf, char *obj +@@ -2415,7 +2513,7 @@ static void kpatch_create_kpatch_arch_section(struct kpatch_elf *kelf, char *obj /* entries[index].sec */ ALLOC_LINK(rela, &karch_sec->rela->relas); rela->sym = sec->secsym; @@ -182,7 +201,7 @@ index 2707cdb..7a27b58 100644 rela->addend = 0; rela->offset = (unsigned int)(index * sizeof(struct kpatch_arch) + \ offsetof(struct kpatch_arch, sec)); -@@ -2423,7 +2519,7 @@ static void kpatch_create_kpatch_arch_section(struct kpatch_elf *kelf, char *obj +@@ -2423,7 +2521,7 @@ static void kpatch_create_kpatch_arch_section(struct kpatch_elf *kelf, char *obj /* entries[index].objname */ ALLOC_LINK(rela, &karch_sec->rela->relas); rela->sym = strsym; @@ -191,7 +210,7 @@ index 2707cdb..7a27b58 100644 rela->addend = offset_of_string(&kelf->strings, objname); rela->offset = (unsigned int)(index * sizeof(struct kpatch_arch) + \ offsetof(struct kpatch_arch, objname)); -@@ -2622,7 +2718,7 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf, +@@ -2622,7 +2720,7 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf, */ ALLOC_LINK(rela, &relasec->relas); rela->sym = sym; @@ -200,7 +219,7 @@ index 2707cdb..7a27b58 100644 rela->addend = 0; rela->offset = (unsigned int)(index * sizeof(*funcs)); -@@ -2632,7 +2728,7 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf, +@@ -2632,7 +2730,7 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf, */ ALLOC_LINK(rela, &relasec->relas); rela->sym = strsym; @@ -209,7 +228,7 @@ index 2707cdb..7a27b58 100644 rela->addend = offset_of_string(&kelf->strings, sym->name); rela->offset = (unsigned int)(index * sizeof(*funcs) + offsetof(struct kpatch_patch_func, name)); -@@ -2643,7 +2739,7 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf, +@@ -2643,7 +2741,7 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf, */ ALLOC_LINK(rela, &relasec->relas); rela->sym = strsym; @@ -218,7 +237,7 @@ index 2707cdb..7a27b58 100644 rela->addend = objname_offset; rela->offset = (unsigned int)(index * sizeof(*funcs) + offsetof(struct kpatch_patch_func,objname)); -@@ -2701,7 +2797,10 @@ static int function_ptr_rela(const struct rela *rela) +@@ -2701,7 +2799,10 @@ static int function_ptr_rela(const struct rela *rela) rela_toc->addend == (int)rela_toc->sym->sym.st_value && (rela->type == R_X86_64_32S || rela->type == R_PPC64_TOC16_HA || @@ -230,7 +249,7 @@ index 2707cdb..7a27b58 100644 } static int may_need_dynrela(const struct rela *rela) -@@ -2955,7 +3054,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, +@@ -2955,7 +3056,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, /* add rela to fill in ksyms[index].name field */ ALLOC_LINK(rela2, &ksym_sec->rela->relas); rela2->sym = strsym; @@ -239,7 +258,7 @@ index 2707cdb..7a27b58 100644 rela2->addend = offset_of_string(&kelf->strings, rela->sym->name); rela2->offset = (unsigned int)(index * sizeof(*ksyms) + \ offsetof(struct kpatch_symbol, name)); -@@ -2963,7 +3062,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, +@@ -2963,7 +3064,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, /* add rela to fill in ksyms[index].objname field */ ALLOC_LINK(rela2, &ksym_sec->rela->relas); rela2->sym = strsym; @@ -248,7 +267,7 @@ index 2707cdb..7a27b58 100644 rela2->addend = offset_of_string(&kelf->strings, sym_objname); rela2->offset = (unsigned int)(index * sizeof(*ksyms) + \ offsetof(struct kpatch_symbol, objname)); -@@ -2984,7 +3083,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, +@@ -2984,7 +3085,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, ERROR("can't create dynrela for section %s (symbol %s): no bundled or section symbol", sec->name, rela->sym->name); @@ -257,7 +276,7 @@ index 2707cdb..7a27b58 100644 rela2->addend = rela->offset; rela2->offset = (unsigned int)(index * sizeof(*krelas) + \ offsetof(struct kpatch_relocation, dest)); -@@ -2992,7 +3091,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, +@@ -2992,7 +3093,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, /* add rela to fill in krelas[index].objname field */ ALLOC_LINK(rela2, &krela_sec->rela->relas); rela2->sym = strsym; @@ -266,7 +285,7 @@ index 2707cdb..7a27b58 100644 rela2->addend = offset_of_string(&kelf->strings, objname); rela2->offset = (unsigned int)(index * sizeof(*krelas) + \ offsetof(struct kpatch_relocation, objname)); -@@ -3000,7 +3099,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, +@@ -3000,7 +3101,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, /* add rela to fill in krelas[index].ksym field */ ALLOC_LINK(rela2, &krela_sec->rela->relas); rela2->sym = ksym_sec_sym; @@ -275,7 +294,7 @@ index 2707cdb..7a27b58 100644 rela2->addend = (unsigned int)(index * sizeof(*ksyms)); rela2->offset = (unsigned int)(index * sizeof(*krelas) + \ offsetof(struct kpatch_relocation, ksym)); -@@ -3063,7 +3162,7 @@ static void kpatch_create_callbacks_objname_rela(struct kpatch_elf *kelf, char * +@@ -3063,7 +3164,7 @@ static void kpatch_create_callbacks_objname_rela(struct kpatch_elf *kelf, char * if (!strcmp(callbackp->name, sec->name)) { ALLOC_LINK(rela, &sec->relas); rela->sym = strsym; @@ -284,24 +303,73 @@ index 2707cdb..7a27b58 100644 rela->addend = objname_offset; rela->offset = callbackp->offset; break; -@@ -3116,6 +3215,7 @@ static void kpatch_create_mcount_sections(struct kpatch_elf *kelf) +@@ -3116,40 +3215,79 @@ static void kpatch_create_mcount_sections(struct kpatch_elf *kelf) /* add rela in .rela__mcount_loc to fill in function pointer */ ALLOC_LINK(rela, &relasec->relas); rela->sym = sym; +- rela->type = R_X86_64_64; +- rela->addend = 0; +- rela->offset = (unsigned int)(index * sizeof(void*)); + if (arch == EM_X86_64) { - rela->type = R_X86_64_64; - rela->addend = 0; - rela->offset = (unsigned int)(index * sizeof(void*)); -@@ -3151,6 +3251,40 @@ static void kpatch_create_mcount_sections(struct kpatch_elf *kelf) ++ rela->type = R_X86_64_64; ++ rela->addend = 0; ++ rela->offset = (unsigned int)(index * sizeof(void *)); + +- /* +- * Modify the first instruction of the function to "callq +- * __fentry__" so that ftrace will be happy. +- */ +- newdata = malloc(sym->sec->data->d_size); +- if (!newdata) +- ERROR("malloc"); ++ /* ++ * Modify the first instruction of the function to "callq ++ * __fentry__" so that ftrace will be happy. ++ */ ++ newdata = malloc(sym->sec->data->d_size); ++ if (!newdata) ++ ERROR("malloc"); - rela->type = R_X86_64_PC32; - } +- memcpy(newdata, sym->sec->data->d_buf, sym->sec->data->d_size); +- sym->sec->data->d_buf = newdata; +- insn = newdata; ++ memcpy(newdata, sym->sec->data->d_buf, sym->sec->data->d_size); ++ sym->sec->data->d_buf = newdata; ++ insn = newdata; + +- rela = list_first_entry(&sym->sec->rela->relas, struct rela, ++ rela = list_first_entry(&sym->sec->rela->relas, struct rela, + list); + +- /* +- * R_X86_64_NONE is only generated by older versions of kernel/gcc +- * which use the mcount script. +- */ +- if (rela->type == R_X86_64_NONE) { +- if (insn[0] != 0xf) ++ /* ++ * R_X86_64_NONE is only generated by older versions of kernel/gcc ++ * which use the mcount script. ++ */ ++ if (rela->type == R_X86_64_NONE) { ++ if (insn[0] != 0xf) ++ ERROR("%s: unexpected instruction at the start of the function", ++ sym->name); ++ insn[0] = 0xe8; ++ insn[1] = 0; ++ insn[2] = 0; ++ insn[3] = 0; ++ insn[4] = 0; ++ ++ rela->type = R_X86_64_PC32; ++ } + } else if (arch == EM_AARCH64) { + unsigned int *insnp; ++ + rela->type = R_AARCH64_ABS64; + /* bl <__fentry__> is the second insn */ + rela->addend = 4; -+ rela->offset = (unsigned int)(index * sizeof(void*)); ++ rela->offset = (unsigned int)(index * sizeof(void *)); + + newdata = malloc(sym->sec->data->d_size); + if (!newdata) @@ -313,11 +381,22 @@ index 2707cdb..7a27b58 100644 + + /* + * mov x9, x30 -+ * nop //function in .text., so it be replaced with nop by recordmcount -+ * mov x30, x9 ++ * nop //function in .text., so it be replaced with nop by ++ * recordmcount ++ * ++ * mov x30, x9 + */ -+ if (insnp[0] != 0xaa1e03e9 || insnp[1] != 0xd503201f || insnp[2] != 0xaa0903fe) -+ ERROR("%s: unexpected instruction at the start of the function", ++ if (insnp[0] != 0xaa1e03e9 || insnp[1] != 0xd503201f ++ || insnp[2] != 0xaa0903fe) + ERROR("%s: unexpected instruction at the start of the function", +- sym->name); +- insn[0] = 0xe8; +- insn[1] = 0; +- insn[2] = 0; +- insn[3] = 0; +- insn[4] = 0; +- +- rela->type = R_X86_64_PC32; + sym->name); + + /* change the nop to bl __fentry__ */ @@ -329,11 +408,10 @@ index 2707cdb..7a27b58 100644 + + } else { + ERROR("unsupport arch %d\n", arch); -+ } + } index++; - } -@@ -3349,6 +3483,8 @@ int main(int argc, char *argv[]) +@@ -3349,6 +3489,8 @@ int main(int argc, char *argv[]) char *hint = NULL, *orig_obj, *patched_obj, *parent_name; char *parent_symtab, *mod_symvers, *patch_name, *output_obj; struct sym_compare_type *base_locals, *sym_comp; @@ -342,7 +420,7 @@ index 2707cdb..7a27b58 100644 arguments.debug = 0; argp_parse (&argp, argc, argv, 0, NULL, &arguments); -@@ -3369,6 +3505,13 @@ int main(int argc, char *argv[]) +@@ -3369,6 +3511,13 @@ int main(int argc, char *argv[]) kelf_base = kpatch_elf_open(orig_obj); kelf_patched = kpatch_elf_open(patched_obj); @@ -356,7 +434,7 @@ index 2707cdb..7a27b58 100644 kpatch_compare_elf_headers(kelf_base->elf, kelf_patched->elf); kpatch_check_program_headers(kelf_base->elf); -@@ -3407,7 +3550,12 @@ int main(int argc, char *argv[]) +@@ -3407,7 +3556,12 @@ int main(int argc, char *argv[]) */ kpatch_mark_ignored_sections(kelf_patched); kpatch_compare_correlated_elements(kelf_patched); @@ -370,7 +448,7 @@ index 2707cdb..7a27b58 100644 kpatch_elf_teardown(kelf_base); kpatch_elf_free(kelf_base); -@@ -3467,7 +3615,14 @@ int main(int argc, char *argv[]) +@@ -3467,7 +3621,13 @@ int main(int argc, char *argv[]) kpatch_create_callbacks_objname_rela(kelf_out, parent_name); kpatch_build_strings_section_data(kelf_out); @@ -378,19 +456,18 @@ index 2707cdb..7a27b58 100644 + gcc_add_option = getenv("GCC_ADD_OPTION"); + if (gcc_add_option) + mlongcall = strstr(gcc_add_option, "-mlong-calls"); -+ if (arch == EM_AARCH64 && mlongcall) { ++ if (arch == EM_AARCH64 && mlongcall) + printf("-mlong-calls found, no need to create mcount section\n"); -+ } else { ++ else + kpatch_create_mcount_sections(kelf_out); -+ } /* * At this point, the set of output sections and symbols is diff --git a/kpatch-build/create-kpatch-module.c b/kpatch-build/create-kpatch-module.c -index 3d197a7..758630b 100644 +index 3d197a7..e8a235d 100644 --- a/kpatch-build/create-kpatch-module.c +++ b/kpatch-build/create-kpatch-module.c -@@ -31,6 +31,17 @@ +@@ -31,6 +31,18 @@ char *childobj; enum loglevel loglevel = NORMAL; @@ -400,6 +477,7 @@ index 3d197a7..758630b 100644 +static unsigned int arch_of_elf(Elf *elf) +{ + GElf_Ehdr eh; ++ + if (!gelf_getehdr(elf, &eh)) + ERROR("gelf_getehdr"); + return eh.e_machine; @@ -408,7 +486,7 @@ index 3d197a7..758630b 100644 /* * Create .kpatch.dynrelas from .kpatch.relocations and .kpatch.symbols sections * -@@ -102,14 +113,14 @@ static void create_dynamic_rela_sections(struct kpatch_elf *kelf, struct section +@@ -102,14 +114,14 @@ static void create_dynamic_rela_sections(struct kpatch_elf *kelf, struct section /* dest */ ALLOC_LINK(rela, &dynsec->rela->relas); rela->sym = sym; @@ -425,7 +503,7 @@ index 3d197a7..758630b 100644 rela->addend = name_offset; rela->offset = (unsigned int)(index * sizeof(*dynrelas) + \ offsetof(struct kpatch_patch_dynrela, name)); -@@ -117,7 +128,7 @@ static void create_dynamic_rela_sections(struct kpatch_elf *kelf, struct section +@@ -117,7 +129,7 @@ static void create_dynamic_rela_sections(struct kpatch_elf *kelf, struct section /* objname */ ALLOC_LINK(rela, &dynsec->rela->relas); rela->sym = strsec->secsym; @@ -434,7 +512,7 @@ index 3d197a7..758630b 100644 rela->addend = objname_offset; rela->offset = (unsigned int)(index * sizeof(*dynrelas) + \ offsetof(struct kpatch_patch_dynrela, objname)); -@@ -200,6 +211,13 @@ int main(int argc, char *argv[]) +@@ -200,6 +212,13 @@ int main(int argc, char *argv[]) childobj = basename(arguments.args[0]); kelf = kpatch_elf_open(arguments.args[0]); @@ -662,4 +740,5 @@ index 9663290..35d7c1c 100755 if [ "$1" = "-o" ]; then obj="$2" -- -2.18.1 \ No newline at end of file +2.18.1 + diff --git a/0003-create-diff-object-new-static-var-should-be-included.patch b/0003-create-diff-object-new-static-var-should-be-included.patch index b4acbec647429d085c2a103cdf857314f2c320f1..b3a8e5fc55cdd9f182dc2fbd24219b0984bd63be 100644 --- a/0003-create-diff-object-new-static-var-should-be-included.patch +++ b/0003-create-diff-object-new-static-var-should-be-included.patch @@ -1,7 +1,7 @@ -From 4511c2f36744529d0298a4d8e56d0b38c2ea5714 Mon Sep 17 00:00:00 2001 +From 232f97ae9acb73ad7bb0b974f6a94ae4c4ca03d9 Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Tue, 25 Feb 2020 22:44:50 -0500 -Subject: [PATCH 03/21] create-diff-object: new static var should be included +Subject: [PATCH 03/23] create-diff-object: new static var should be included Before this patch, only global variables(no referenced) will be included by kpatch-build. But some macros put some static varibles @@ -14,41 +14,43 @@ cause a problem even the new static variables are in unbundled section. Signed-off-by: Zhou Chengming Signed-off-by: Zhipeng Xie --- - kpatch-build/create-diff-object.c | 15 +++++++++++++++ - 1 file changed, 15 insertions(+) + kpatch-build/create-diff-object.c | 16 ++++++++++++++++ + 1 file changed, 16 insertions(+) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c -index 7a27b58..267bd66 100644 +index b161fee..b94060e 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c -@@ -1702,6 +1702,20 @@ static void kpatch_include_force_elements(struct kpatch_elf *kelf) +@@ -1704,6 +1704,21 @@ static void kpatch_include_force_elements(struct kpatch_elf *kelf) sym->include = 0; } +int kpatch_include_new_static_var(struct kpatch_elf *kelf) +{ -+ struct symbol *sym; ++ struct symbol *sym; + -+ list_for_each_entry(sym, &kelf->symbols, list) { -+ if (sym->status == NEW && -+ sym->bind == STB_LOCAL && -+ (sym->type == STT_OBJECT || (sym->type == STT_NOTYPE && sym->name[0] != '$'))) -+ kpatch_include_symbol(sym); -+ } ++ list_for_each_entry(sym, &kelf->symbols, list) { ++ if (sym->status == NEW && ++ sym->bind == STB_LOCAL && ++ (sym->type == STT_OBJECT || ++ (sym->type == STT_NOTYPE && sym->name[0] != '$'))) ++ kpatch_include_symbol(sym); ++ } + -+ return 0; ++ return 0; +} + static int kpatch_include_new_globals(struct kpatch_elf *kelf) { struct symbol *sym; -@@ -3567,6 +3581,7 @@ int main(int argc, char *argv[]) +@@ -3573,6 +3588,7 @@ int main(int argc, char *argv[]) callbacks_exist = kpatch_include_callback_elements(kelf_patched); kpatch_include_force_elements(kelf_patched); new_globals_exist = kpatch_include_new_globals(kelf_patched); -+ kpatch_include_new_static_var(kelf_patched); ++ kpatch_include_new_static_var(kelf_patched); kpatch_include_debug_sections(kelf_patched); kpatch_process_special_sections(kelf_patched); -- 2.18.1 + diff --git a/0004-livepatch-fix-use-THIS-modname-as-the-name-of-ddebug.patch b/0004-livepatch-fix-use-THIS-modname-as-the-name-of-ddebug.patch index ee2db58a1944f24a81bcf3ca05c8d3cfce149b86..4990de1b5fb39e09f7ecbf2a00f3607a37a75da5 100644 --- a/0004-livepatch-fix-use-THIS-modname-as-the-name-of-ddebug.patch +++ b/0004-livepatch-fix-use-THIS-modname-as-the-name-of-ddebug.patch @@ -1,7 +1,7 @@ -From b407defcd16f6a8a49ed0f66d4902eb0bc1b2021 Mon Sep 17 00:00:00 2001 +From 67c3fb57cf0b991c4f70aec78bdf25a47fb590b4 Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Fri, 2 Nov 2018 17:24:42 +0000 -Subject: [PATCH 04/21] livepatch, fix: use THIS modname as the name of +Subject: [PATCH 04/23] livepatch, fix: use THIS modname as the name of ddebug_table We just want a unique name for every module, so put a _ddebug in @@ -16,16 +16,17 @@ Signed-off-by: Zhipeng Xie 1 file changed, 1 insertion(+) diff --git a/kmod/patch/livepatch-patch-hook.c b/kmod/patch/livepatch-patch-hook.c -index e12fd50..613d037 100644 +index e12fd50..6ae40de 100644 --- a/kmod/patch/livepatch-patch-hook.c +++ b/kmod/patch/livepatch-patch-hook.c @@ -473,6 +473,7 @@ out: static void __exit patch_exit(void) { -+ pr_debug("make THIS modname first\n"); ++ pr_debug("make THIS modname first\n"); #ifndef HAVE_SIMPLE_ENABLE WARN_ON(klp_unregister_patch(lpatch)); #endif -- 2.18.1 + diff --git a/0005-create-diff-object-fix-correlate-static-local-variab.patch b/0005-create-diff-object-fix-correlate-static-local-variab.patch index df85099464efc61b591ec0fa6cd2fc3c5b5d1cb4..aceb5befd6256d5de65f369ad2f317cd5246201e 100644 --- a/0005-create-diff-object-fix-correlate-static-local-variab.patch +++ b/0005-create-diff-object-fix-correlate-static-local-variab.patch @@ -1,7 +1,7 @@ -From e3a9643c7fa2ac5f8093c8ac578ce9dfd45084c7 Mon Sep 17 00:00:00 2001 +From 24c01beb0ac8cee521ba654ece6c22f6ce9bdafe Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Fri, 2 Nov 2018 17:24:51 +0000 -Subject: [PATCH 05/21] create-diff-object: fix correlate static local +Subject: [PATCH 05/23] create-diff-object: fix correlate static local variables for __param section kpatch-build correlate fail when no sections reference @@ -31,10 +31,10 @@ Signed-off-by: Zhipeng Xie 1 file changed, 4 insertions(+) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c -index 267bd66..78f5a7e 100644 +index b94060e..3681adb 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c -@@ -1107,6 +1107,10 @@ static int kpatch_is_normal_static_local(struct symbol *sym) +@@ -1108,6 +1108,10 @@ static int kpatch_is_normal_static_local(struct symbol *sym) if (is_special_static(sym)) return 0; @@ -47,3 +47,4 @@ index 267bd66..78f5a7e 100644 -- 2.18.1 + diff --git a/0006-create-diff-object-don-t-create-dynamic-reloc-for-sy.patch b/0006-create-diff-object-don-t-create-dynamic-reloc-for-sy.patch index fd2503b3cd8e11d700a68760162a9cf4b0fab438..828da77e4ae42c4953d5e83e7bd3d37409ac5105 100644 --- a/0006-create-diff-object-don-t-create-dynamic-reloc-for-sy.patch +++ b/0006-create-diff-object-don-t-create-dynamic-reloc-for-sy.patch @@ -1,7 +1,7 @@ -From 28a1433cc6342ee48cfea60b755c0e746b9ff548 Mon Sep 17 00:00:00 2001 +From 30446d9a1a65c8369a54844d471c2aeb4c9139dd Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Fri, 2 Nov 2018 17:24:58 +0000 -Subject: [PATCH 06/21] create-diff-object: don't create dynamic reloc for +Subject: [PATCH 06/23] create-diff-object: don't create dynamic reloc for symbol exported by patch itself when a patch export a new function, ___kcrctab+xxx has a reloc, @@ -13,10 +13,10 @@ Signed-off-by: Zhipeng Xie 1 file changed, 3 insertions(+) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c -index 78f5a7e..2cda233 100644 +index 3681adb..ba2976b 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c -@@ -3053,6 +3053,9 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, +@@ -3056,6 +3056,9 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, if (!strcmp(sym_objname, "vmlinux")) continue; @@ -28,3 +28,4 @@ index 78f5a7e..2cda233 100644 } -- 2.18.1 + diff --git a/0007-create-diff-object-create-dynamic-relocs-for-changed.patch b/0007-create-diff-object-create-dynamic-relocs-for-changed.patch index e0865111c6ce278b0d4adbc5a4f328ab1de0c602..a24b56778d1bbb04e120f611f51847f710bb98b2 100644 --- a/0007-create-diff-object-create-dynamic-relocs-for-changed.patch +++ b/0007-create-diff-object-create-dynamic-relocs-for-changed.patch @@ -1,7 +1,7 @@ -From f6d53ba1e5d1b8c8e026bd537235e201f8482065 Mon Sep 17 00:00:00 2001 +From 66d1b112903b4942cc1033a1be93ae79c1ecf8ef Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Fri, 2 Nov 2018 17:25:38 +0000 -Subject: [PATCH 07/21] create-diff-object: create dynamic relocs for changed +Subject: [PATCH 07/23] create-diff-object: create dynamic relocs for changed functions in this object Currently, we only create dynamic relocs for changed functions of @@ -22,29 +22,29 @@ Signed-off-by: Zhou Chengming Signed-off-by: Li Bin Signed-off-by: Zhipeng Xie --- - kpatch-build/create-diff-object.c | 20 ++++++++++++++++---- - 1 file changed, 16 insertions(+), 4 deletions(-) + kpatch-build/create-diff-object.c | 23 +++++++++++++++++++---- + 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c -index 2cda233..67c062e 100644 +index ba2976b..8ce3b59 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c -@@ -2897,6 +2897,14 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, +@@ -2900,6 +2900,14 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, */ if (may_need_dynrela(rela)) toc_rela(rela)->need_dynrela = 1; + if (rela->sym->sec) { + if (rela->sym->type == STT_FUNC && -+ rela->sym->status == CHANGED && -+ rela->sym->sec != sec->base && -+ sec->base->sym && -+ sec->base->sym->type == STT_FUNC) -+ toc_rela(rela)->need_dynrela = 1; ++ rela->sym->status == CHANGED && ++ rela->sym->sec != sec->base && ++ sec->base->sym && ++ sec->base->sym->type == STT_FUNC) ++ toc_rela(rela)->need_dynrela = 1; + } } } -@@ -2979,10 +2987,14 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, +@@ -2982,10 +2990,17 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, /* An unchanged local symbol */ ret = lookup_local_symbol(table, rela->sym->name, &result); @@ -53,10 +53,13 @@ index 2cda233..67c062e 100644 - rela->sym->name, sec->base->name); - + if (ret) { -+ /* maybe it is a global symbol converted in kpatch_create_patches_sections*/ ++ /* ++ * maybe it is a global symbol converted in ++ * kpatch_create_patches_sections ++ */ + ret = lookup_global_symbol(table, + rela->sym->name, &result); -+ if (ret) ++ if (ret) + ERROR("lookup_local_symbol %s needed for %s", + rela->sym->name, sec->base->name); + } @@ -65,3 +68,4 @@ index 2cda233..67c062e 100644 /* -- 2.18.1 + diff --git a/0008-fix-rodata.str-problem.patch b/0008-fix-rodata.str-problem.patch index 3df94f256e96feb5e66b7c6e727b44ef23cf2353..803c7399adfef5aa0dfaa2283e152a2a06b919a7 100644 --- a/0008-fix-rodata.str-problem.patch +++ b/0008-fix-rodata.str-problem.patch @@ -1,7 +1,7 @@ -From 10370cef2ef3e690355412048d19a88f81fa465b Mon Sep 17 00:00:00 2001 +From 9f30a27617915ee8c59aa43d9165d938129796b3 Mon Sep 17 00:00:00 2001 From: Zhiyu Hu Date: Fri, 28 Dec 2018 07:06:38 +0000 -Subject: [PATCH 08/21] fix rodata.str problem +Subject: [PATCH 08/23] fix rodata.str problem fix some rodata.str problem @@ -11,10 +11,10 @@ Signed-off-by: Zhiyu Hu 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c -index 67c062e..bb2a803 100644 +index 8ce3b59..f37d404 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c -@@ -1632,7 +1632,7 @@ static void kpatch_include_standard_elements(struct kpatch_elf *kelf) +@@ -1634,7 +1634,7 @@ static void kpatch_include_standard_elements(struct kpatch_elf *kelf) !strcmp(sec->name, ".toc") || !strcmp(sec->name, ".rodata") || (!strncmp(sec->name, ".rodata.", 8) && @@ -25,3 +25,4 @@ index 67c062e..bb2a803 100644 } -- 2.18.1 + diff --git a/0009-livepatch-patch-hook-don-t-active-patch-when-insmod.patch b/0009-livepatch-patch-hook-don-t-active-patch-when-insmod.patch index b3e533ece4edcd63a94a21520a691dc69e6438cb..226e691e9ae944c487ade2c02d8790bb11692a77 100644 --- a/0009-livepatch-patch-hook-don-t-active-patch-when-insmod.patch +++ b/0009-livepatch-patch-hook-don-t-active-patch-when-insmod.patch @@ -1,7 +1,7 @@ -From 66b833f4de9dca62b97f077df962c3702c919664 Mon Sep 17 00:00:00 2001 +From 1bc8c76085839576576fc780336fbd9d7ebd29ef Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Tue, 25 Feb 2020 23:40:37 -0500 -Subject: [PATCH 09/21] livepatch-patch-hook: don't active patch when insmod +Subject: [PATCH 09/23] livepatch-patch-hook: don't active patch when insmod Don't active patch after loading the patch when DISABLE_AFTER_LOAD is set. @@ -13,7 +13,7 @@ Signed-off-by: Zhipeng Xie 2 files changed, 6 insertions(+) diff --git a/kmod/patch/livepatch-patch-hook.c b/kmod/patch/livepatch-patch-hook.c -index 613d037..163ae1d 100644 +index 6ae40de..fb23a94 100644 --- a/kmod/patch/livepatch-patch-hook.c +++ b/kmod/patch/livepatch-patch-hook.c @@ -455,6 +455,7 @@ static int __init patch_init(void) @@ -49,3 +49,4 @@ index 17a5e11..894f0ab 100755 if [[ -z "$USERSRCDIR" ]] && [[ "$DISTRO" = ubuntu ]]; then -- 2.18.1 + diff --git a/0010-kpatch-build-enhance-for-out-of-tree-module.patch b/0010-kpatch-build-enhance-for-out-of-tree-module.patch index cc4122e546e1858504bc308e34be755fe44025a6..3c52d528beac2d82d65eafea8d8f052e6919a78a 100644 --- a/0010-kpatch-build-enhance-for-out-of-tree-module.patch +++ b/0010-kpatch-build-enhance-for-out-of-tree-module.patch @@ -1,7 +1,7 @@ -From 8486c25a0b94eb9b415572eec58508204d8e5458 Mon Sep 17 00:00:00 2001 +From a1303033db88fa0036387f3a86f71d162bd5c037 Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Wed, 26 Feb 2020 06:44:06 -0500 -Subject: [PATCH 10/21] kpatch-build: enhance for out of tree module +Subject: [PATCH 10/23] kpatch-build: enhance for out of tree module support set USERMODBUILDDIR to build patch for out of tree module. @@ -130,3 +130,4 @@ index 894f0ab..4e38412 100755 readelf -s --wide "$KOBJFILE_PATH" > "$SYMTAB" -- 2.18.1 + diff --git a/0011-support-c-plus-kernel-module.patch b/0011-support-c-plus-kernel-module.patch index 306bea141d9db6f37864d44fa5f98297fa8a6c7f..5bb0b7e4a3680467422b91b95b1dd9555a07f343 100644 --- a/0011-support-c-plus-kernel-module.patch +++ b/0011-support-c-plus-kernel-module.patch @@ -1,7 +1,7 @@ -From e438d0139d5e0c60b1e8dc78af8825f1a26fa438 Mon Sep 17 00:00:00 2001 +From d170861502e78c396f0283f66f444a496efd11de Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Wed, 26 Feb 2020 07:36:59 -0500 -Subject: [PATCH 11/21] support c plus kernel module +Subject: [PATCH 11/23] support c plus kernel module support GNU_UNIQUE type symbols. support .group section corelation. @@ -9,18 +9,18 @@ ignore compile warning for third party modules. Signed-off-by: Zhipeng Xie --- - kpatch-build/create-diff-object.c | 62 ++++++++++++++++++++----------- + kpatch-build/create-diff-object.c | 60 +++++++++++++++++++++---------- kpatch-build/kpatch-build | 2 +- - kpatch-build/kpatch-elf.c | 8 +++- + kpatch-build/kpatch-elf.c | 8 ++++- kpatch-build/kpatch-gcc | 3 +- kpatch-build/lookup.c | 5 ++- - 5 files changed, 55 insertions(+), 25 deletions(-) + 5 files changed, 55 insertions(+), 23 deletions(-) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c -index bb2a803..5f90c6b 100644 +index f37d404..d139f45 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c -@@ -459,7 +459,7 @@ static void kpatch_compare_correlated_nonrela_section(struct section *sec) +@@ -460,7 +460,7 @@ static void kpatch_compare_correlated_nonrela_section(struct section *sec) { struct section *sec1 = sec, *sec2 = sec->twin; @@ -29,7 +29,7 @@ index bb2a803..5f90c6b 100644 memcmp(sec1->data->d_buf, sec2->data->d_buf, sec1->data->d_size)) sec->status = CHANGED; else -@@ -475,7 +475,7 @@ static void kpatch_compare_correlated_section(struct section *sec) +@@ -476,7 +476,7 @@ static void kpatch_compare_correlated_section(struct section *sec) sec1->sh.sh_flags != sec2->sh.sh_flags || sec1->sh.sh_entsize != sec2->sh.sh_entsize || (sec1->sh.sh_addralign != sec2->sh.sh_addralign && @@ -38,11 +38,12 @@ index bb2a803..5f90c6b 100644 DIFF_FATAL("%s section header details differ from %s", sec1->name, sec2->name); /* Short circuit for mcount sections, we rebuild regardless */ -@@ -912,6 +912,33 @@ static void kpatch_correlate_section(struct section *sec1, struct section *sec2) +@@ -913,6 +913,34 @@ static void kpatch_correlate_section(struct section *sec1, struct section *sec2) kpatch_correlate_symbol(sec1->sym, sec2->sym); } -+static int kpatch_correlate_group_section(struct list_head *seclist1, struct list_head *seclist2, struct section *sec1, struct section *sec2) ++static int kpatch_correlate_group_section(struct list_head *seclist1, ++ struct list_head *seclist2, struct section *sec1, struct section *sec2) +{ + unsigned int *data1, *end1, *data2; + struct section *isec1, *isec2; @@ -72,15 +73,13 @@ index bb2a803..5f90c6b 100644 static void kpatch_correlate_sections(struct list_head *seclist1, struct list_head *seclist2) { struct section *sec1, *sec2; -@@ -929,15 +956,19 @@ static void kpatch_correlate_sections(struct list_head *seclist1, struct list_he - sec1->secsym)) +@@ -931,14 +959,19 @@ static void kpatch_correlate_sections(struct list_head *seclist1, struct list_he continue; -- /* + /* - * Group sections must match exactly to be correlated. - * Changed group sections are currently not supported. -- */ -+ /* Group section的格式为: ++ * Group section的格式为: + * flag + * section index + * section index @@ -89,18 +88,18 @@ index bb2a803..5f90c6b 100644 + * 当C++代码发生修改时,section index可能会发生变化 + * 这时候我们就比对一下section index所对应的section的 + * name,如果相同,我们就认为这两个group是SAME -+ * */ + */ + if (sec1->sh.sh_type == SHT_GROUP) { - if (sec1->data->d_size != sec2->data->d_size) - continue; - if (memcmp(sec1->data->d_buf, sec2->data->d_buf, - sec1->data->d_size)) -+ if(kpatch_correlate_group_section(seclist1, seclist2, sec1, sec2)) ++ if (kpatch_correlate_group_section(seclist1, seclist2, sec1, sec2)) continue; } -@@ -1519,17 +1550,6 @@ static void kpatch_verify_patchability(struct kpatch_elf *kelf) +@@ -1521,17 +1554,6 @@ static void kpatch_verify_patchability(struct kpatch_elf *kelf) errs++; } @@ -132,7 +131,7 @@ index 4e38412..4896136 100755 cp -f "$TEMPDIR/patch/$MODNAME.ko" "$BASE" || die diff --git a/kpatch-build/kpatch-elf.c b/kpatch-build/kpatch-elf.c -index c6af59e..b3ca7f5 100644 +index c6af59e..f76a9eb 100644 --- a/kpatch-build/kpatch-elf.c +++ b/kpatch-build/kpatch-elf.c @@ -710,8 +710,14 @@ void kpatch_reindex_elements(struct kpatch_elf *kelf) @@ -142,10 +141,10 @@ index c6af59e..b3ca7f5 100644 - list_for_each_entry(sec, &kelf->sections, list) + list_for_each_entry(sec, &kelf->sections, list) { sec->index = index++; -+ /* ++ /* + * since we exclude .group section, we clear SHF_GROUP + * for every section in case of link error. -+ * */ ++ */ + sec->sh.sh_flags &= (~SHF_GROUP); + } @@ -190,3 +189,4 @@ index 8387e8b..4e2fcb9 100644 result->size = sym->size; -- 2.18.1 + diff --git a/0012-symbol-lookup-enhancement.patch b/0012-symbol-lookup-enhancement.patch index 328d65d23591fbeb89170f49a8d4b51bf399be59..1239e300cc000116bebc0b6bf82c11ac6a3aa16e 100644 --- a/0012-symbol-lookup-enhancement.patch +++ b/0012-symbol-lookup-enhancement.patch @@ -1,7 +1,7 @@ -From cf0a8995e6924d8130087a4859c5bf619515768d Mon Sep 17 00:00:00 2001 +From 8dbdf64abc81a8c6f9ec71a4187eb7db9b81d090 Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Wed, 26 Feb 2020 22:03:55 -0500 -Subject: [PATCH 12/21] symbol lookup enhancement +Subject: [PATCH 12/23] symbol lookup enhancement For symbols which have same name in one module or have length longger than KSYM_NAME_LEN(128 bytes). we add @@ -13,16 +13,16 @@ style. Signed-off-by: Zhipeng Xie --- kmod/patch/kpatch-patch.h | 4 + - kpatch-build/create-diff-object.c | 46 ++++++++++- - kpatch-build/create-klp-module.c | 26 ++++-- + kpatch-build/create-diff-object.c | 53 +++++++++++- + kpatch-build/create-klp-module.c | 25 +++++- kpatch-build/kpatch-build | 12 +++ kpatch-build/kpatch-intermediate.h | 2 + - kpatch-build/lookup.c | 123 ++++++++++++++++++++++++++++- + kpatch-build/lookup.c | 129 ++++++++++++++++++++++++++++- kpatch-build/lookup.h | 13 +++ - 7 files changed, 217 insertions(+), 9 deletions(-) + 7 files changed, 230 insertions(+), 8 deletions(-) diff --git a/kmod/patch/kpatch-patch.h b/kmod/patch/kpatch-patch.h -index da4f6a0..3530f66 100644 +index da4f6a0..9df7818 100644 --- a/kmod/patch/kpatch-patch.h +++ b/kmod/patch/kpatch-patch.h @@ -30,6 +30,8 @@ struct kpatch_patch_func { @@ -38,16 +38,16 @@ index da4f6a0..3530f66 100644 char *objname; int external; long addend; -+ char *ref_name; -+ long ref_offset; ++ char *ref_name; ++ long ref_offset; }; struct kpatch_pre_patch_callback { diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c -index 5f90c6b..1bec4f4 100644 +index d139f45..73c557b 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c -@@ -2748,6 +2748,28 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf, +@@ -2753,6 +2753,29 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf, funcs[index].old_size = result.size; funcs[index].new_size = sym->sym.st_size; funcs[index].sympos = result.pos; @@ -55,7 +55,8 @@ index 5f90c6b..1bec4f4 100644 + struct lookup_refsym refsym; + long offset; + -+ if (lookup_ref_symbol_offset(table, sym->name, &refsym, objname, &offset)) ++ if (lookup_ref_symbol_offset(table, sym->name, &refsym, ++ objname, &offset)) + ERROR("unresolvable ambiguity on symbol %s\n", sym->name); + + funcs[index].ref_offset = offset; @@ -76,16 +77,17 @@ index 5f90c6b..1bec4f4 100644 /* * Add a relocation that will populate -@@ -2767,7 +2789,7 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf, +@@ -2772,7 +2795,8 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf, ALLOC_LINK(rela, &relasec->relas); rela->sym = strsym; rela->type = absolute_rela_type; - rela->addend = offset_of_string(&kelf->strings, sym->name); -+ rela->addend = offset_of_string(&kelf->strings, strndup(sym->name, KSYM_NAME_LEN-1)); ++ rela->addend = offset_of_string(&kelf->strings, ++ strndup(sym->name, KSYM_NAME_LEN-1)); rela->offset = (unsigned int)(index * sizeof(*funcs) + offsetof(struct kpatch_patch_func, name)); -@@ -2886,6 +2908,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, +@@ -2891,6 +2915,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, struct lookup_result result; char *sym_objname; int ret, vmlinux, external; @@ -93,7 +95,7 @@ index 5f90c6b..1bec4f4 100644 vmlinux = !strcmp(objname, "vmlinux"); -@@ -3094,12 +3117,28 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, +@@ -3102,12 +3127,32 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, log_debug("lookup for %s @ 0x%016lx len %lu\n", rela->sym->name, result.value, result.size); @@ -105,17 +107,21 @@ index 5f90c6b..1bec4f4 100644 + else { /* for modules, src is discovered at runtime */ ksyms[index].src = 0; -+ if (lookup_is_duplicate_symbol(table, rela->sym->name, objname, result.pos)) { ++ if (lookup_is_duplicate_symbol(table, rela->sym->name, objname, ++ result.pos)) { + struct lookup_refsym refsym; + -+ if (lookup_ref_symbol_offset(table, rela->sym->name, &refsym, objname, &ref_offset)) -+ ERROR("unresolvable ambiguity on symbol %s\n", rela->sym->name); ++ if (lookup_ref_symbol_offset(table, rela->sym->name, ++ &refsym, objname, &ref_offset)) ++ ERROR("unresolvable ambiguity on symbol %s\n", ++ rela->sym->name); + + /* add rela to fill in ref_name field */ + ALLOC_LINK(rela2, &krela_sec->rela->relas); + rela2->sym = strsym; + rela2->type = absolute_rela_type; -+ rela2->addend = offset_of_string(&kelf->strings, refsym.name); ++ rela2->addend = offset_of_string(&kelf->strings, ++ refsym.name); + rela2->offset = (unsigned int)(index * sizeof(*krelas) + + offsetof(struct kpatch_relocation, ref_name)); + } @@ -123,16 +129,17 @@ index 5f90c6b..1bec4f4 100644 ksyms[index].pos = result.pos; ksyms[index].type = rela->sym->type; ksyms[index].bind = rela->sym->bind; -@@ -3108,7 +3147,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, +@@ -3116,7 +3161,8 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, ALLOC_LINK(rela2, &ksym_sec->rela->relas); rela2->sym = strsym; rela2->type = absolute_rela_type; - rela2->addend = offset_of_string(&kelf->strings, rela->sym->name); -+ rela2->addend = offset_of_string(&kelf->strings, strndup(rela->sym->name, KSYM_NAME_LEN-1)); ++ rela2->addend = offset_of_string(&kelf->strings, ++ strndup(rela->sym->name, KSYM_NAME_LEN-1)); rela2->offset = (unsigned int)(index * sizeof(*ksyms) + \ offsetof(struct kpatch_symbol, name)); -@@ -3127,6 +3166,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, +@@ -3135,6 +3181,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, krelas[index].addend = rela->addend; krelas[index].type = rela->type; krelas[index].external = external; @@ -141,7 +148,7 @@ index 5f90c6b..1bec4f4 100644 /* add rela to fill in krelas[index].dest field */ ALLOC_LINK(rela2, &krela_sec->rela->relas); diff --git a/kpatch-build/create-klp-module.c b/kpatch-build/create-klp-module.c -index a97b146..0b441fa 100644 +index a97b146..5b89b73 100644 --- a/kpatch-build/create-klp-module.c +++ b/kpatch-build/create-klp-module.c @@ -38,7 +38,9 @@ enum loglevel loglevel = NORMAL; @@ -176,7 +183,7 @@ index a97b146..0b441fa 100644 struct rela *rela; char *objname; unsigned int nr, index, offset, dest_off; -+ char *ref_name; ++ char *ref_name; krelas = krelasec->data->d_buf; nr = (unsigned int)(krelasec->data->d_size / sizeof(*krelas)); @@ -186,23 +193,22 @@ index a97b146..0b441fa 100644 + /* Get the unique ref_name */ + rela = find_rela_by_offset(krelasec->rela, -+ (unsigned int)(offset + offsetof(struct kpatch_relocation, ref_name))); ++ (unsigned int)(offset + offsetof(struct kpatch_relocation, ++ ref_name))); + if (!rela) + ref_name = NULL; -+ else { ++ else + ref_name = strings + rela->addend; -+ } + /* Get the .kpatch.symbol entry for the rela src */ rela = find_rela_by_offset(krelasec->rela, (unsigned int)(offset + offsetof(struct kpatch_relocation, ksym))); -@@ -207,8 +224,7 @@ static void create_klp_relasecs_and_syms(struct kpatch_elf *kelf, struct section - ERROR("find_rela_by_offset"); +@@ -208,7 +225,7 @@ static void create_klp_relasecs_and_syms(struct kpatch_elf *kelf, struct section /* Create (or find) a klp symbol from the rela src entry */ -- sym = find_or_add_ksym_to_symbols(kelf, ksymsec, strings, + sym = find_or_add_ksym_to_symbols(kelf, ksymsec, strings, - (unsigned int)rela->addend); -+ sym = find_or_add_ksym_to_symbols(kelf, ksymsec, strings, (unsigned int)rela->addend, ref_name, krelas[index].ref_offset); ++ (unsigned int)rela->addend, ref_name, krelas[index].ref_offset); if (!sym) ERROR("error finding or adding ksym to symtab"); @@ -230,20 +236,20 @@ index 4896136..8bef7fb 100755 BUILDDIR="/lib/modules/$ARCHVERSION/build/" SYMVERS_FILE="$TEMPDIR/Module.symvers" diff --git a/kpatch-build/kpatch-intermediate.h b/kpatch-build/kpatch-intermediate.h -index 7230cd4..7247cac 100644 +index 7230cd4..5322e7a 100644 --- a/kpatch-build/kpatch-intermediate.h +++ b/kpatch-build/kpatch-intermediate.h @@ -39,6 +39,8 @@ struct kpatch_relocation { long addend; char *objname; /* object to which this rela applies to */ struct kpatch_symbol *ksym; -+ char *ref_name; -+ long ref_offset; ++ char *ref_name; ++ long ref_offset; }; struct kpatch_arch { diff --git a/kpatch-build/lookup.c b/kpatch-build/lookup.c -index 4e2fcb9..190a7d8 100644 +index 4e2fcb9..1dd183f 100644 --- a/kpatch-build/lookup.c +++ b/kpatch-build/lookup.c @@ -44,6 +44,7 @@ struct object_symbol { @@ -262,15 +268,17 @@ index 4e2fcb9..190a7d8 100644 if (!strcmp(bind, "LOCAL")) { table->obj_syms[i].bind = STB_LOCAL; -@@ -398,6 +400,15 @@ int lookup_local_symbol(struct lookup_table *table, char *name, +@@ -398,6 +400,17 @@ int lookup_local_symbol(struct lookup_table *table, char *name, for_each_obj_symbol(i, sym, table) { if (sym->bind == STB_LOCAL && !strcmp(sym->name, name)) pos++; + else { -+ /* symbol name longer than KSYM_NAME_LEN will be truncated ++ /* ++ * symbol name longer than KSYM_NAME_LEN will be truncated + * by kernel, so we can not find it using its original + * name. we need to add pos for symbols which have same -+ * KSYM_NAME_LEN-1 long prefix.*/ ++ * KSYM_NAME_LEN-1 long prefix. ++ */ + if (strlen(name) >= KSYM_NAME_LEN-1 && + !strncmp(sym->name, name, KSYM_NAME_LEN-1)) + pos++; @@ -278,7 +286,7 @@ index 4e2fcb9..190a7d8 100644 if (table->local_syms == sym) { in_file = 1; -@@ -429,16 +440,25 @@ int lookup_global_symbol(struct lookup_table *table, char *name, +@@ -429,16 +442,27 @@ int lookup_global_symbol(struct lookup_table *table, char *name, struct lookup_result *result) { struct object_symbol *sym; @@ -287,10 +295,12 @@ index 4e2fcb9..190a7d8 100644 memset(result, 0, sizeof(*result)); for_each_obj_symbol(i, sym, table) { -+ /* symbol name longer than KSYM_NAME_LEN will be truncated ++ /* ++ * symbol name longer than KSYM_NAME_LEN will be truncated + * by kernel, so we can not find it using its original + * name. we need to add pos for symbols which have same -+ * KSYM_NAME_LEN-1 long prefix.*/ ++ * KSYM_NAME_LEN-1 long prefix. ++ */ + if (strlen(name) >= KSYM_NAME_LEN-1 && + !strncmp(sym->name, name, KSYM_NAME_LEN-1)) + pos++; @@ -305,7 +315,7 @@ index 4e2fcb9..190a7d8 100644 return 0; } } -@@ -485,6 +505,107 @@ char *lookup_exported_symbol_objname(struct lookup_table *table, char *name) +@@ -485,6 +509,109 @@ char *lookup_exported_symbol_objname(struct lookup_table *table, char *name) return NULL; } @@ -323,12 +333,14 @@ index 4e2fcb9..190a7d8 100644 + return 1; + } + -+ /* symbol name longer than KSYM_NAME_LEN will be truncated ++ /* ++ * symbol name longer than KSYM_NAME_LEN will be truncated + * by kernel, so we can not find it using its original + * name. Here, we consider these long name symbol as duplicated -+ * symbols. since create_klp_module will create symbol name ++ * symbols. since create_klp_module will create symbol name + * format like .klp.sym.objname.symbol,pos, so we consider name -+ * length longer than KSYM_NAME_LEN-1 bytes as duplicated symbol*/ ++ * length longer than KSYM_NAME_LEN-1 bytes as duplicated symbol ++ */ + snprintf(posstr, 32, "%lu", pos); + snprintf(buf, 256, KLP_SYM_PREFIX "%s.%s,%s", objname, name, posstr); + if (strlen(buf) >= KSYM_NAME_LEN-1) @@ -414,7 +426,7 @@ index 4e2fcb9..190a7d8 100644 static void find_this(struct lookup_table *table, char *sym, char *hint) { diff --git a/kpatch-build/lookup.h b/kpatch-build/lookup.h -index 420d0f0..fed3fe9 100644 +index 420d0f0..6f640fd 100644 --- a/kpatch-build/lookup.h +++ b/kpatch-build/lookup.h @@ -1,6 +1,9 @@ @@ -446,9 +458,10 @@ index 420d0f0..fed3fe9 100644 +int lookup_is_duplicate_symbol(struct lookup_table *table, char *name, + char *objname, unsigned long pos); +int lookup_ref_symbol_offset(struct lookup_table *table, char *name, -+ struct lookup_refsym *refsym, char *objname, ++ struct lookup_refsym *refsym, char *objname, + long *offset); #endif /* _LOOKUP_H_ */ -- 2.18.1 + diff --git a/0013-Add-running-kernel-symbol-table-to-help-symbol-looku.patch b/0013-Add-running-kernel-symbol-table-to-help-symbol-looku.patch index 432180387a9d82472f5b619a466903c2ca6aa119..199b2245fdb83caeaef44ddf43328492ae67bb6f 100644 --- a/0013-Add-running-kernel-symbol-table-to-help-symbol-looku.patch +++ b/0013-Add-running-kernel-symbol-table-to-help-symbol-looku.patch @@ -1,7 +1,7 @@ -From 0475b1196c1b5eea3a52e2ff104be91fb27192be Mon Sep 17 00:00:00 2001 +From 5e6c1b2c91af547ad53faafeec20cddaedf7aaa4 Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Wed, 26 Feb 2020 20:28:13 -0500 -Subject: [PATCH 13/21] Add running kernel symbol table to help symbol lookup +Subject: [PATCH 13/23] Add running kernel symbol table to help symbol lookup For some duplicate symbols whose section have no other symbols, we need running kernel symbol table to help @@ -10,15 +10,15 @@ symbol lookup. Signed-off-by: Zhipeng Xie --- kpatch-build/create-diff-object.c | 7 ++- - kpatch-build/lookup.c | 73 ++++++++++++++++++++++++++++++- + kpatch-build/lookup.c | 74 ++++++++++++++++++++++++++++++- kpatch-build/lookup.h | 3 +- - 3 files changed, 80 insertions(+), 3 deletions(-) + 3 files changed, 81 insertions(+), 3 deletions(-) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c -index 1bec4f4..10d07ba 100644 +index 73c557b..c5320d4 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c -@@ -3578,6 +3578,7 @@ int main(int argc, char *argv[]) +@@ -3597,6 +3597,7 @@ int main(int argc, char *argv[]) struct sym_compare_type *base_locals, *sym_comp; char *no_profiling_calls = NULL; char *gcc_add_option = NULL, *mlongcall = NULL; @@ -26,7 +26,7 @@ index 1bec4f4..10d07ba 100644 arguments.debug = 0; argp_parse (&argp, argc, argv, 0, NULL, &arguments); -@@ -3691,8 +3692,12 @@ int main(int argc, char *argv[]) +@@ -3710,8 +3711,12 @@ int main(int argc, char *argv[]) */ kpatch_elf_teardown(kelf_patched); @@ -41,7 +41,7 @@ index 1bec4f4..10d07ba 100644 free(sym_comp->name); } diff --git a/kpatch-build/lookup.c b/kpatch-build/lookup.c -index 190a7d8..8f53567 100644 +index 1dd183f..03a5b32 100644 --- a/kpatch-build/lookup.c +++ b/kpatch-build/lookup.c @@ -45,6 +45,7 @@ struct object_symbol { @@ -52,7 +52,7 @@ index 190a7d8..8f53567 100644 }; struct export_symbol { -@@ -284,6 +285,56 @@ static void symtab_read(struct lookup_table *table, char *path) +@@ -284,6 +285,57 @@ static void symtab_read(struct lookup_table *table, char *path) fclose(file); } @@ -63,9 +63,10 @@ index 190a7d8..8f53567 100644 + unsigned long value; + int i, j, idx; + char line[256], name[256], type[256], mod[256]; -+ idx = 0; + -+ if ((file = fopen(path, "r")) == NULL) ++ idx = 0; ++ file = fopen(path, "r"); ++ if (file == NULL) + ERROR("fopen"); + + while (fgets(line, 256, file)) { @@ -109,7 +110,7 @@ index 190a7d8..8f53567 100644 /* * Symvers file format is the following for kernels v5.3 and newer: * -@@ -352,7 +403,8 @@ static void symvers_read(struct lookup_table *table, char *path) +@@ -352,7 +404,8 @@ static void symvers_read(struct lookup_table *table, char *path) } struct lookup_table *lookup_open(char *symtab_path, char *symvers_path, @@ -119,7 +120,7 @@ index 190a7d8..8f53567 100644 { struct lookup_table *table; -@@ -363,6 +415,8 @@ struct lookup_table *lookup_open(char *symtab_path, char *symvers_path, +@@ -363,6 +416,8 @@ struct lookup_table *lookup_open(char *symtab_path, char *symvers_path, symtab_read(table, symtab_path); symvers_read(table, symvers_path); @@ -128,7 +129,7 @@ index 190a7d8..8f53567 100644 find_local_syms(table, hint, locals); return table; -@@ -603,6 +657,23 @@ int lookup_ref_symbol_offset(struct lookup_table *table, char *name, +@@ -609,6 +664,23 @@ int lookup_ref_symbol_offset(struct lookup_table *table, char *name, } } @@ -153,7 +154,7 @@ index 190a7d8..8f53567 100644 } diff --git a/kpatch-build/lookup.h b/kpatch-build/lookup.h -index fed3fe9..00b6ccc 100644 +index 6f640fd..daeea73 100644 --- a/kpatch-build/lookup.h +++ b/kpatch-build/lookup.h @@ -23,7 +23,8 @@ struct lookup_refsym { @@ -168,3 +169,4 @@ index fed3fe9..00b6ccc 100644 struct lookup_result *result); -- 2.18.1 + diff --git a/0014-livepatch-patch-hook-support-force-enable-disable.patch b/0014-livepatch-patch-hook-support-force-enable-disable.patch index 515443db87070eef408bb96f509d807f9a314476..6ffc163f36196bbe56ada394fb37b50f142bf524 100644 --- a/0014-livepatch-patch-hook-support-force-enable-disable.patch +++ b/0014-livepatch-patch-hook-support-force-enable-disable.patch @@ -1,38 +1,49 @@ -From aacab0b9a2f65adfee8258515cbbb34546f3acc7 Mon Sep 17 00:00:00 2001 +From 62e9cb43c324c933b2934ce9d2923097b96dab1e Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Wed, 26 Feb 2020 20:43:34 -0500 -Subject: [PATCH 14/21] livepatch-patch-hook: support force enable/disable +Subject: [PATCH 14/23] livepatch-patch-hook: support force enable/disable we use force to indicate function which bypass stack check Signed-off-by: Zhipeng Xie --- + kmod/patch/kpatch-patch.h | 1 + kmod/patch/livepatch-patch-hook.c | 18 ++++++++++++++++++ kpatch-build/kpatch-build | 4 ++++ - 2 files changed, 22 insertions(+) + 3 files changed, 23 insertions(+) +diff --git a/kmod/patch/kpatch-patch.h b/kmod/patch/kpatch-patch.h +index 9df7818..6e39364 100644 +--- a/kmod/patch/kpatch-patch.h ++++ b/kmod/patch/kpatch-patch.h +@@ -64,4 +64,5 @@ struct kpatch_post_unpatch_callback { + char *objname; + }; + ++extern unsigned long __kpatch_force_funcs[], __kpatch_force_funcs_end[]; + #endif /* _KPATCH_PATCH_H_ */ diff --git a/kmod/patch/livepatch-patch-hook.c b/kmod/patch/livepatch-patch-hook.c -index 163ae1d..7e848a7 100644 +index fb23a94..5a0de7f 100644 --- a/kmod/patch/livepatch-patch-hook.c +++ b/kmod/patch/livepatch-patch-hook.c -@@ -238,6 +238,17 @@ extern struct kpatch_pre_patch_callback __kpatch_callbacks_pre_patch[], __kpatch - extern struct kpatch_post_patch_callback __kpatch_callbacks_post_patch[], __kpatch_callbacks_post_patch_end[]; +@@ -239,6 +239,17 @@ extern struct kpatch_post_patch_callback __kpatch_callbacks_post_patch[], __kpat extern struct kpatch_pre_unpatch_callback __kpatch_callbacks_pre_unpatch[], __kpatch_callbacks_pre_unpatch_end[]; extern struct kpatch_post_unpatch_callback __kpatch_callbacks_post_unpatch[], __kpatch_callbacks_post_unpatch_end[]; -+extern unsigned long __kpatch_force_funcs[], __kpatch_force_funcs_end[]; -+ + +static int patch_is_func_forced(unsigned long addr) +{ + unsigned long *a; ++ + for (a = __kpatch_force_funcs; a < __kpatch_force_funcs_end; a++) + if (*a == addr) + return 1; + return 0; +} + - ++ #ifdef HAVE_CALLBACKS static int add_callbacks_to_patch_objects(void) + { @@ -403,6 +414,13 @@ static int __init patch_init(void) lfunc = &lfuncs[j]; lfunc->old_name = func->kfunc->name; @@ -64,3 +75,4 @@ index 8bef7fb..57487b1 100755 fi -- 2.18.1 + diff --git a/0015-kpatch-build-ignore-debuginfo-in-patch.patch b/0015-kpatch-build-ignore-debuginfo-in-patch.patch index 788f4da9ea76c3d975fb6b7776d14261b9ce1850..94f31ca8eec19d305bd347ca3058b0dca659fdd7 100644 --- a/0015-kpatch-build-ignore-debuginfo-in-patch.patch +++ b/0015-kpatch-build-ignore-debuginfo-in-patch.patch @@ -1,7 +1,7 @@ -From 4e3c6975dcd0d36509a69bbed1f200f3c49fab23 Mon Sep 17 00:00:00 2001 +From 48fef6d7eceb336816e45690d43093f8be919315 Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Wed, 26 Feb 2020 21:01:02 -0500 -Subject: [PATCH 15/21] kpatch-build: ignore debuginfo in patch +Subject: [PATCH 15/23] kpatch-build: ignore debuginfo in patch Just ignore all .debug_* sections @@ -12,10 +12,10 @@ Signed-off-by: Zhipeng Xie 2 files changed, 19 insertions(+) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c -index 10d07ba..495cce1 100644 +index c5320d4..bc3685b 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c -@@ -2409,6 +2409,23 @@ static void kpatch_include_debug_sections(struct kpatch_elf *kelf) +@@ -2414,6 +2414,23 @@ static void kpatch_include_debug_sections(struct kpatch_elf *kelf) } } @@ -39,9 +39,9 @@ index 10d07ba..495cce1 100644 static void kpatch_mark_ignored_sections(struct kpatch_elf *kelf) { struct section *sec, *strsec, *ignoresec; -@@ -3663,6 +3680,7 @@ int main(int argc, char *argv[]) +@@ -3682,6 +3699,7 @@ int main(int argc, char *argv[]) new_globals_exist = kpatch_include_new_globals(kelf_patched); - kpatch_include_new_static_var(kelf_patched); + kpatch_include_new_static_var(kelf_patched); kpatch_include_debug_sections(kelf_patched); + kpatch_ignore_debug_sections(kelf_patched); @@ -61,3 +61,4 @@ index 57487b1..c109ee3 100755 if [[ -z "$KPATCH_LDFLAGS" ]]; then -- 2.18.1 + diff --git a/0016-add-object-in-kpatch.patch b/0016-add-object-in-kpatch.patch index 3b1ca93d63eb0bfec743eb86e0906e9960efaf86..f907d2ae036b82c5ac7cb2cb32e8a1bf8c568020 100644 --- a/0016-add-object-in-kpatch.patch +++ b/0016-add-object-in-kpatch.patch @@ -1,8 +1,11 @@ -From ea1fb4eb836033b33f08047c3a1cb74a1a458fb2 Mon Sep 17 00:00:00 2001 +From 24392c6f62e26afb192992808772bd19ceab5446 Mon Sep 17 00:00:00 2001 From: Bin Yang Date: Tue, 16 Jul 2019 14:39:27 +0800 -Subject: [PATCH 16/21] add object in kpatch +Subject: [PATCH 16/23] add object in kpatch +it is required by make_hotpatch users + +Signed-off-by: Bin Yang --- kpatch-build/kpatch-build | 3 +++ 1 file changed, 3 insertions(+) @@ -30,3 +33,4 @@ index c109ee3..de448dc 100755 -- 2.18.1 + diff --git a/0017-create-diff-object-fix-.orc_unwind_ip-error.patch b/0017-create-diff-object-fix-.orc_unwind_ip-error.patch index 3569f1a5e3a94d58f787f220ea34baa42b8041aa..be975d26a07c17f1744dae4658f6bc7b6394571f 100644 --- a/0017-create-diff-object-fix-.orc_unwind_ip-error.patch +++ b/0017-create-diff-object-fix-.orc_unwind_ip-error.patch @@ -1,7 +1,7 @@ -From 9fa4a3a0a62a383e635ea7de631176a4513f6db9 Mon Sep 17 00:00:00 2001 +From a1d89dc3ab47d443e879d4553a9ff80e8b82a3ab Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Thu, 27 Feb 2020 15:36:55 -0500 -Subject: [PATCH 17/21] create-diff-object: fix .orc_unwind_ip error +Subject: [PATCH 17/23] create-diff-object: fix .orc_unwind_ip error error: .orc_unwind_ip section header details differ from .orc_unwind_ip @@ -14,10 +14,10 @@ Signed-off-by: Zhipeng Xie 1 file changed, 6 insertions(+) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c -index 495cce1..45979d6 100644 +index bc3685b..20213a0 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c -@@ -972,6 +972,9 @@ static void kpatch_correlate_sections(struct list_head *seclist1, struct list_he +@@ -975,6 +975,9 @@ static void kpatch_correlate_sections(struct list_head *seclist1, struct list_he continue; } @@ -27,7 +27,7 @@ index 495cce1..45979d6 100644 kpatch_correlate_section(sec1, sec2); break; } -@@ -1017,6 +1020,9 @@ static void kpatch_correlate_symbols(struct list_head *symlist1, struct list_hea +@@ -1020,6 +1023,9 @@ static void kpatch_correlate_symbols(struct list_head *symlist1, struct list_hea sym1->sec->twin != sym2->sec) continue; @@ -39,3 +39,4 @@ index 495cce1..45979d6 100644 } -- 2.18.1 + diff --git a/0018-use-orignal-reloc-for-symbols-from-modules.patch b/0018-use-original-reloc-for-symbols-from-modules.patch similarity index 76% rename from 0018-use-orignal-reloc-for-symbols-from-modules.patch rename to 0018-use-original-reloc-for-symbols-from-modules.patch index fc88c8b882641cf09a91c48f55593d5695f0b7c1..7444cbcc37f19b1d19221fe7a0107a1b287c7ac2 100644 --- a/0018-use-orignal-reloc-for-symbols-from-modules.patch +++ b/0018-use-original-reloc-for-symbols-from-modules.patch @@ -1,7 +1,7 @@ -From 7c7f582a9b051c4570a00f215f5534ff0fdfd9a0 Mon Sep 17 00:00:00 2001 +From f162056f0448e676345e3205ef4b190f81b51295 Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Thu, 12 Mar 2020 05:10:55 -0400 -Subject: [PATCH 18/21] use orignal reloc for symbols from modules +Subject: [PATCH 18/23] use original reloc for symbols from modules symbols exported in a patch will generate a symbol version with object module name in Module.symvers, but the symbol is actually @@ -13,10 +13,10 @@ Signed-off-by: Zhipeng Xie 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c -index 45979d6..7d24c7e 100644 +index 20213a0..457d517 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c -@@ -3131,10 +3131,8 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, +@@ -3141,10 +3141,8 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, if (!strcmp(sym_objname, "vmlinux")) continue; @@ -24,9 +24,10 @@ index 45979d6..7d24c7e 100644 - continue; - external = 1; -+ continue; ++ continue; } } log_debug("lookup for %s @ 0x%016lx len %lu\n", -- 2.18.1 + diff --git a/0019-create-diff-object-add-jump-label-support.patch b/0019-create-diff-object-add-jump-label-support.patch index ff6036447ea92a9a6a89b67a04fb440e5752ba74..931c9b72d584ea04d999c5ece25b7dde4d1ce90c 100644 --- a/0019-create-diff-object-add-jump-label-support.patch +++ b/0019-create-diff-object-add-jump-label-support.patch @@ -1,7 +1,7 @@ -From 9233e07a0dfdb3eceb44093feb2e5928a9e391d9 Mon Sep 17 00:00:00 2001 +From c0b20224cf1b081fba152cb4944d762515561d89 Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Mon, 2 Mar 2020 04:35:07 -0500 -Subject: [PATCH 19/21] create-diff-object: add jump label support +Subject: [PATCH 19/23] create-diff-object: add jump label support This patch processes the __jump_table special section, and only the jump_lable used by the changed functions will be @@ -15,10 +15,10 @@ Signed-off-by: Zhipeng Xie 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c -index 7d24c7e..448911b 100644 +index 457d517..4fa4488 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c -@@ -2135,7 +2135,6 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf, +@@ -2140,7 +2140,6 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf, struct rela *rela, *safe; char *src, *dest; unsigned int group_size, src_offset, dest_offset, include; @@ -26,7 +26,7 @@ index 7d24c7e..448911b 100644 LIST_HEAD(newrelas); -@@ -2175,49 +2174,6 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf, +@@ -2180,49 +2179,6 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf, if (!include) continue; @@ -76,7 +76,7 @@ index 7d24c7e..448911b 100644 /* * Copy all relas in the group. It's possible that the relas * aren't sorted (e.g. .rela.fixup), so go through the entire -@@ -2654,8 +2610,7 @@ static void kpatch_process_special_sections(struct kpatch_elf *kelf) +@@ -2659,8 +2615,7 @@ static void kpatch_process_special_sections(struct kpatch_elf *kelf) * jump labels and enable tracepoints in a patched function. */ list_for_each_entry(sec, &kelf->sections, list) { @@ -88,3 +88,4 @@ index 7d24c7e..448911b 100644 continue; -- 2.18.1 + diff --git a/0020-kpatch-build-add-compile-flag-fno-reorder-functions.patch b/0020-kpatch-build-add-compile-flag-fno-reorder-functions.patch index 6b75320508341e25816e72a2fac22d8a5c157c54..0e15c9fd622022cbcbfcd60268a0aa0c7e0733b8 100644 --- a/0020-kpatch-build-add-compile-flag-fno-reorder-functions.patch +++ b/0020-kpatch-build-add-compile-flag-fno-reorder-functions.patch @@ -1,7 +1,7 @@ -From da47ad5e439e9ba9422cac2ade847463bc8578ee Mon Sep 17 00:00:00 2001 +From 586dcb3d2ccd8e45c78d3d140f0190ab5a78ecb3 Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Thu, 12 Mar 2020 06:56:21 -0400 -Subject: [PATCH 20/21] kpatch-build: add compile flag -fno-reorder-functions +Subject: [PATCH 20/23] kpatch-build: add compile flag -fno-reorder-functions Sometimes function foo with static variables can be put in .text.foo section in original binary and be put in @@ -37,3 +37,4 @@ index de448dc..ad7ab71 100755 echo "Reading special section data" -- 2.18.1 + diff --git a/0021-kpatch-build-don-t-copy-.config-for-out-of-tree-modu.patch b/0021-kpatch-build-don-t-copy-.config-for-out-of-tree-modu.patch index 3bca5b416d26ba8c57b0ab1a58a4d88aef3a2365..7ed26264753f841e2c4cc3a3e5f15bb7035acc0b 100644 --- a/0021-kpatch-build-don-t-copy-.config-for-out-of-tree-modu.patch +++ b/0021-kpatch-build-don-t-copy-.config-for-out-of-tree-modu.patch @@ -1,7 +1,9 @@ -From b05aaaf13978393f8e9c2329a80765c0069e7e87 Mon Sep 17 00:00:00 2001 +From cff73a8dca7069d9e558c65f0b76297feab09719 Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Thu, 12 Mar 2020 07:37:00 -0400 -Subject: [PATCH 21/21] kpatch-build: don't copy .config for out of tree module +Subject: [PATCH 21/23] kpatch-build: don't copy .config for out of tree module + +.config only need to be restored when the build patch for kernel Signed-off-by: Zhipeng Xie --- @@ -23,3 +25,4 @@ index ad7ab71..fd34812 100755 # according to .config and kernel version -- 2.18.1 + diff --git a/0022-support-force-enable-disable-for-x86.patch b/0022-support-force-enable-disable-for-x86.patch index eaaea29d69fb0ab08187a80364c0fcef079b28fb..07dc053842e9932cd7f9ee53650292dc8d3081bf 100644 --- a/0022-support-force-enable-disable-for-x86.patch +++ b/0022-support-force-enable-disable-for-x86.patch @@ -1,7 +1,7 @@ -From 4cad4a9ec87736e938ccd13b62c5ef8e595a591e Mon Sep 17 00:00:00 2001 +From 11e57aa03ae87fa24028800851f34205a2aeb0d8 Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Wed, 15 Apr 2020 06:37:59 -0400 -Subject: [PATCH 22/22] support force enable/disable for x86 +Subject: [PATCH 22/23] support force enable/disable for x86 detect if the klp_func structure in vmlinux have force member, if it has, export KLP_SUPPORT_FORCE=y. @@ -55,3 +55,4 @@ index fd34812..523d5df 100755 -- 2.18.1 + diff --git a/0023-create-diff-object-fix-duplicate-symbols-for-vmlinux.patch b/0023-create-diff-object-fix-duplicate-symbols-for-vmlinux.patch index 77a21f50ce4c5be2dbab3900308304ba19e9edd4..002668f39a6fbcf2bad4927176a1f8a924247c98 100644 --- a/0023-create-diff-object-fix-duplicate-symbols-for-vmlinux.patch +++ b/0023-create-diff-object-fix-duplicate-symbols-for-vmlinux.patch @@ -1,49 +1,57 @@ -From 50401005b1a16b93307390983dd61f480492d495 Mon Sep 17 00:00:00 2001 +From 459018cfabc65e9f29bf25476c727b4d5d8089c4 Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Wed, 22 Apr 2020 05:55:33 -0400 -Subject: [PATCH] create-diff-object: fix duplicate symbols for vmlinux +Subject: [PATCH 23/23] create-diff-object: fix duplicate symbols for vmlinux symbol pos in vmlinux may be different with runtime /proc/kallsyms, use ref_name and ref_offset method too. Signed-off-by: Zhipeng Xie --- - kpatch-build/create-diff-object.c | 28 +++++++++++++++------------- - 1 file changed, 15 insertions(+), 13 deletions(-) + kpatch-build/create-diff-object.c | 36 ++++++++++++++++--------------- + 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c -index 2b1ee36..c0c8106 100644 +index 4fa4488..ad5746b 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c -@@ -3100,21 +3100,23 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, +@@ -3110,25 +3110,27 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf, else { /* for modules, src is discovered at runtime */ ksyms[index].src = 0; -- if (lookup_is_duplicate_symbol(table, rela->sym->name, objname, result.pos)) { +- if (lookup_is_duplicate_symbol(table, rela->sym->name, objname, +- result.pos)) { - struct lookup_refsym refsym; - -- if (lookup_ref_symbol_offset(table, rela->sym->name, &refsym, objname, &ref_offset)) -- ERROR("unresolvable ambiguity on symbol %s\n", rela->sym->name); +- if (lookup_ref_symbol_offset(table, rela->sym->name, +- &refsym, objname, &ref_offset)) +- ERROR("unresolvable ambiguity on symbol %s\n", +- rela->sym->name); - - /* add rela to fill in ref_name field */ - ALLOC_LINK(rela2, &krela_sec->rela->relas); - rela2->sym = strsym; - rela2->type = absolute_rela_type; -- rela2->addend = offset_of_string(&kelf->strings, refsym.name); +- rela2->addend = offset_of_string(&kelf->strings, +- refsym.name); - rela2->offset = (unsigned int)(index * sizeof(*krelas) + + } + -+ if (lookup_is_duplicate_symbol(table, rela->sym->name, objname, result.pos)) { ++ if (lookup_is_duplicate_symbol(table, rela->sym->name, objname, ++ result.pos)) { + struct lookup_refsym refsym; + -+ if (lookup_ref_symbol_offset(table, rela->sym->name, &refsym, objname, &ref_offset)) -+ ERROR("unresolvable ambiguity on symbol %s\n", rela->sym->name); ++ if (lookup_ref_symbol_offset(table, rela->sym->name, ++ &refsym, objname, &ref_offset)) ++ ERROR("unresolvable ambiguity on symbol %s\n", ++ rela->sym->name); + + /* add rela to fill in ref_name field */ + ALLOC_LINK(rela2, &krela_sec->rela->relas); + rela2->sym = strsym; + rela2->type = absolute_rela_type; -+ rela2->addend = offset_of_string(&kelf->strings, refsym.name); ++ rela2->addend = offset_of_string(&kelf->strings, ++ refsym.name); + rela2->offset = (unsigned int)(index * sizeof(*krelas) + offsetof(struct kpatch_relocation, ref_name)); - } @@ -54,3 +62,4 @@ index 2b1ee36..c0c8106 100644 ksyms[index].bind = rela->sym->bind; -- 2.18.1 + diff --git a/kpatch.spec b/kpatch.spec index 465ddd6f4a716f9e80a2038ad88cb820043bc554..f091b9634ab95c64980d4f074f964dfac883f1cc 100644 --- a/kpatch.spec +++ b/kpatch.spec @@ -1,14 +1,12 @@ -%global raw_version 0.9.1 - Name: kpatch Epoch: 1 -Version: %{raw_version} -Release: 2 +Version: 0.9.1 +Release: 6 Summary: A Linux dynamic kernel patching infrastructure License: GPLv2 URL: https://github.com/dynup/kpatch -Source0: https://github.com/dynup/kpatch/archive/%{name}-%{raw_version}.tar.gz +Source0: https://github.com/dynup/kpatch/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz Source1: os_hotpatch Source2: livepatch @@ -31,15 +29,16 @@ Patch0014:0014-livepatch-patch-hook-support-force-enable-disable.patch Patch0015:0015-kpatch-build-ignore-debuginfo-in-patch.patch Patch0016:0016-add-object-in-kpatch.patch Patch0017:0017-create-diff-object-fix-.orc_unwind_ip-error.patch -Patch0018:0018-use-orignal-reloc-for-symbols-from-modules.patch +Patch0018:0018-use-original-reloc-for-symbols-from-modules.patch Patch0019:0019-create-diff-object-add-jump-label-support.patch Patch0020:0020-kpatch-build-add-compile-flag-fno-reorder-functions.patch Patch0021:0021-kpatch-build-don-t-copy-.config-for-out-of-tree-modu.patch Patch0022:0022-support-force-enable-disable-for-x86.patch Patch0023:0023-create-diff-object-fix-duplicate-symbols-for-vmlinux.patch -BuildRequires: gcc elfutils-libelf-devel uname-build-checks kernel kernel-devel git +BuildRequires: gcc elfutils-libelf-devel uname-build-checks kernel-devel git Requires: bc +Recommends: %{name}-help = %{version}-%{release} %description kpatch is a Linux dynamic kernel patching infrastructure which allows you to patch @@ -58,7 +57,7 @@ Dynamic kernel patching %package_help %prep -%autosetup -n %{name}-%{raw_version} -p1 -Sgit +%autosetup -n %{name}-%{version} -p1 -Sgit %build export CFLAGS="$RPM_OPT_FLAGS" LDFLAGS="$RPM_LD_FLAGS" @@ -95,6 +94,30 @@ popd %{_mandir}/man1/*.1.gz %changelog +* Thu Nov 22 2020 Zhipeng Xie -1:0.9.1-6 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC:add help package Recommends + +* Fri Sep 25 2020 Zhipeng Xie -1:0.9.1-5 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC:update Source0 + +* Sat Sep 12 2020 Zhipeng Xie -1:0.9.1-4 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC:code optimization + +* Sat Aug 29 2020 Yeqing Peng -1:0.9.1-3 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:adapt kernel source path and name + * Wed Apr 22 2020 Zhipeng Xie -1:0.9.1-2 - Type:bugfix - ID:NA diff --git a/kpatch.yaml b/kpatch.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9e0ac56a415653ee4252b09670e3b1cc735663bd --- /dev/null +++ b/kpatch.yaml @@ -0,0 +1,4 @@ +version_control: github +src_repo: dynup/kpatch +tag_prefix: ^v +seperator: . \ No newline at end of file diff --git a/make_hotpatch b/make_hotpatch index fb8c37aea682afecdd02536c8a7a73dabe26faf3..8c060514a32b180d7b562a45cba9cb8a17433e5c 100644 --- a/make_hotpatch +++ b/make_hotpatch @@ -690,24 +690,28 @@ function fn_main() function fn_prepare() { + local src_dir="" kerver=`uname -r` - kerver=${kerver%.x86_64} - kerver=${kerver%.aarch64} + if [ ! -d /usr/src/linux-$kerver ];then + kerver=${kerver%.x86_64} + kerver=${kerver%.aarch64} + src_dir="kernels" + fi echo kernel version:$kerver if [ ! -L kernel-source ];then if [ -d /arm/arm_kernel ];then ln -s /arm/arm_kernel/linux-$kerver kernel-source else - ln -s /usr/src/kernels/linux-$kerver kernel-source - cp /lib/modules/`uname -r`/build/Makefile /usr/src/kernels/linux-$kerver + ln -s /usr/src/$src_dir/linux-$kerver kernel-source + cp /lib/modules/`uname -r`/build/Makefile /usr/src/$src_dir/linux-$kerver fi fi if [ ! -L .config ];then if [ -d /arm/arm_kernel ];then ln -s /arm/arm_kernel/linux-$kerver/.config .config else - ln -s /usr/src/kernels/linux-$kerver/.config .config - cp /lib/modules/`uname -r`/build/.config /usr/src/kernels/linux-$kerver + ln -s /usr/src/$src_dir/linux-$kerver/.config .config + cp /lib/modules/`uname -r`/build/.config /usr/src/$src_dir/linux-$kerver fi fi rm -rf $G_KPATCH_FLAGS