kexec.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Baoquan He <bhe@redhat.com>
To: kexec@lists.infradead.org
Cc: kumagai-atsushi@mxc.nes.nec.co.jp, thgarnie@google.com,
	Baoquan He <bhe@redhat.com>
Subject: [PATCH 3/3] makedumpfile: Add support for MM randomization
Date: Mon, 29 Aug 2016 16:54:22 +0800	[thread overview]
Message-ID: <1472460862-29842-4-git-send-email-bhe@redhat.com> (raw)
In-Reply-To: <1472460862-29842-1-git-send-email-bhe@redhat.com>

In kernel patchset "x86/mm: memory area address KASLR", PAGE_OFFSET,
VMALLOC_START and VMEMMAP_START are all randomized. Please check below
link:
	https://lwn.net/Articles/692289/

And these need be exported into vmcoreinfo and tell makedumpfile. In
this patch get and handle them to support MM randomization.

Signed-off-by: Baoquan He <bhe@redhat.com>
---
 arch/x86_64.c  | 26 +++++++++-----------------
 makedumpfile.c | 29 ++++++++++++++++++++++++++++-
 makedumpfile.h |  3 +++
 3 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/arch/x86_64.c b/arch/x86_64.c
index ddf7be6..ff787cc 100644
--- a/arch/x86_64.c
+++ b/arch/x86_64.c
@@ -146,8 +146,9 @@ get_machdep_info_x86_64(void)
 	return TRUE;
 }
 
