diff --git a/0025-create-diff-object-update-for-__already_done.patch b/0025-create-diff-object-update-for-__already_done.patch new file mode 100644 index 0000000..aa623f6 --- /dev/null +++ b/0025-create-diff-object-update-for-__already_done.patch @@ -0,0 +1,68 @@ +From 03a09bb210eb5b03ceb5a45452fa962efbd923d1 Mon Sep 17 00:00:00 2001 +From: Joe Lawrence +Date: Mon, 6 Dec 2021 09:55:06 -0500 +Subject: [PATCH] create-diff-object: update for __already_done + +Upstream v5.14+ kernel change a358f40600b3 ("once: implement +DO_ONCE_LITE for non-fast-path "do once" functionality") consolidated a +bunch of do-once macros into a common macro: + + #define DO_ONCE_LITE_IF(condition, func, ...) \ + ({ \ + static bool __section(".data.once") __already_done; \ + ... + +which replaced static local variable __warned with __already_done. + +Update any __warned static local checks to also look for the new +__already_done variable as well. + +Signed-off-by: Joe Lawrence +--- + kpatch-build/create-diff-object.c | 9 ++++++--- + 1 file changed, 6 insertions(+), 3 deletions(-) + +diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c +index 6a06b04..442d8f8 100644 +--- a/kpatch-build/create-diff-object.c ++++ b/kpatch-build/create-diff-object.c +@@ -320,6 +320,7 @@ static bool is_special_static(struct symbol *sym) + static char *var_names[] = { + "__key", + "__warned", ++ "__already_done.", + "__func__", + "__FUNCTION__", + "_rs", +@@ -610,7 +611,7 @@ out: + * The pattern which applies to all cases: + * 1) immediate move of the line number to %esi + * 2) (optional) string section rela +- * 3) (optional) __warned.xxxxx static local rela ++ * 3) (optional) __warned.xxxxx or __already_done.xxxxx static local rela + * 4) warn_slowpath_* or __might_sleep or some other similar rela + */ + static bool kpatch_line_macro_change_only(struct section *sec) +@@ -666,7 +667,8 @@ static bool kpatch_line_macro_change_only(struct section *sec) + continue; + if (rela->string) + continue; +- if (!strncmp(rela->sym->name, "__warned.", 9)) ++ if (!strncmp(rela->sym->name, "__warned.", 9) || ++ !strncmp(rela->sym->name, "__already_done.", 15)) + continue; + if (!strncmp(rela->sym->name, "warn_slowpath_", 14) || + (!strcmp(rela->sym->name, "__warn_printk")) || +@@ -732,7 +734,8 @@ static bool kpatch_line_macro_change_only(struct section *sec) + continue; + if (toc_rela(rela) && toc_rela(rela)->string) + continue; +- if (!strncmp(rela->sym->name, "__warned.", 9)) ++ if (!strncmp(rela->sym->name, "__warned.", 9) || ++ !strncmp(rela->sym->name, "__already_done.", 15)) + continue; + if (!strncmp(rela->sym->name, "warn_slowpath_", 14) || + (!strcmp(rela->sym->name, "__warn_printk")) || +-- +2.23.0 + diff --git a/0026-kpatch-build-Add-missing-allocation-failure-checks.patch b/0026-kpatch-build-Add-missing-allocation-failure-checks.patch new file mode 100644 index 0000000..218fea7 --- /dev/null +++ b/0026-kpatch-build-Add-missing-allocation-failure-checks.patch @@ -0,0 +1,60 @@ +From e06664f379eab0b3f80c504c6656f805bba30e69 Mon Sep 17 00:00:00 2001 +From: David Vernet +Date: Thu, 13 Jan 2022 12:57:15 -0800 +Subject: [PATCH] kpatch-build: Add missing allocation failure checks + +In kpatch-build, there are a number of places where a dynamic allocation +is performed, but the allocation is not checked for a failure. The +common pattern in kpatch-build is to check whether the returned pointer +is NULL, and if so, invoke the ERROR() macro to print a message and +abort the program. + +kpatch_create_mcount_sections(), CORRELATE_ELEMENT(), and +create_klp_arch_sections() all had dynamic allocations without failure +checks. This diff adjusts those callsites to properly check for a failed +allocation, and ERROR() accordingly. + +Signed-off-by: David Vernet +--- + kpatch-build/create-diff-object.c | 4 ++++ + kpatch-build/create-klp-module.c | 2 ++ + 2 files changed, 6 insertions(+) + +diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c +index 442d8f8..01e5d63 100644 +--- a/kpatch-build/create-diff-object.c ++++ b/kpatch-build/create-diff-object.c +@@ -979,6 +979,8 @@ do { \ + log_debug("renaming %s %s to %s\n", \ + kindstr, e2->name, e1->name); \ + e2->name = strdup(e1->name); \ ++ if (!e2->name) \ ++ ERROR("strdup"); \ + } \ + } while (0) + +@@ -3688,6 +3690,8 @@ static void kpatch_create_mcount_sections(struct kpatch_elf *kelf) + + /* Make a writable copy of the text section data */ + newdata = malloc(sym->sec->data->d_size); ++ if (!newdata) ++ ERROR("malloc"); + memcpy(newdata, sym->sec->data->d_buf, sym->sec->data->d_size); + sym->sec->data->d_buf = newdata; + insn = newdata; +diff --git a/kpatch-build/create-klp-module.c b/kpatch-build/create-klp-module.c +index 547e587..8ceb8f3 100644 +--- a/kpatch-build/create-klp-module.c ++++ b/kpatch-build/create-klp-module.c +@@ -343,6 +343,8 @@ static void create_klp_arch_sections(struct kpatch_elf *kelf, char *strings) + + new_size = old_size + base->data->d_size; + sec->data->d_buf = realloc(sec->data->d_buf, new_size); ++ if (!sec->data->d_buf) ++ ERROR("realloc"); + sec->data->d_size = new_size; + sec->sh.sh_size = sec->data->d_size; + memcpy(sec->data->d_buf + old_size, +-- +2.27.0 + diff --git a/0027-create-diff-object-add-support-for-.retpoline_sites-.patch b/0027-create-diff-object-add-support-for-.retpoline_sites-.patch new file mode 100644 index 0000000..fb5df40 --- /dev/null +++ b/0027-create-diff-object-add-support-for-.retpoline_sites-.patch @@ -0,0 +1,48 @@ +From 20c31ce6e82430ae0df0e8014058cfde83196ea0 Mon Sep 17 00:00:00 2001 +From: Markus Boehme +Date: Sat, 15 Jan 2022 01:00:39 +0100 +Subject: [PATCH] create-diff-object: add support for .retpoline_sites section + +Commit 134ab5bd1883 ("objtool,x86: Replace alternatives with .retpoline_sites") +in the kernel starts keeping track of retpoline thunk call sites in a +dedicated section rather than via the alternatives mechanism. + +The .retpoline_sites section needs to have its entries and relocations +for changed symbols included in the patch ELF when building for kernel +5.16+ with CONFIG_RETPOLINE=y. + +Signed-off-by: Markus Boehme +--- + kpatch-build/create-diff-object.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c +index 01e5d63..bbb40ed 100644 +--- a/kpatch-build/create-diff-object.c ++++ b/kpatch-build/create-diff-object.c +@@ -2233,6 +2233,11 @@ static int static_call_sites_group_size(struct kpatch_elf *kelf, int offset) + + return size; + } ++ ++static int retpoline_sites_group_size(struct kpatch_elf *kelf, int offset) ++{ ++ return 4; ++} + #endif + #ifdef __powerpc64__ + static int fixup_entry_group_size(struct kpatch_elf *kelf, int offset) +@@ -2349,6 +2354,10 @@ static struct special_section special_sections[] = { + .name = ".static_call_sites", + .group_size = static_call_sites_group_size, + }, ++ { ++ .name = ".retpoline_sites", ++ .group_size = retpoline_sites_group_size, ++ }, + #endif + #ifdef __powerpc64__ + { +-- +2.27.0 + diff --git a/kpatch.spec b/kpatch.spec index db91d2a..1cff35c 100644 --- a/kpatch.spec +++ b/kpatch.spec @@ -1,7 +1,7 @@ Name: kpatch Epoch: 1 Version: 0.9.5 -Release: 1 +Release: 3 Summary: A Linux dynamic kernel patching infrastructure License: GPLv2 @@ -37,6 +37,9 @@ Patch0021:0021-create-diff-object-fix-segment-fault-when-sec2-rela-.patch Patch0022:0022-use-original-reloc-for-symbols-exported-from-modules.patch Patch0023:0023-create-diff-object-create-dynamic-relocs-for-changed.patch Patch0024:0024-kpatch-build-support-CROSS_COMPILE.patch +Patch0025:0025-create-diff-object-update-for-__already_done.patch +Patch0026:0026-kpatch-build-Add-missing-allocation-failure-checks.patch +Patch0027:0027-create-diff-object-add-support-for-.retpoline_sites-.patch BuildRequires: gcc elfutils-libelf-devel kernel-devel git Requires: bc make gcc patch bison flex openssl-devel @@ -97,13 +100,62 @@ popd %{_mandir}/man1/*.1.gz %changelog +* Wed Jan 26 2022 Zhipeng Xie -1:0.9.5-3 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC:backport upstream patch + +* Wed Dec 22 2021 Wentao Fan -1:0.9.5-2 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC:backport upstream patch + * Sat Nov 13 2021 Zhipeng Xie -1:0.9.5-1 - Type:enhancement - ID:NA - SUG:NA - DESC:upgrade to upstream v0.9.5 -* Fri Jul 23 2021 Xinpeng Liu -1:0.9.1-15 +* Sat Oct 30 2021 Bin Hu -1:0.9.1-21 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC:backport upstream patch + +* Tue Oct 26 2021 Zhipeng Xie -1:0.9.1-20 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC:backport upstream patches + +* Tue Oct 26 2021 Zhipeng Xie -1:0.9.1-19 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC:support make compile environment + +* Tue Sep 28 2021 Zhipeng Xie -1:0.9.1-18 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:kpatch: update sympos for duplicate symbols in vmlinux + create-diff-object: fix segment fault when sec2->rela is NULL + +* Tue Sep 28 2021 Bin Hu -1:0.9.1-17 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:remove uname-build-check from build dependency + +* Sat Aug 21 2021 Zhipeng Xie -1:0.9.1-16 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC:create-diff-object: error on detect new/changed ALTINSTR_ENTRY_CB + +* Fri Jul 23 2021 Zhipeng Xie -1:0.9.1-15 - Type:enhancement - ID:NA - SUG:NA