From 900190de6b67b2de410cfc8023c1b198a416ceb3 Mon Sep 17 00:00:00 2001 From: Kazuhito Hagio Date: Mon, 22 Jul 2024 14:31:43 +0900 Subject: [PATCH] [PATCH] Workaround for segfault by "makedumpfile --mem-usage" on PPC64 "makedumpfile --mem-usage /proc/kcore" can cause a segmentation fault on PPC64, because the readmem() of the following code path uses cache before it's initialized in initial(). show_mem_usage get_page_offset get_versiondep_info_ppc64 readmem ... initial cache_init The get_page_offset() is needed to get vmcoreinfo from /proc/kcore data, so we can avoid calling it when a vmcoreinfo exists in the ELF NOTE segment of /proc/kcore, i.e. on Linux 4.19 and later. (Note: for older kernels, we will need another way to fix it.) Reported-by: Lichen Liu Signed-off-by: Kazuhito Hagio --- makedumpfile.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/makedumpfile.c b/makedumpfile.c index 5b34712..7d1dfcc 100644 --- a/makedumpfile.c +++ b/makedumpfile.c @@ -12019,14 +12019,14 @@ int show_mem_usage(void) DEBUG_MSG("Read vmcoreinfo from NOTE segment: %d\n", vmcoreinfo); } - if (!get_page_offset()) - return FALSE; + if (!vmcoreinfo) { + if (!get_page_offset()) + return FALSE; - /* paddr_to_vaddr() on arm64 needs phys_base. */ - if (!get_phys_base()) - return FALSE; + /* paddr_to_vaddr() on arm64 needs phys_base. */ + if (!get_phys_base()) + return FALSE; - if (!vmcoreinfo) { if (!get_sys_kernel_vmcoreinfo(&vmcoreinfo_addr, &vmcoreinfo_len)) return FALSE; -- 2.45.2