-int
-get_versiondep_info_x86_64(void)
+#define VMALLOC_SIZE            (0x200000000000)
+#define VMEMMAP_SIZE            (0x10000000000)
+int get_versiondep_info_x86_64(void)
 {
 	/*
 	 * On linux-2.6.26, MAX_PHYSMEM_BITS is changed to 44 from 40.
@@ -159,22 +160,13 @@ get_versiondep_info_x86_64(void)
 	else
 		info->max_physmem_bits  = _MAX_PHYSMEM_BITS_2_6_31;
 
-	if (info->kernel_version < KERNEL_VERSION(2, 6, 27))
-		info->page_offset = __PAGE_OFFSET_ORIG;
-	else
-		info->page_offset = __PAGE_OFFSET_2_6_27;
+	info->page_offset = NUMBER(page_offset);
 
-	if (info->kernel_version < KERNEL_VERSION(2, 6, 31)) {
-		info->vmalloc_start = VMALLOC_START_ORIG;
-		info->vmalloc_end   = VMALLOC_END_ORIG;
-		info->vmemmap_start = VMEMMAP_START_ORIG;
-		info->vmemmap_end   = VMEMMAP_END_ORIG;
-	} else {
-		info->vmalloc_start = VMALLOC_START_2_6_31;
-		info->vmalloc_end   = VMALLOC_END_2_6_31;
-		info->vmemmap_start = VMEMMAP_START_2_6_31;
-		info->vmemmap_end   = VMEMMAP_END_2_6_31;
-	}
+
+	info->vmalloc_start = NUMBER(vmalloc_start);
+	info->vmalloc_end   = info->vmalloc_start + VMALLOC_SIZE - 1;
+	info->vmemmap_start = NUMBER(vmemmap_start);
+	info->vmemmap_end   = info->vmemmap_start + VMEMMAP_SIZE - 1;
 
 	return TRUE;
 }
diff --git a/makedumpfile.c b/makedumpfile.c
index 2713f8a..6b0c6ab 100644
--- a/makedumpfile.c
+++ b/makedumpfile.c
@@ -1985,6 +1985,7 @@ get_value_for_old_linux(void)
 			NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) =
 			PAGE_BUDDY_MAPCOUNT_VALUE_v2_6_39_to_latest_version;
 	}
+	ERRMSG("info->kernel_version=%d\n", info->kernel_version);
 #ifdef __x86_64__
 	if (NUMBER(KERNEL_IMAGE_SIZE) == NOT_FOUND_NUMBER) {
 		if (info->kernel_version < KERNEL_VERSION(2, 6, 26))
@@ -1992,6 +1993,26 @@ get_value_for_old_linux(void)
 		else
 			NUMBER(KERNEL_IMAGE_SIZE) = KERNEL_IMAGE_SIZE_2_6_26;
 	}
+	if (NUMBER(page_offset) == NOT_FOUND_NUMBER) {
+		if (info->kernel_version < KERNEL_VERSION(2, 6, 27))
+			NUMBER(page_offset) = __PAGE_OFFSET_ORIG;
+		else
+			NUMBER(page_offset) = __PAGE_OFFSET_2_6_27;
+	}
+	if (NUMBER(vmalloc_start) == NOT_FOUND_NUMBER) {
+		if (info->kernel_version < KERNEL_VERSION(2, 6, 31)) {
+			NUMBER(vmalloc_start) = VMALLOC_START_ORIG;
+		} else {
+			NUMBER(vmalloc_start) = VMALLOC_START_2_6_31;
+		}
+	}
+	if (NUMBER(vmemmap_start) == NOT_FOUND_NUMBER) {
+		if (info->kernel_version < KERNEL_VERSION(2, 6, 31))
+			NUMBER(vmemmap_start) = VMEMMAP_START_ORIG;
+		else
+			NUMBER(vmemmap_start) = VMEMMAP_START_2_6_31;
+	}
+
 #endif
 	if (SIZE(pageflags) == NOT_FOUND_STRUCTURE) {
 		if (info->kernel_version >= KERNEL_VERSION(2, 6, 27))
@@ -2249,6 +2270,9 @@ write_vmcoreinfo_data(void)
 
 	WRITE_NUMBER("PAGE_BUDDY_MAPCOUNT_VALUE", PAGE_BUDDY_MAPCOUNT_VALUE);
 	WRITE_NUMBER("KERNEL_IMAGE_SIZE", KERNEL_IMAGE_SIZE);
+	WRITE_NUMBER("PAGE_OFFSET", page_offset);
+	WRITE_NUMBER("VMALLOC_START", vmalloc_start);
+	WRITE_NUMBER("VMEMMAP_START", vmemmap_start);
 
 	WRITE_NUMBER("HUGETLB_PAGE_DTOR", HUGETLB_PAGE_DTOR);
 
@@ -2595,6 +2619,9 @@ read_vmcoreinfo(void)
 
 	READ_NUMBER("PAGE_BUDDY_MAPCOUNT_VALUE", PAGE_BUDDY_MAPCOUNT_VALUE);
 	READ_NUMBER("KERNEL_IMAGE_SIZE", KERNEL_IMAGE_SIZE);
+	READ_NUMBER("PAGE_OFFSET", page_offset);
+	READ_NUMBER("VMALLOC_START", vmalloc_start);
+	READ_NUMBER("VMEMMAP_START", vmemmap_start);
 
 	READ_NUMBER("HUGETLB_PAGE_DTOR", HUGETLB_PAGE_DTOR);
 
@@ -3826,7 +3853,7 @@ initial(void)
 		debug_info = TRUE;
 	}
 
-	info->kernel_version = get_kernel_version(info.release);
+	info->kernel_version = get_kernel_version(info->release);
 	if (info->kernel_version == FALSE) {
 		ERRMSG("Can't get the kernel version.\n");
 		return FALSE;
diff --git a/makedumpfile.h b/makedumpfile.h
index 533e5b8..0e34fae 100644
--- a/makedumpfile.h
+++ b/makedumpfile.h
@@ -1685,6 +1685,9 @@ struct number_table {
 
 	long	PAGE_BUDDY_MAPCOUNT_VALUE;
 	long	KERNEL_IMAGE_SIZE;
+	long	page_offset;
+	long	vmalloc_start;
+	long	vmemmap_start;
 	long	SECTION_SIZE_BITS;
 	long	MAX_PHYSMEM_BITS;
 	long    HUGETLB_PAGE_DTOR;
-- 
2.5.5


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  parent reply	other threads:[~2016-08-29  8:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-29  8:54 [PATCH 0/3] makedumpfile: Add support of mm randomization Baoquan He
2016-08-29  8:54 ` [PATCH 1/3] makedumpfile: Get info->kernel_version from SYMBOL(init_uts_ns) earlier Baoquan He
2016-08-29  8:54 ` [PATCH 2/3] makedumpfile: Move get_versiondep_info calling earlier Baoquan He
2016-08-29  8:54 ` Baoquan He [this message]
2016-08-31  7:56   ` [PATCH 3/3] makedumpfile: Add support for MM randomization Atsushi Kumagai
2016-09-30  4:56     ` Baoquan He
2016-10-04  1:40       ` Atsushi Kumagai
2016-10-04 13:09         ` Baoquan He
2016-08-29  9:03 ` [PATCH 0/3] makedumpfile: Add support of mm randomization Baoquan He
2016-09-22  8:45 ` Dave Young
2016-09-22  8:48   ` Dave Young
2016-09-22  8:57     ` Baoquan He
2016-09-22  9:03       ` Dave Young
2016-09-22  9:07         ` Baoquan He
2016-09-23  2:38           ` Dave Young

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1472460862-29842-4-git-send-email-bhe@redhat.com \
    --to=bhe@redhat.com \
    --cc=kexec@lists.infradead.org \
    --cc=kumagai-atsushi@mxc.nes.nec.co.jp \
    --cc=thgarnie@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).