From: Bhupesh Sharma <bhsharma@redhat.com>
To: kexec@lists.infradead.org
Cc: bhsharma@redhat.com, bhupesh.linux@gmail.com, k-hagio@ab.jp.nec.com
Subject: [PATCH 1/2] arm64: Get 'info->page_offset' from PT_LOAD segments to support KASLR boot cases
Date: Thu, 19 Jul 2018 11:13:40 +0530 [thread overview]
Message-ID: <1531979021-31780-2-git-send-email-bhsharma@redhat.com> (raw)
In-Reply-To: <1531979021-31780-1-git-send-email-bhsharma@redhat.com>
The existing methodology to obtain 'info->page_offset' from reading
_stext symbol (from kallsyms) doesn't work well in KASLR boot cases on
arm64 machines as the PAGE_OFFSET (or the virtual address which
indicates the start of the linear region) can be randomized as well
on basis of the kaslr-seed.
Since the value of PAGE_OFFSET inside the kernel is randomized in such
cases and there is no existing mechanism of conveying this value from
kernel-space to user-space, so we can use the method used by archs like
x86_64 to generate the 'info->page_offset' value from the PT_LOAD
segments by subtracting the phy_addr from virt_addr of a PT_LOAD
segment.
This approach works fine both with KASLR and non-KASLR boot cases.
I tested this on my qualcomm-amberwing board. Here are some logs from
the KASLR boot cases:
- Verify that the EFI firmware supports 'kaslr-seed':
chosen {
kaslr-seed = <0x0 0x0>;
<..snip..>
};
- Verify that '--mem-usage' works well after this fix as well (I used
kernel 4.18.0-rc4+ for my checks):
The kernel version is not supported.
The makedumpfile operation may be incomplete.
TYPE PAGES EXCLUDABLE DESCRIPTION
----------------------------------------------------------------------
ZERO 4396 yes Pages filled
with zero
NON_PRI_CACHE 27859 yes Cache pages
without private flag
PRI_CACHE 18490 yes Cache pages with
private flag
USER 2728 yes User process
pages
FREE 1465848 yes Free pages
KERN_DATA 18537 no Dumpable kernel
data
page size: 65536
Total pages on system: 1537858
Total size on system: 100785061888 Byte
Signed-off-by: Bhupesh Sharma <bhsharma@redhat.com>
---
arch/arm64.c | 23 ++++++++++++++++++-----
common.h | 1 +
makedumpfile.h | 1 +
3 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/arch/arm64.c b/arch/arm64.c
index 2fd3e1874376..9e8c77c76935 100644
--- a/arch/arm64.c
+++ b/arch/arm64.c
@@ -265,6 +265,9 @@ get_xen_info_arm64(void)
int
get_versiondep_info_arm64(void)
{
+ int i;
+ unsigned long long phys_start;
+ unsigned long long virt_start;
ulong _stext;
_stext = get_stext_symbol();
@@ -289,12 +292,22 @@ get_versiondep_info_arm64(void)
return FALSE;
}
- info->page_offset = (0xffffffffffffffffUL) << (va_bits - 1);
-
- DEBUG_MSG("page_offset=%lx, va_bits=%d\n", info->page_offset,
- va_bits);
+ if (get_num_pt_loads()) {
+ for (i = 0;
+ get_pt_load(i, &phys_start, NULL, &virt_start, NULL);
+ i++) {
+ if (virt_start != NOT_KV_ADDR
+ && virt_start < __START_KERNEL_map
+ && phys_start != NOT_PADDR && phys_start != NOT_PADDR_ARM64) {
+ info->page_offset = virt_start - phys_start;
+ DEBUG_MSG("info->page_offset: %lx, VA_BITS: %d\n",
+ info->page_offset, va_bits);
+ return TRUE;
+ }
+ }
+ }
- return TRUE;
+ return FALSE;
}
/*
diff --git a/common.h b/common.h
index 6e2f657a79c7..a8181777dbb7 100644
--- a/common.h
+++ b/common.h
@@ -48,6 +48,7 @@
#define NOT_MEMMAP_ADDR (0x0)
#define NOT_KV_ADDR (0x0)
#define NOT_PADDR (ULONGLONG_MAX)
+#define NOT_PADDR_ARM64 (0x0000000010a80000UL)
#define BADADDR ((ulong)(-1))
#endif /* COMMON_H */
diff --git a/makedumpfile.h b/makedumpfile.h
index 5ff94b8e4ac6..5297279f0f3b 100644
--- a/makedumpfile.h
+++ b/makedumpfile.h
@@ -2020,6 +2020,7 @@ struct domain_list {
#define MFNS_PER_FRAME (info->page_size / sizeof(unsigned long))
#ifdef __aarch64__
+#define __START_KERNEL_map (0xffffffff80000000UL)
unsigned long long kvtop_xen_arm64(unsigned long kvaddr);
#define kvtop_xen(X) kvtop_xen_arm64(X)
#endif /* aarch64 */
--
2.7.4
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
next prev parent reply other threads:[~2018-07-19 5:44 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-19 5:43 [PATCH 0/2] arm64, makedumpfile: A couple of KASLR related fixes Bhupesh Sharma
2018-07-19 5:43 ` Bhupesh Sharma [this message]
2018-07-20 21:48 ` [PATCH 1/2] arm64: Get 'info->page_offset' from PT_LOAD segments to support KASLR boot cases Kazuhito Hagio
2018-07-22 7:44 ` Bhupesh Sharma
2018-07-23 16:45 ` Kazuhito Hagio
2018-07-24 5:17 ` Bhupesh Sharma
2018-08-15 19:55 ` Bhupesh Sharma
2018-08-20 15:24 ` Kazuhito Hagio
2018-08-20 19:50 ` Bhupesh Sharma
2018-07-19 5:43 ` [PATCH 2/2] arm64: Add runtime kaslr offset if it exists Bhupesh Sharma
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=1531979021-31780-2-git-send-email-bhsharma@redhat.com \
--to=bhsharma@redhat.com \
--cc=bhupesh.linux@gmail.com \
--cc=k-hagio@ab.jp.nec.com \
--cc=kexec@lists.infradead.org \
/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