Blob Blame History Raw
From 90cc28fc9ab0a0076bcd9120b4f791401655280d Mon Sep 17 00:00:00 2001
Message-Id: <90cc28fc9ab0a0076bcd9120b4f791401655280d.1496033260.git.panand@redhat.com>
In-Reply-To: <302c16ede3723264ca0abb5eef9c9f553ffcfbd7.1496033260.git.panand@redhat.com>
References: <302c16ede3723264ca0abb5eef9c9f553ffcfbd7.1496033260.git.panand@redhat.com>
From: "Hatayama, Daisuke" <d.hatayama@jp.fujitsu.com>
Date: Tue, 23 May 2017 02:52:51 +0000
Subject: [PATCH 3/3] sadump: set info->page_size before cache_init()

Currently, makedumpfile results in Segmentation fault on sadump dump
files as follows:

    # LANG=C makedumpfile -f --message-level=31 -ld31 -x vmlinux ./sadump_vmcore sadump_vmcore-ld31
    sadump: read dump device as single partition
    sadump: single partition configuration
    page_size    : 4096
    sadump: timezone information is missing
    Segmentation fault

By bisect, I found that this issue is caused by the following commit
that moves invocation of cache_init() in initial() a bit early:

    # git bisect bad
    8e2834bac4f62da3894da297f083068431be6d80 is the first bad commit
    commit 8e2834bac4f62da3894da297f083068431be6d80
    Author: Pratyush Anand <panand@redhat.com>
    Date:   Thu Mar 2 17:37:11 2017 +0900

        [PATCH v3 2/7] initial(): call cache_init() a bit early

        Call cache_init() before get_kcore_dump_loads(), because latter uses
        cache_search().

        Call path is like this :
        get_kcore_dump_loads() -> process_dump_load() -> vaddr_to_paddr() ->
        vtop4_x86_64() -> readmem() -> cache_search()

        Signed-off-by: Pratyush Anand <panand@redhat.com>

    :100644 100644 6942047199deb09dd1fff2121e264584dbb05587 3b8e9810468de26b0d8b73d456f0bd4f3d3aa2fe M      makedumpfile.c

In this timing, on sadump vmcores, info->page_size has not been
initialized yet so has 0. So, malloc() in cache_init() returns a chunk
of 0 size. A bit later, info->page_size is initialized with 4096.
Later processing on cache.c behaves assuming the chunk size is 8 *
4096. This destroys objects allocated after the chunk, resulting in
the above Segmentation fault.

To fix this issue, this commit moves setting info->page_size before
cache_init().

Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Cc: Pratyush Anand <panand@redhat.com>
---
 makedumpfile.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/makedumpfile-1.6.1/makedumpfile.c b/makedumpfile-1.6.1/makedumpfile.c
index 9babf1a07154..2e4286c83b8f 100644
--- a/makedumpfile-1.6.1/makedumpfile.c
+++ b/makedumpfile-1.6.1/makedumpfile.c
@@ -3921,6 +3921,9 @@ initial(void)
 	if (!get_value_for_old_linux())
 		return FALSE;
 
+	if (info->flag_sadump && !set_page_size(sadump_page_size()))
+			return FALSE;
+
 	if (!is_xen_memory() && !cache_init())
 		return FALSE;
 
@@ -3949,9 +3952,6 @@ initial(void)
 			return FALSE;
 		}
 
-		if (!set_page_size(sadump_page_size()))
-			return FALSE;
-
 		if (!sadump_initialize_bitmap_memory())
 			return FALSE;
 
-- 
2.9.3