backport upstream patches

Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
This commit is contained in:
Zhipeng Xie 2022-01-26 15:25:39 +08:00
parent 7f267089a2
commit 2cb5ae19c7
3 changed files with 117 additions and 1 deletions

View File

@ -0,0 +1,60 @@
From e06664f379eab0b3f80c504c6656f805bba30e69 Mon Sep 17 00:00:00 2001
From: David Vernet <void@manifault.com>
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 <void@manifault.com>
---
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

View File

@ -0,0 +1,48 @@
From 20c31ce6e82430ae0df0e8014058cfde83196ea0 Mon Sep 17 00:00:00 2001
From: Markus Boehme <markubo@amazon.com>
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 <markubo@amazon.com>
---
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

View File

@ -1,7 +1,7 @@
Name: kpatch
Epoch: 1
Version: 0.9.5
Release: 2
Release: 3
Summary: A Linux dynamic kernel patching infrastructure
License: GPLv2
@ -38,6 +38,8 @@ 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
@ -98,6 +100,12 @@ popd
%{_mandir}/man1/*.1.gz
%changelog
* Wed Jan 26 2022 Zhipeng Xie<xiezhipeng1@huawei.com> -1:0.9.5-3
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:backport upstream patch
* Wed Dec 22 2021 Wentao Fan<fanwentao@huawei.com> -1:0.9.5-2
- Type:enhancement
- ID:NA