Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: WANG Chao <chaowang@redhat.com>
To: kexec@lists.infradead.org
Cc: dyoung@redhat.com, ebiederm@xmission.com, vgoyal@redhat.com
Subject: [PATCH v2] x86, kaslr: Kernel base can be randomized at 0-1G offset.
Date: Fri, 14 Mar 2014 16:20:18 +0800	[thread overview]
Message-ID: <1394785218-25168-1-git-send-email-chaowang@redhat.com> (raw)

With kASLR enabled (CONFIG_RANDOMIZED_BASE=y), kernel virtual address
base is PAGE_OFFSET plus a randomized offset from 0 to 1G.

Current kexec-tools gets kernel vaddr and size from /proc/kcore. It
assumes kernel vaddr start/end is within the range [0,512M). If kaslr
enabled, kernel vaddr start/end will stay at [0+offset, 512M+offset).

To adapt kaslr, introduce a new macro X86_64_RANDOMIZED_BASE_MAX_OFFSET
to address the max offset and use this macro to filter out the kernel
text PT_LOAD from /proc/kcore.

Signed-off-by: WANG Chao <chaowang@redhat.com>
---
 kexec/arch/i386/crashdump-x86.c | 3 ++-
 kexec/arch/i386/crashdump-x86.h | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c
index cb19e7d..1e6d3a3 100644
--- a/kexec/arch/i386/crashdump-x86.c
+++ b/kexec/arch/i386/crashdump-x86.c
@@ -156,7 +156,8 @@ static int get_kernel_vaddr_and_size(struct kexec_info *UNUSED(info),
 
 			/* Look for kernel text mapping header. */
 			if ((saddr >= X86_64__START_KERNEL_map) &&
-			    (eaddr <= X86_64__START_KERNEL_map + X86_64_KERNEL_TEXT_SIZE)) {
+			    (saddr <= X86_64__START_KERNEL_map + X86_64_RANDOMIZE_BASE_MAX_OFFSET) &&
+			    (eaddr - saddr  < X86_64_KERNEL_TEXT_SIZE)) {
 				saddr = _ALIGN_DOWN(saddr, X86_64_KERN_VADDR_ALIGN);
 				elf_info->kern_vaddr_start = saddr;
 				size = eaddr - saddr;
diff --git a/kexec/arch/i386/crashdump-x86.h b/kexec/arch/i386/crashdump-x86.h
index e68b626..71a09f8 100644
--- a/kexec/arch/i386/crashdump-x86.h
+++ b/kexec/arch/i386/crashdump-x86.h
@@ -15,6 +15,9 @@ int load_crashdump_segments(struct kexec_info *info, char *mod_cmdline,
 #define X86_64_PAGE_OFFSET_PRE_2_6_27	0xffff810000000000ULL
 #define X86_64_PAGE_OFFSET		0xffff880000000000ULL
 
+/* kASLR - Kernel base offset could be randomized up to 1G */
+#define X86_64_RANDOMIZE_BASE_MAX_OFFSET	0x40000000
+
 #define X86_64_MAXMEM        		0x3fffffffffffUL
 
 /* Kernel text size */
-- 
1.8.5.3


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

             reply	other threads:[~2014-03-14  8:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-14  8:20 WANG Chao [this message]
2014-03-17  3:27 ` [PATCH v2] x86, kaslr: Kernel base can be randomized at 0-1G offset Dave Young
2014-03-17 12:56 ` Vivek Goyal
2014-03-19  7:05   ` WANG Chao
2014-03-19 13:33     ` Vivek Goyal
2014-03-20  5:46       ` WANG Chao
2014-03-20 15:18         ` Vivek Goyal

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=1394785218-25168-1-git-send-email-chaowang@redhat.com \
    --to=chaowang@redhat.com \
    --cc=dyoung@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=kexec@lists.infradead.org \
    --cc=vgoyal@redhat.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