check for invalid physical address of /proc/kcore when finding max_paddr

Backport from upstream.

commit 38d921a2ef50ebd36258097553626443ffe27496
Author: Coiby Xu <coxu@redhat.com>
Date:   Tue Jun 15 18:26:31 2021 +0800

    [PATCH] check for invalid physical address of /proc/kcore when finding max_paddr

    Kernel commit 464920104bf7adac12722035bfefb3d772eb04d8 ("/proc/kcore:
    update physical address for kcore ram and text") sets an invalid paddr
    (0xffffffffffffffff = -1) for PT_LOAD segments of not direct mapped
    regions:

      $ readelf -l /proc/kcore
      ...
      Program Headers:
        Type           Offset             VirtAddr           PhysAddr
                       FileSiz            MemSiz              Flags  Align
        NOTE           0x0000000000000120 0x0000000000000000 0x0000000000000000
                       0x0000000000002320 0x0000000000000000         0x0
        LOAD           0x1000000000010000 0xd000000000000000 0xffffffffffffffff
                                                             ^^^^^^^^^^^^^^^^^^
                       0x0001f80000000000 0x0001f80000000000  RWE    0x10000

    makedumpfile uses max_paddr to calculate the number of sections for
    sparse memory model thus wrong number is obtained based on max_paddr
    (-1).  This error could lead to the failure of copying /proc/kcore
    for RHEL-8.5 on ppc64le machine [1]:

      $ makedumpfile /proc/kcore vmcore1
      get_mem_section: Could not validate mem_section.
      get_mm_sparsemem: Can't get the address of mem_section.

      makedumpfile Failed.

    Let's check if the phys_start of the segment is a valid physical
    address to fix this problem.

    [1] https://bugzilla.redhat.com/show_bug.cgi?id=1965267

    Reported-by: Xiaoying Yan <yiyan@redhat.com>
    Signed-off-by: Coiby Xu <coxu@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
Acked-by: Kairui Song <kasong@redhat.com>
This commit is contained in:
Tao Liu 2021-06-22 21:30:26 +08:00 committed by Kairui Song
parent 18b9b763de
commit 0feb109818
2 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,60 @@
From 38d921a2ef50ebd36258097553626443ffe27496 Mon Sep 17 00:00:00 2001
From: Coiby Xu <coxu@redhat.com>
Date: Tue, 15 Jun 2021 18:26:31 +0800
Subject: [PATCH] check for invalid physical address of /proc/kcore
when finding max_paddr
Kernel commit 464920104bf7adac12722035bfefb3d772eb04d8 ("/proc/kcore:
update physical address for kcore ram and text") sets an invalid paddr
(0xffffffffffffffff = -1) for PT_LOAD segments of not direct mapped
regions:
$ readelf -l /proc/kcore
...
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
NOTE 0x0000000000000120 0x0000000000000000 0x0000000000000000
0x0000000000002320 0x0000000000000000 0x0
LOAD 0x1000000000010000 0xd000000000000000 0xffffffffffffffff
^^^^^^^^^^^^^^^^^^
0x0001f80000000000 0x0001f80000000000 RWE 0x10000
makedumpfile uses max_paddr to calculate the number of sections for
sparse memory model thus wrong number is obtained based on max_paddr
(-1). This error could lead to the failure of copying /proc/kcore
for RHEL-8.5 on ppc64le machine [1]:
$ makedumpfile /proc/kcore vmcore1
get_mem_section: Could not validate mem_section.
get_mm_sparsemem: Can't get the address of mem_section.
makedumpfile Failed.
Let's check if the phys_start of the segment is a valid physical
address to fix this problem.
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1965267
Reported-by: Xiaoying Yan <yiyan@redhat.com>
Signed-off-by: Coiby Xu <coxu@redhat.com>
---
elf_info.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/makedumpfile-1.6.9/elf_info.c b/makedumpfile-1.6.9/elf_info.c
index e8affb7..bc24083 100644
--- a/makedumpfile-1.6.9/elf_info.c
+++ b/makedumpfile-1.6.9/elf_info.c
@@ -628,7 +628,7 @@ get_max_paddr(void)
for (i = 0; i < num_pt_loads; i++) {
pls = &pt_loads[i];
- if (max_paddr < pls->phys_end)
+ if (pls->phys_start != NOT_PADDR && max_paddr < pls->phys_end)
max_paddr = pls->phys_end;
}
return max_paddr;
--
2.29.2

View File

@ -101,6 +101,7 @@ Requires: systemd-udev%{?_isa}
# Patches 601 onward are generic patches # Patches 601 onward are generic patches
# #
Patch601: ./kexec-tools-2.0.22-makedumpfile-Increase-SECTION_MAP_LAST_BIT-to-5.patch Patch601: ./kexec-tools-2.0.22-makedumpfile-Increase-SECTION_MAP_LAST_BIT-to-5.patch
Patch602: ./kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-finding-max_paddr.patch
%description %description
kexec-tools provides /sbin/kexec binary that facilitates a new kexec-tools provides /sbin/kexec binary that facilitates a new
@ -117,6 +118,7 @@ tar -z -x -v -f %{SOURCE9}
tar -z -x -v -f %{SOURCE19} tar -z -x -v -f %{SOURCE19}
%patch601 -p1 %patch601 -p1
%patch602 -p1
%ifarch ppc %ifarch ppc
%define archdef ARCH=ppc %define archdef ARCH=ppc