From 5c9a9e50f3071e758ad02fec40efcc02c05ae5941389ec4910e48603bf1e0129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Tesa=C5=99=C3=ADk?= Date: Sun, 25 Apr 2021 18:13:48 +0000 Subject: [PATCH 1/3] Accepting request 886982 from home:wfrisch:branches:Kernel:kdump Hardening: Link as PIE (bsc#1185020). OBS-URL: https://build.opensuse.org/request/show/886982 OBS-URL: https://build.opensuse.org/package/show/Kernel:kdump/kexec-tools?expand=0&rev=135 --- kexec-tools.changes | 5 +++++ kexec-tools.spec | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/kexec-tools.changes b/kexec-tools.changes index 23985e4..6013cb7 100644 --- a/kexec-tools.changes +++ b/kexec-tools.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Tue Apr 20 12:01:43 UTC 2021 - Wolfgang Frisch + +- Hardening: Link as PIE (bsc#1185020). + ------------------------------------------------------------------- Tue Nov 24 16:54:57 UTC 2020 - Ludwig Nussel diff --git a/kexec-tools.spec b/kexec-tools.spec index f0e6bfc..d297ab3 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -1,7 +1,7 @@ # # spec file for package kexec-tools # -# Copyright (c) 2020 SUSE LLC +# Copyright (c) 2021 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -47,7 +47,7 @@ BuildRequires: zlib-devel #!BuildIgnore: gcc-PIE Requires: perl-Bootloader Requires(post): suse-module-tools -Requires(postun): suse-module-tools +Requires(postun):suse-module-tools %{?systemd_requires} %ifarch x86_64 BuildRequires: pkgconfig @@ -77,8 +77,9 @@ the loaded kernel after it panics. %build autoreconf -fvi -export CFLAGS="%{optflags}" +export CFLAGS="%{optflags} -fPIC" export BUILD_CFLAGS="%{optflags}" +export LDFLAGS="-pie" %configure make %{?_smp_mflags} From b09439fd7624ffd822f00d5c1374531ac7798d9c6450a920d815f0524082bb9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Tesa=C5=99=C3=ADk?= Date: Mon, 26 Apr 2021 08:45:50 +0000 Subject: [PATCH 2/3] Accepting request 888400 from home:ptesarik:branches:Kernel:kdump - Bump version to 2.0.21 - Drop patches from upstream git: * kexec-tools-add-variant-helper-functions.patch * kexec-tools-arm64-kexec-allocate-memory-space-avoiding-reserved-regions.patch * kexec-tools-arm64-kdump-deal-with-resource-entries-in-proc-iomem.patch * kexec-tools-build-multiboot2-for-i386.patch * kexec-tools-fix-kexec_file_load-error-handling.patch * kexec-tools-reset-getopt-before-falling-back-to-legacy.patch * kexec-tools-s390-Reset-kernel-command-line-on-syscal.patch * kexec-tools-Remove-duplicated-variable-declarations.patch OBS-URL: https://build.opensuse.org/request/show/888400 OBS-URL: https://build.opensuse.org/package/show/Kernel:kdump/kexec-tools?expand=0&rev=136 --- kexec-tools-2.0.20.tar.xz | 3 - kexec-tools-2.0.21.tar.xz | 3 + ...ove-duplicated-variable-declarations.patch | 92 ------- ...c-tools-add-variant-helper-functions.patch | 84 ------ ...-with-resource-entries-in-proc-iomem.patch | 77 ------ ...mory-space-avoiding-reserved-regions.patch | 247 ------------------ kexec-tools-build-multiboot2-for-i386.patch | 70 ----- ...s-fix-kexec_file_load-error-handling.patch | 231 ---------------- ...getopt-before-falling-back-to-legacy.patch | 55 ---- ...-Reset-kernel-command-line-on-syscal.patch | 32 --- kexec-tools.changes | 14 + kexec-tools.spec | 23 +- 12 files changed, 19 insertions(+), 912 deletions(-) delete mode 100644 kexec-tools-2.0.20.tar.xz create mode 100644 kexec-tools-2.0.21.tar.xz delete mode 100644 kexec-tools-Remove-duplicated-variable-declarations.patch delete mode 100644 kexec-tools-add-variant-helper-functions.patch delete mode 100644 kexec-tools-arm64-kdump-deal-with-resource-entries-in-proc-iomem.patch delete mode 100644 kexec-tools-arm64-kexec-allocate-memory-space-avoiding-reserved-regions.patch delete mode 100644 kexec-tools-build-multiboot2-for-i386.patch delete mode 100644 kexec-tools-fix-kexec_file_load-error-handling.patch delete mode 100644 kexec-tools-reset-getopt-before-falling-back-to-legacy.patch delete mode 100644 kexec-tools-s390-Reset-kernel-command-line-on-syscal.patch diff --git a/kexec-tools-2.0.20.tar.xz b/kexec-tools-2.0.20.tar.xz deleted file mode 100644 index 4d05fc4..0000000 --- a/kexec-tools-2.0.20.tar.xz +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:dad8077f0315445d1f6335579fc4ade222facf82a67124974c7be5303ba4f8c8 -size 297476 diff --git a/kexec-tools-2.0.21.tar.xz b/kexec-tools-2.0.21.tar.xz new file mode 100644 index 0000000..bf09483 --- /dev/null +++ b/kexec-tools-2.0.21.tar.xz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e113142dee891638ad96e0f72cf9277b244477619470b30c41999d312e8e8702 +size 303300 diff --git a/kexec-tools-Remove-duplicated-variable-declarations.patch b/kexec-tools-Remove-duplicated-variable-declarations.patch deleted file mode 100644 index b42feea..0000000 --- a/kexec-tools-Remove-duplicated-variable-declarations.patch +++ /dev/null @@ -1,92 +0,0 @@ -From cc087b11462af9f971a2c090d07e8d780a867b50 Mon Sep 17 00:00:00 2001 -From: Kairui Song -Date: Wed, 29 Jan 2020 13:38:19 +0800 -Subject: kexec-tools: Remove duplicated variable declarations -References: boo#1160399 -Upstream: merged -Git-commit: cc087b11462af9f971a2c090d07e8d780a867b50 - -When building kexec-tools for Fedora 32, following error is observed: - -/usr/bin/ld: kexec/arch/x86_64/kexec-bzImage64.o:(.bss+0x0): multiple definition of `bzImage_support_efi_boot'; -kexec/arch/i386/kexec-bzImage.o:(.bss+0x0): first defined here - -/builddir/build/BUILD/kexec-tools-2.0.20/kexec/arch/arm/../../fs2dt.h:33: multiple definition of `my_debug'; -kexec/fs2dt.o:/builddir/build/BUILD/kexec-tools-2.0.20/kexec/fs2dt.h:33: first defined here - -/builddir/build/BUILD/kexec-tools-2.0.20/kexec/arch/arm64/kexec-arm64.h:68: multiple definition of `arm64_mem'; -kexec/fs2dt.o:/builddir/build/BUILD/kexec-tools-2.0.20/././kexec/arch/arm64/kexec-arm64.h:68: first defined here - -/builddir/build/BUILD/kexec-tools-2.0.20/kexec/arch/arm64/kexec-arm64.h:54: multiple definition of `initrd_size'; -kexec/fs2dt.o:/builddir/build/BUILD/kexec-tools-2.0.20/././kexec/arch/arm64/kexec-arm64.h:54: first defined here - -/builddir/build/BUILD/kexec-tools-2.0.20/kexec/arch/arm64/kexec-arm64.h:53: multiple definition of `initrd_base'; -kexec/fs2dt.o:/builddir/build/BUILD/kexec-tools-2.0.20/././kexec/arch/arm64/kexec-arm64.h:53: first defined here - -And apparently, these variables are wrongly declared multiple times. So -remove duplicated declaration. - -Signed-off-by: Kairui Song -Signed-off-by: Simon Horman -Acked-by: Petr Tesarik ---- - kexec/arch/arm64/kexec-arm64.h | 6 +++--- - kexec/arch/ppc64/kexec-elf-ppc64.c | 2 -- - kexec/arch/x86_64/kexec-bzImage64.c | 1 - - kexec/fs2dt.h | 2 +- - 4 files changed, 4 insertions(+), 7 deletions(-) - ---- a/kexec/arch/arm64/kexec-arm64.h -+++ b/kexec/arch/arm64/kexec-arm64.h -@@ -50,8 +50,8 @@ int zImage_arm64_load(int argc, char **a - void zImage_arm64_usage(void); - - --off_t initrd_base; --off_t initrd_size; -+extern off_t initrd_base; -+extern off_t initrd_size; - - /** - * struct arm64_mem - Memory layout info. -@@ -65,7 +65,7 @@ struct arm64_mem { - }; - - #define arm64_mem_ngv UINT64_MAX --struct arm64_mem arm64_mem; -+extern struct arm64_mem arm64_mem; - - uint64_t get_phys_offset(void); - uint64_t get_vp_offset(void); ---- a/kexec/arch/ppc64/kexec-elf-ppc64.c -+++ b/kexec/arch/ppc64/kexec-elf-ppc64.c -@@ -44,8 +44,6 @@ - uint64_t initrd_base, initrd_size; - unsigned char reuse_initrd = 0; - const char *ramdisk; --/* Used for enabling printing message from purgatory code */ --int my_debug = 0; - - int elf_ppc64_probe(const char *buf, off_t len) - { ---- a/kexec/arch/x86_64/kexec-bzImage64.c -+++ b/kexec/arch/x86_64/kexec-bzImage64.c -@@ -42,7 +42,6 @@ - #include - - static const int probe_debug = 0; --int bzImage_support_efi_boot; - - int bzImage64_probe(const char *buf, off_t len) - { ---- a/kexec/fs2dt.h -+++ b/kexec/fs2dt.h -@@ -30,7 +30,7 @@ extern struct bootblock bb[1]; - - /* Used for enabling printing message from purgatory code - * Only has implemented for PPC64 */ --int my_debug; -+extern int my_debug; - extern int dt_no_old_root; - - void reserve(unsigned long long where, unsigned long long length); diff --git a/kexec-tools-add-variant-helper-functions.patch b/kexec-tools-add-variant-helper-functions.patch deleted file mode 100644 index ce572cd..0000000 --- a/kexec-tools-add-variant-helper-functions.patch +++ /dev/null @@ -1,84 +0,0 @@ -From: AKASHI Takahiro -Date: Fri, 11 Jan 2019 01:59:44 +0900 -Subject: kexec: add variant helper functions for handling memory regions -References: jsc#SLE-9943 -Upstream: not yet, it's under review in upstream - -mem_regions_alloc_and_add() and mem_regions_alloc_and_exclude() are -functionally equivalent to, respectively, mem_regions_add() and -mem_regions_exclude() except the formers will re-allocate memory -dynamically when no more entries are available in 'ranges' array. - -Signed-off-by: AKASHI Takahiro -Signed-off-by: Chester Lin ---- - kexec/mem_regions.c | 42 ++++++++++++++++++++++++++++++++++++++++++ - kexec/mem_regions.h | 7 +++++++ - 2 files changed, 49 insertions(+) - -diff --git a/kexec/mem_regions.c b/kexec/mem_regions.c -index 50c8abccb93a..ad7d3f13fd84 100644 ---- a/kexec/mem_regions.c -+++ b/kexec/mem_regions.c -@@ -125,3 +125,45 @@ int mem_regions_exclude(struct memory_ranges *ranges, - } - return 0; - } -+ -+#define KEXEC_MEMORY_RANGES 16 -+ -+int mem_regions_alloc_and_add(struct memory_ranges *ranges, -+ unsigned long long base, -+ unsigned long long length, int type) -+{ -+ void *new_ranges; -+ -+ if (ranges->size >= ranges->max_size) { -+ new_ranges = realloc(ranges->ranges, -+ sizeof(struct memory_range) * -+ (ranges->max_size + KEXEC_MEMORY_RANGES)); -+ if (!new_ranges) -+ return -1; -+ -+ ranges->ranges = new_ranges; -+ ranges->max_size += KEXEC_MEMORY_RANGES; -+ } -+ -+ return mem_regions_add(ranges, base, length, type); -+} -+ -+int mem_regions_alloc_and_exclude(struct memory_ranges *ranges, -+ const struct memory_range *range) -+{ -+ void *new_ranges; -+ -+ /* for safety, we should have at least one free entry in ranges */ -+ if (ranges->size >= ranges->max_size) { -+ new_ranges = realloc(ranges->ranges, -+ sizeof(struct memory_range) * -+ (ranges->max_size + KEXEC_MEMORY_RANGES)); -+ if (!new_ranges) -+ return -1; -+ -+ ranges->ranges = new_ranges; -+ ranges->max_size += KEXEC_MEMORY_RANGES; -+ } -+ -+ return mem_regions_exclude(ranges, range); -+} -diff --git a/kexec/mem_regions.h b/kexec/mem_regions.h -index ae9e972b0206..e306d67e3261 100644 ---- a/kexec/mem_regions.h -+++ b/kexec/mem_regions.h -@@ -12,4 +12,11 @@ int mem_regions_exclude(struct memory_ranges *ranges, - int mem_regions_add(struct memory_ranges *ranges, unsigned long long base, - unsigned long long length, int type); - -+int mem_regions_alloc_and_exclude(struct memory_ranges *ranges, -+ const struct memory_range *range); -+ -+int mem_regions_alloc_and_add(struct memory_ranges *ranges, -+ unsigned long long base, -+ unsigned long long length, int type); -+ - #endif diff --git a/kexec-tools-arm64-kdump-deal-with-resource-entries-in-proc-iomem.patch b/kexec-tools-arm64-kdump-deal-with-resource-entries-in-proc-iomem.patch deleted file mode 100644 index 2abc986..0000000 --- a/kexec-tools-arm64-kdump-deal-with-resource-entries-in-proc-iomem.patch +++ /dev/null @@ -1,77 +0,0 @@ -From: AKASHI Takahiro -Date: Fri, 11 Jan 2019 01:59:46 +0900 -Subject: arm64: kdump: deal with a lot of resource entries in /proc/iomem -References: jsc#SLE-9943 -Upstream: not yet, it's under review in upstream - -As described in the commit ("arm64: kexec: allocate memory space avoiding -reserved regions"), /proc/iomem now has a lot of "reserved" entries, and -it's not just enough to have a fixed size of memory range array. - -With this patch, kdump is allowed to handle arbitrary number of memory -ranges, using mem_regions_alloc_and_xxx() functions. - -Signed-off-by: AKASHI Takahiro -Signed-off-by: Chester Lin ---- - kexec/arch/arm64/crashdump-arm64.c | 25 ++++++++++--------------- - 1 file changed, 10 insertions(+), 15 deletions(-) - -diff --git a/kexec/arch/arm64/crashdump-arm64.c b/kexec/arch/arm64/crashdump-arm64.c -index 4fd7aa8fd43c..38d1a0f3000d 100644 ---- a/kexec/arch/arm64/crashdump-arm64.c -+++ b/kexec/arch/arm64/crashdump-arm64.c -@@ -23,13 +23,8 @@ - #include "kexec-elf.h" - #include "mem_regions.h" - --/* memory ranges on crashed kernel */ --static struct memory_range system_memory_ranges[CRASH_MAX_MEMORY_RANGES]; --static struct memory_ranges system_memory_rgns = { -- .size = 0, -- .max_size = CRASH_MAX_MEMORY_RANGES, -- .ranges = system_memory_ranges, --}; -+/* memory ranges of crashed kernel */ -+static struct memory_ranges system_memory_rgns; - - /* memory range reserved for crashkernel */ - struct memory_range crash_reserved_mem; -@@ -82,7 +77,7 @@ static uint64_t get_kernel_page_offset(void) - * - * This function is called once for each memory region found in /proc/iomem. - * It locates system RAM and crashkernel reserved memory and places these to -- * variables, respectively, system_memory_ranges and crash_reserved_mem. -+ * variables, respectively, system_memory_rgns and usablemem_rgns. - */ - - static int iomem_range_callback(void *UNUSED(data), int UNUSED(nr), -@@ -90,11 +85,11 @@ static int iomem_range_callback(void *UNUSED(data), int UNUSED(nr), - unsigned long long length) - { - if (strncmp(str, CRASH_KERNEL, strlen(CRASH_KERNEL)) == 0) -- return mem_regions_add(&usablemem_rgns, -- base, length, RANGE_RAM); -+ return mem_regions_alloc_and_add(&usablemem_rgns, -+ base, length, RANGE_RAM); - else if (strncmp(str, SYSTEM_RAM, strlen(SYSTEM_RAM)) == 0) -- return mem_regions_add(&system_memory_rgns, -- base, length, RANGE_RAM); -+ return mem_regions_alloc_and_add(&system_memory_rgns, -+ base, length, RANGE_RAM); - else if (strncmp(str, KERNEL_CODE, strlen(KERNEL_CODE)) == 0) - elf_info.kern_paddr_start = base; - else if (strncmp(str, KERNEL_DATA, strlen(KERNEL_DATA)) == 0) -@@ -135,9 +130,9 @@ static int crash_get_memory_ranges(void) - - dbgprint_mem_range("Reserved memory range", &crash_reserved_mem, 1); - -- if (mem_regions_exclude(&system_memory_rgns, &crash_reserved_mem)) { -- fprintf(stderr, -- "Error: Number of crash memory ranges excedeed the max limit\n"); -+ if (mem_regions_alloc_and_exclude(&system_memory_rgns, -+ &crash_reserved_mem)) { -+ fprintf(stderr, "Cannot allocate memory for ranges\n"); - return -ENOMEM; - } - diff --git a/kexec-tools-arm64-kexec-allocate-memory-space-avoiding-reserved-regions.patch b/kexec-tools-arm64-kexec-allocate-memory-space-avoiding-reserved-regions.patch deleted file mode 100644 index 65e7ca4..0000000 --- a/kexec-tools-arm64-kexec-allocate-memory-space-avoiding-reserved-regions.patch +++ /dev/null @@ -1,247 +0,0 @@ -From: AKASHI Takahiro -Date: Fri, 11 Jan 2019 01:59:45 +0900 -Subject: arm64: kexec: allocate memory space avoiding reserved regions -References: jsc#SLE-9943 -Upstream: not yet, it's under review in upstream - -On UEFI/ACPI-only system, some memory regions, including but not limited -to UEFI memory map and ACPI tables, must be preserved across kexec'ing. -Otherwise, they can be corrupted and result in early failure in booting -a new kernel. - -In recent kernels, /proc/iomem now has an extended file format like: - 40000000-5871ffff : System RAM - 41800000-426affff : Kernel code - 426b0000-42aaffff : reserved - 42ab0000-42c64fff : Kernel data - 54400000-583fffff : Crash kernel - 58590000-585effff : reserved - 58700000-5871ffff : reserved - 58720000-58b5ffff : reserved - 58b60000-5be3ffff : System RAM - 58b61000-58b61fff : reserved - 59a77000-59a77fff : reserved - 5be40000-5becffff : reserved - 5bed0000-5bedffff : System RAM - 5bee0000-5bffffff : reserved - 5c000000-5fffffff : System RAM - 5da00000-5e9fffff : reserved - 5ec00000-5edfffff : reserved - 5ef6a000-5ef6afff : reserved - 5ef6b000-5efcafff : reserved - 5efcd000-5efcffff : reserved - 5efd0000-5effffff : reserved - 5f000000-5fffffff : reserved - -where the "reserved" entries at the top level or under System RAM (and -its descendant resources) are ones of such kind and should not be regarded -as usable memory ranges where several free spaces for loading kexec data -will be allocated. - -With this patch, get_memory_ranges() will handle this format of file -correctly. Note that, for safety, unknown regions, in addition to -"reserved" ones, will also be excluded. - -Signed-off-by: AKASHI Takahiro -Signed-off-by: Chester Lin ---- - kexec/arch/arm64/kexec-arm64.c | 146 ++++++++++++++++++++------------- - 1 file changed, 87 insertions(+), 59 deletions(-) - -diff --git a/kexec/arch/arm64/kexec-arm64.c b/kexec/arch/arm64/kexec-arm64.c -index 1cde75d1a771..2e923b54f5b1 100644 ---- a/kexec/arch/arm64/kexec-arm64.c -+++ b/kexec/arch/arm64/kexec-arm64.c -@@ -10,7 +10,9 @@ - #include - #include - #include -+#include - #include -+#include - #include - #include - #include -@@ -29,6 +31,7 @@ - #include "fs2dt.h" - #include "iomem.h" - #include "kexec-syscall.h" -+#include "mem_regions.h" - #include "arch/options.h" - - #define ROOT_NODE_ADDR_CELLS_DEFAULT 1 -@@ -899,19 +902,33 @@ int get_phys_base_from_pt_load(unsigned long *phys_offset) - return 0; - } - -+static bool to_be_excluded(char *str) -+{ -+ if (!strncmp(str, SYSTEM_RAM, strlen(SYSTEM_RAM)) || -+ !strncmp(str, KERNEL_CODE, strlen(KERNEL_CODE)) || -+ !strncmp(str, KERNEL_DATA, strlen(KERNEL_DATA)) || -+ !strncmp(str, CRASH_KERNEL, strlen(CRASH_KERNEL))) -+ return false; -+ else -+ return true; -+} -+ - /** -- * get_memory_ranges_iomem_cb - Helper for get_memory_ranges_iomem. -+ * get_memory_ranges - Try to get the memory ranges from -+ * /proc/iomem. - */ -- --static int get_memory_ranges_iomem_cb(void *data, int nr, char *str, -- unsigned long long base, unsigned long long length) -+int get_memory_ranges(struct memory_range **range, int *ranges, -+ unsigned long kexec_flags) - { -- int ret; - unsigned long phys_offset = UINT64_MAX; -- struct memory_range *r; -- -- if (nr >= KEXEC_SEGMENT_MAX) -- return -1; -+ FILE *fp; -+ const char *iomem = proc_iomem(); -+ char line[MAX_LINE], *str; -+ unsigned long long start, end; -+ int n, consumed; -+ struct memory_ranges memranges; -+ struct memory_range *last, excl_range; -+ int ret; - - if (!try_read_phys_offset_from_kcore) { - /* Since kernel version 4.19, 'kcore' contains -@@ -945,17 +962,65 @@ static int get_memory_ranges_iomem_cb(void *data, int nr, char *str, - try_read_phys_offset_from_kcore = true; - } - -- r = (struct memory_range *)data + nr; -+ fp = fopen(iomem, "r"); -+ if (!fp) -+ die("Cannot open %s\n", iomem); -+ -+ memranges.ranges = NULL; -+ memranges.size = memranges.max_size = 0; -+ -+ while (fgets(line, sizeof(line), fp) != 0) { -+ n = sscanf(line, "%llx-%llx : %n", &start, &end, &consumed); -+ if (n != 2) -+ continue; -+ str = line + consumed; -+ -+ if (!strncmp(str, SYSTEM_RAM, strlen(SYSTEM_RAM))) { -+ ret = mem_regions_alloc_and_add(&memranges, -+ start, end - start + 1, RANGE_RAM); -+ if (ret) { -+ fprintf(stderr, -+ "Cannot allocate memory for ranges\n"); -+ return -ENOMEM; -+ } - -- if (!strncmp(str, SYSTEM_RAM, strlen(SYSTEM_RAM))) -- r->type = RANGE_RAM; -- else if (!strncmp(str, IOMEM_RESERVED, strlen(IOMEM_RESERVED))) -- r->type = RANGE_RESERVED; -- else -- return 1; -+ dbgprintf("%s:+[%d] %016llx - %016llx\n", __func__, -+ memranges.size - 1, -+ memranges.ranges[memranges.size - 1].start, -+ memranges.ranges[memranges.size - 1].end); -+ } else if (to_be_excluded(str)) { -+ if (!memranges.size) -+ continue; -+ -+ /* -+ * Note: mem_regions_exclude() doesn't guarantee -+ * that the ranges are sorted out, but as long as -+ * we cope with /proc/iomem, we only operate on -+ * the last entry and so it is safe. -+ */ - -- r->start = base; -- r->end = base + length - 1; -+ /* The last System RAM range */ -+ last = &memranges.ranges[memranges.size - 1]; -+ -+ if (last->end < start) -+ /* New resource outside of System RAM */ -+ continue; -+ if (end < last->start) -+ /* Already excluded by parent resource */ -+ continue; -+ -+ excl_range.start = start; -+ excl_range.end = end; -+ mem_regions_alloc_and_exclude(&memranges, &excl_range); -+ dbgprintf("%s:- %016llx - %016llx\n", -+ __func__, start, end); -+ } -+ } -+ -+ fclose(fp); -+ -+ *range = memranges.ranges; -+ *ranges = memranges.size; - - /* As a fallback option, we can try determining the PHYS_OFFSET - * value from the '/proc/iomem' entries as well. -@@ -976,52 +1041,15 @@ static int get_memory_ranges_iomem_cb(void *data, int nr, char *str, - * between the user-space and kernel space 'PHYS_OFFSET' - * value. - */ -- set_phys_offset(r->start, "iomem"); -+ if (memranges.size) -+ set_phys_offset(memranges.ranges[0].start, "iomem"); - -- dbgprintf("%s: %016llx - %016llx : %s", __func__, r->start, -- r->end, str); -+ dbgprint_mem_range("System RAM ranges;", -+ memranges.ranges, memranges.size); - - return 0; - } - --/** -- * get_memory_ranges_iomem - Try to get the memory ranges from -- * /proc/iomem. -- */ -- --static int get_memory_ranges_iomem(struct memory_range *array, -- unsigned int *count) --{ -- *count = kexec_iomem_for_each_line(NULL, -- get_memory_ranges_iomem_cb, array); -- -- if (!*count) { -- dbgprintf("%s: failed: No RAM found.\n", __func__); -- return EFAILED; -- } -- -- return 0; --} -- --/** -- * get_memory_ranges - Try to get the memory ranges some how. -- */ -- --int get_memory_ranges(struct memory_range **range, int *ranges, -- unsigned long kexec_flags) --{ -- static struct memory_range array[KEXEC_SEGMENT_MAX]; -- unsigned int count; -- int result; -- -- result = get_memory_ranges_iomem(array, &count); -- -- *range = result ? NULL : array; -- *ranges = result ? 0 : count; -- -- return result; --} -- - int arch_compat_trampoline(struct kexec_info *info) - { - return 0; diff --git a/kexec-tools-build-multiboot2-for-i386.patch b/kexec-tools-build-multiboot2-for-i386.patch deleted file mode 100644 index 3172657..0000000 --- a/kexec-tools-build-multiboot2-for-i386.patch +++ /dev/null @@ -1,70 +0,0 @@ -From: Chris Packham -Date: Sun, 17 Nov 2019 15:52:15 -0800 -Subject: kexec: build multiboot2 for i386 -References: jsc#SLE-9943 -Upstream: Queued, http://lists.infradead.org/pipermail/kexec/2020-January/024311.html - -This addresses the following compilation issues when building for i386. - - kexec/arch/i386/kexec-x86.c:39:22: error: 'multiboot2_x86_probe' undeclared here (not in a function); did you mean 'multiboot_x86_probe'? - { "multiboot2-x86", multiboot2_x86_probe, multiboot2_x86_load, - ^~~~~~~~~~~~~~~~~~~~ - multiboot_x86_probe - kexec/arch/i386/kexec-x86.c:39:44: error: 'multiboot2_x86_load' undeclared here (not in a function); did you mean 'multiboot_x86_load'? - { "multiboot2-x86", multiboot2_x86_probe, multiboot2_x86_load, - ^~~~~~~~~~~~~~~~~~~ - multiboot_x86_load - kexec/arch/i386/kexec-x86.c:40:4: error: 'multiboot2_x86_usage' undeclared here (not in a function); did you mean 'multiboot_x86_usage'? - multiboot2_x86_usage }, - ^~~~~~~~~~~~~~~~~~~~ - multiboot_x86_usage - make: *** [Makefile:114: kexec/arch/i386/kexec-x86.o] Error 1 - make: *** Waiting for unfinished jobs.... - -Signed-off-by: Chris Packham -Signed-off-by: Chester Lin ---- -I wasn't sure whether this should be fixed by linking with kexec-mb2-x86.o or -by removing the code from kexec-x86.c. I went for the former but I'd happily -change to the latter. - - kexec/arch/i386/Makefile | 2 +- - kexec/arch/i386/kexec-x86.h | 5 +++++ - 2 files changed, 6 insertions(+), 1 deletion(-) - -diff --git a/kexec/arch/i386/Makefile b/kexec/arch/i386/Makefile -index 105cefd..f486103 100644 ---- a/kexec/arch/i386/Makefile -+++ b/kexec/arch/i386/Makefile -@@ -7,6 +7,7 @@ i386_KEXEC_SRCS += kexec/arch/i386/kexec-elf-x86.c - i386_KEXEC_SRCS += kexec/arch/i386/kexec-elf-rel-x86.c - i386_KEXEC_SRCS += kexec/arch/i386/kexec-bzImage.c - i386_KEXEC_SRCS += kexec/arch/i386/kexec-multiboot-x86.c -+i386_KEXEC_SRCS += kexec/arch/i386/kexec-mb2-x86.c - i386_KEXEC_SRCS += kexec/arch/i386/kexec-beoboot-x86.c - i386_KEXEC_SRCS += kexec/arch/i386/kexec-nbi.c - i386_KEXEC_SRCS += kexec/arch/i386/x86-linux-setup.c -@@ -14,7 +15,6 @@ i386_KEXEC_SRCS += kexec/arch/i386/crashdump-x86.c - - dist += kexec/arch/i386/Makefile $(i386_KEXEC_SRCS) \ - kexec/arch/i386/crashdump-x86.h \ -- kexec/arch/i386/kexec-mb2-x86.c \ - kexec/arch/i386/kexec-x86.h \ - kexec/arch/i386/x86-linux-setup.h \ - kexec/arch/i386/include/arch/options.h -diff --git a/kexec/arch/i386/kexec-x86.h b/kexec/arch/i386/kexec-x86.h -index 1b58c3b..0f941df 100644 ---- a/kexec/arch/i386/kexec-x86.h -+++ b/kexec/arch/i386/kexec-x86.h -@@ -60,6 +60,11 @@ int multiboot_x86_load(int argc, char **argv, const char *buf, off_t len, - struct kexec_info *info); - void multiboot_x86_usage(void); - -+int multiboot2_x86_load(int argc, char **argv, const char *buf, off_t len, -+ struct kexec_info *info); -+void multiboot2_x86_usage(void); -+int multiboot2_x86_probe(const char *buf, off_t buf_len); -+ - int elf_x86_probe(const char *buf, off_t len); - int elf_x86_load(int argc, char **argv, const char *buf, off_t len, - struct kexec_info *info); diff --git a/kexec-tools-fix-kexec_file_load-error-handling.patch b/kexec-tools-fix-kexec_file_load-error-handling.patch deleted file mode 100644 index b615e82..0000000 --- a/kexec-tools-fix-kexec_file_load-error-handling.patch +++ /dev/null @@ -1,231 +0,0 @@ -From 0ec1fd23847ba103f967e3377e2a1b13712cff6e Mon Sep 17 00:00:00 2001 -From: Petr Tesarik -Date: Thu, 12 Mar 2020 20:12:12 +0100 -Subject: Fix kexec_file_load(2) error handling -References: bsc#1166105 -Upstream: merged -Git-commit: 4f77da6340356de40af70473d3c3ae6ec663fbdf - -The handling of kexec_file_load() error conditions needs some -improvement. - -First, on failure, the system call itself returns -1 and sets -errno. It is wrong to check the return value itself. - -Second, do_kexec_file_load() mixes different types of error -codes (-1, return value of a load method, negative kernel error -number). Let it always return one of the reason codes defined in -kexec/kexec.h. - -Third, the caller of do_kexec_file_load() cannot know what exactly -failed inside that function, so it should not check errno directly. -All it needs to know is whether it makes sense to fall back to the -other syscall. Add an error code for that purpose (EFALLBACK), and -let do_kexec_file_load() decide. - -Fourth, do_kexec_file_load() should not print any error message if -it returns EFALLBACK, because the fallback syscall may succeed -later, and the user is confused whether the command failed, or not. -Move the error message towards the end of main(). - -Signed-off-by: Petr Tesarik ---- - kexec/kexec.c | 114 ++++++++++++++++++++++++++++++---------------------------- - kexec/kexec.h | 1 + - 2 files changed, 61 insertions(+), 54 deletions(-) - -diff --git a/kexec/kexec.c b/kexec/kexec.c -index bc6ab3d..33c1b4b 100644 ---- a/kexec/kexec.c -+++ b/kexec/kexec.c -@@ -836,11 +836,21 @@ static int kexec_file_unload(unsigned long kexec_file_flags) - { - int ret = 0; - -+ if (!is_kexec_file_load_implemented()) -+ return EFALLBACK; -+ - ret = kexec_file_load(-1, -1, 0, NULL, kexec_file_flags); - if (ret != 0) { -- /* The unload failed, print some debugging information */ -- fprintf(stderr, "kexec_file_load(unload) failed\n: %s\n", -- strerror(errno)); -+ if (errno == ENOSYS) { -+ ret = EFALLBACK; -+ } else { -+ /* -+ * The unload failed, print some debugging -+ * information */ -+ fprintf(stderr, "kexec_file_load(unload) failed: %s\n", -+ strerror(errno)); -+ ret = EFAILED; -+ } - } - return ret; - } -@@ -1182,15 +1192,13 @@ static int do_kexec_file_load(int fileind, int argc, char **argv, - info.file_mode = 1; - info.initrd_fd = -1; - -- if (!is_kexec_file_load_implemented()) { -- fprintf(stderr, "syscall kexec_file_load not available.\n"); -- return -ENOSYS; -- } -+ if (!is_kexec_file_load_implemented()) -+ return EFALLBACK; - - if (argc - fileind <= 0) { - fprintf(stderr, "No kernel specified\n"); - usage(); -- return -1; -+ return EFAILED; - } - - kernel = argv[fileind]; -@@ -1199,7 +1207,7 @@ static int do_kexec_file_load(int fileind, int argc, char **argv, - if (kernel_fd == -1) { - fprintf(stderr, "Failed to open file %s:%s\n", kernel, - strerror(errno)); -- return -1; -+ return EFAILED; - } - - /* slurp in the input kernel */ -@@ -1225,7 +1233,7 @@ static int do_kexec_file_load(int fileind, int argc, char **argv, - if (i == file_types) { - fprintf(stderr, "Cannot determine the file type " "of %s\n", - kernel); -- return -1; -+ return EFAILED; - } - - ret = file_type[i].load(argc, argv, kernel_buf, kernel_size, &info); -@@ -1243,9 +1251,43 @@ static int do_kexec_file_load(int fileind, int argc, char **argv, - - ret = kexec_file_load(kernel_fd, info.initrd_fd, info.command_line_len, - info.command_line, info.kexec_flags); -- if (ret != 0) -- fprintf(stderr, "kexec_file_load failed: %s\n", -- strerror(errno)); -+ if (ret != 0) { -+ switch (errno) { -+ /* -+ * Something failed with signature verification. -+ * Reject the image. -+ */ -+ case ELIBBAD: -+ case EKEYREJECTED: -+ case ENOPKG: -+ case ENOKEY: -+ case EBADMSG: -+ case EMSGSIZE: -+ /* Reject by default. */ -+ default: -+ ret = EFAILED; -+ break; -+ -+ /* Not implemented. */ -+ case ENOSYS: -+ /* -+ * Parsing image or other options failed -+ * The image may be invalid or image -+ * type may not supported by kernel so -+ * retry parsing in kexec-tools. -+ */ -+ case EINVAL: -+ case ENOEXEC: -+ /* -+ * ENOTSUP can be unsupported image -+ * type or unsupported PE signature -+ * wrapper type, duh. -+ */ -+ case ENOTSUP: -+ ret = EFALLBACK; -+ break; -+ } -+ } - - close(kernel_fd); - return ret; -@@ -1496,7 +1538,7 @@ int main(int argc, char *argv[]) - if (do_unload) { - if (do_kexec_file_syscall) { - result = kexec_file_unload(kexec_file_flags); -- if ((result == -ENOSYS) && do_kexec_fallback) -+ if (result == EFALLBACK && do_kexec_fallback) - do_kexec_file_syscall = 0; - } - if (!do_kexec_file_syscall) -@@ -1506,46 +1548,8 @@ int main(int argc, char *argv[]) - if (do_kexec_file_syscall) { - result = do_kexec_file_load(fileind, argc, argv, - kexec_file_flags); -- if (do_kexec_fallback) switch (result) { -- /* -- * Something failed with signature verification. -- * Reject the image. -- */ -- case -ELIBBAD: -- case -EKEYREJECTED: -- case -ENOPKG: -- case -ENOKEY: -- case -EBADMSG: -- case -EMSGSIZE: -- /* -- * By default reject or do nothing if -- * succeded -- */ -- default: break; -- case -ENOSYS: /* not implemented */ -- /* -- * Parsing image or other options failed -- * The image may be invalid or image -- * type may not supported by kernel so -- * retry parsing in kexec-tools. -- */ -- case -EINVAL: -- case -ENOEXEC: -- /* -- * ENOTSUP can be unsupported image -- * type or unsupported PE signature -- * wrapper type, duh -- * -- * The kernel sometimes wrongly -- * returns ENOTSUPP (524) - ignore -- * that. It is not supposed to be seen -- * by userspace so seeing it is a -- * kernel bug -- */ -- case -ENOTSUP: -- do_kexec_file_syscall = 0; -- break; -- } -+ if (result == EFALLBACK && do_kexec_fallback) -+ do_kexec_file_syscall = 0; - } - if (!do_kexec_file_syscall) - result = my_load(type, fileind, argc, argv, -@@ -1570,6 +1574,8 @@ int main(int argc, char *argv[]) - if ((result == 0) && do_load_jump_back_helper) { - result = my_load_jump_back_helper(kexec_flags, entry); - } -+ if (result == EFALLBACK) -+ fputs("syscall kexec_file_load not available.\n", stderr); - - fflush(stdout); - fflush(stderr); -diff --git a/kexec/kexec.h b/kexec/kexec.h -index a97b9ce..28fd129 100644 ---- a/kexec/kexec.h -+++ b/kexec/kexec.h -@@ -63,6 +63,7 @@ - */ - #define EFAILED -1 /* default error code */ - #define ENOCRASHKERNEL -2 /* no memory reserved for crashkernel */ -+#define EFALLBACK -3 /* fallback to kexec_load(2) may work */ - - /* - * This function doesn't actually exist. The idea is that when someone --- -2.16.4 - diff --git a/kexec-tools-reset-getopt-before-falling-back-to-legacy.patch b/kexec-tools-reset-getopt-before-falling-back-to-legacy.patch deleted file mode 100644 index e9b0e39..0000000 --- a/kexec-tools-reset-getopt-before-falling-back-to-legacy.patch +++ /dev/null @@ -1,55 +0,0 @@ -From dadafc4664c7b78ea1561ccca33986c9639106ec Mon Sep 17 00:00:00 2001 -From: Petr Tesarik -Date: Fri, 13 Mar 2020 14:54:00 +0100 -Subject: Reset getopt before falling back to legacy syscall -References: bsc#1166105 -Upstream: merged -Git-commit: 9cf721279f6cb0dec09c8752e471f15fb662406b - -The modules may need to parse the arguments again after -kexec_file_load(2) failed, but getopt is not reset. - -This change fixes the --initrd option on s390x. Without this patch, -it will fail to load the initrd on kernels that do not implement -kexec_file_load(2). - -Signed-off-by: Petr Tesarik ---- - kexec/kexec.c | 12 ++++++++++-- - 1 file changed, 10 insertions(+), 2 deletions(-) - -diff --git a/kexec/kexec.c b/kexec/kexec.c -index 33c1b4b..6601f1f 100644 ---- a/kexec/kexec.c -+++ b/kexec/kexec.c -@@ -1538,8 +1538,12 @@ int main(int argc, char *argv[]) - if (do_unload) { - if (do_kexec_file_syscall) { - result = kexec_file_unload(kexec_file_flags); -- if (result == EFALLBACK && do_kexec_fallback) -+ if (result == EFALLBACK && do_kexec_fallback) { -+ /* Reset getopt for fallback */ -+ opterr = 1; -+ optind = 1; - do_kexec_file_syscall = 0; -+ } - } - if (!do_kexec_file_syscall) - result = k_unload(kexec_flags); -@@ -1548,8 +1552,12 @@ int main(int argc, char *argv[]) - if (do_kexec_file_syscall) { - result = do_kexec_file_load(fileind, argc, argv, - kexec_file_flags); -- if (result == EFALLBACK && do_kexec_fallback) -+ if (result == EFALLBACK && do_kexec_fallback) { -+ /* Reset getopt for fallback */ -+ opterr = 1; -+ optind = 1; - do_kexec_file_syscall = 0; -+ } - } - if (!do_kexec_file_syscall) - result = my_load(type, fileind, argc, argv, --- -2.16.4 - diff --git a/kexec-tools-s390-Reset-kernel-command-line-on-syscal.patch b/kexec-tools-s390-Reset-kernel-command-line-on-syscal.patch deleted file mode 100644 index 011717e..0000000 --- a/kexec-tools-s390-Reset-kernel-command-line-on-syscal.patch +++ /dev/null @@ -1,32 +0,0 @@ -From: Petr Tesarik -Date: Fri, 3 Apr 2020 13:12:00 +0200 -Subject: kexec-tools: s390: Reset kernel command line on syscall fallback -References: bsc#1167868 -Upstream: merged -Git-commit: 5dc72ded6050a5bb161e3b832867e660c9ca009e - -The command line is duplicated on s390 if kexec_file_load(2) is not -implemented. That's because the corresponding variable is not reset -to an empty string before re-parsing the kexec command line. - -Fixes: 9cf721279f6c ("Reset getopt before falling back to legacy syscall") -Signed-off-by: Petr Tesarik ---- - kexec/arch/s390/kexec-image.c | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/kexec/arch/s390/kexec-image.c b/kexec/arch/s390/kexec-image.c -index 8b39566..3c24fdf 100644 ---- a/kexec/arch/s390/kexec-image.c -+++ b/kexec/arch/s390/kexec-image.c -@@ -112,6 +112,7 @@ image_s390_load(int argc, char **argv, const char *kernel_buf, - }; - static const char short_options[] = KEXEC_OPT_STR ""; - -+ command_line[0] = 0; - ramdisk = NULL; - ramdisk_len = 0; - ramdisk_origin = 0; --- -2.16.4 - diff --git a/kexec-tools.changes b/kexec-tools.changes index 6013cb7..b66ad58 100644 --- a/kexec-tools.changes +++ b/kexec-tools.changes @@ -1,3 +1,17 @@ +------------------------------------------------------------------- +Mon Apr 26 08:07:47 UTC 2021 - Petr Tesařík + +- Bump version to 2.0.21 +- Drop patches from upstream git: + * kexec-tools-add-variant-helper-functions.patch + * kexec-tools-arm64-kexec-allocate-memory-space-avoiding-reserved-regions.patch + * kexec-tools-arm64-kdump-deal-with-resource-entries-in-proc-iomem.patch + * kexec-tools-build-multiboot2-for-i386.patch + * kexec-tools-fix-kexec_file_load-error-handling.patch + * kexec-tools-reset-getopt-before-falling-back-to-legacy.patch + * kexec-tools-s390-Reset-kernel-command-line-on-syscal.patch + * kexec-tools-Remove-duplicated-variable-declarations.patch + ------------------------------------------------------------------- Tue Apr 20 12:01:43 UTC 2021 - Wolfgang Frisch diff --git a/kexec-tools.spec b/kexec-tools.spec index d297ab3..21c8137 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -17,7 +17,7 @@ Name: kexec-tools -Version: 2.0.20 +Version: 2.0.21 Release: 0 Summary: Tools for loading replacement kernels into memory License: GPL-2.0-or-later @@ -29,16 +29,8 @@ Source3: kexec-load.service Source4: %{name}-rpmlintrc Patch3: %{name}-disable-test.patch Patch4: %{name}-vmcoreinfo-in-xen.patch -Patch5: %{name}-add-variant-helper-functions.patch -Patch6: %{name}-arm64-kexec-allocate-memory-space-avoiding-reserved-regions.patch -Patch7: %{name}-arm64-kdump-deal-with-resource-entries-in-proc-iomem.patch -Patch8: %{name}-build-multiboot2-for-i386.patch Patch9: %{name}-video-capability.patch Patch10: %{name}-SYS_getrandom.patch -Patch11: %{name}-fix-kexec_file_load-error-handling.patch -Patch12: %{name}-reset-getopt-before-falling-back-to-legacy.patch -Patch13: %{name}-s390-Reset-kernel-command-line-on-syscal.patch -Patch14: %{name}-Remove-duplicated-variable-declarations.patch BuildRequires: autoconf BuildRequires: automake BuildRequires: systemd-rpm-macros @@ -62,18 +54,7 @@ the loaded kernel after it panics. %prep %setup -q -%patch3 -p1 -%patch4 -p1 -%patch5 -p1 -%patch6 -p1 -%patch7 -p1 -%patch8 -p1 -%patch9 -p1 -%patch10 -p1 -%patch11 -p1 -%patch12 -p1 -%patch13 -p1 -%patch14 -p1 +%autopatch -p1 %build autoreconf -fvi From 2223aa05ad84131b8e3a9cafec8aa42b6b8b18c0b226aac6477a9371b3949aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Tesa=C5=99=C3=ADk?= Date: Mon, 26 Apr 2021 09:45:32 +0000 Subject: [PATCH 3/3] Accepting request 888429 from home:ptesarik:branches:Kernel:kdump - kexec-tools-remove-duplicate-ramdisk-definition.patch: Remove duplicate definition of ramdisk (fix ppc build). OBS-URL: https://build.opensuse.org/request/show/888429 OBS-URL: https://build.opensuse.org/package/show/Kernel:kdump/kexec-tools?expand=0&rev=137 --- ...-remove-duplicate-ramdisk-definition.patch | 22 +++++++++++++++++++ kexec-tools.changes | 6 +++++ kexec-tools.spec | 1 + 3 files changed, 29 insertions(+) create mode 100644 kexec-tools-remove-duplicate-ramdisk-definition.patch diff --git a/kexec-tools-remove-duplicate-ramdisk-definition.patch b/kexec-tools-remove-duplicate-ramdisk-definition.patch new file mode 100644 index 0000000..e0be72c --- /dev/null +++ b/kexec-tools-remove-duplicate-ramdisk-definition.patch @@ -0,0 +1,22 @@ +From: Petr Tesarik +Subject: Remove duplicate definition of ramdisk +Upstream: not yet, sent on 2021-04-26 + +The ramdisk variable is defined in kexec/arch/ppc/kexec-ppc.c. This +other definition is not needed and breaks build with -fno-common. + +Signed-off-by: Petr Tesarik +--- + kexec/arch/ppc/kexec-elf-ppc.c | 1 - + 1 file changed, 1 deletion(-) + +--- a/kexec/arch/ppc/kexec-elf-ppc.c ++++ b/kexec/arch/ppc/kexec-elf-ppc.c +@@ -33,7 +33,6 @@ + static const int probe_debug = 0; + + unsigned char reuse_initrd; +-const char *ramdisk; + int create_flatten_tree(struct kexec_info *, unsigned char **, unsigned long *, + char *); + diff --git a/kexec-tools.changes b/kexec-tools.changes index b66ad58..78b9c8a 100644 --- a/kexec-tools.changes +++ b/kexec-tools.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Apr 26 09:35:21 UTC 2021 - Petr Tesařík + +- kexec-tools-remove-duplicate-ramdisk-definition.patch: + Remove duplicate definition of ramdisk (fix ppc build). + ------------------------------------------------------------------- Mon Apr 26 08:07:47 UTC 2021 - Petr Tesařík diff --git a/kexec-tools.spec b/kexec-tools.spec index 21c8137..370b8e3 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -31,6 +31,7 @@ Patch3: %{name}-disable-test.patch Patch4: %{name}-vmcoreinfo-in-xen.patch Patch9: %{name}-video-capability.patch Patch10: %{name}-SYS_getrandom.patch +Patch11: %{name}-remove-duplicate-ramdisk-definition.patch BuildRequires: autoconf BuildRequires: automake BuildRequires: systemd-rpm-macros