[Crash-utility] [PATCH] Obtain KASLR offset from early S390X dumps

Mikhail Zaslonko zaslonko at linux.ibm.com
Mon Nov 25 14:52:01 UTC 2019


If the kernel crashes before vmcoreinfo initialization, there is
no way to extract KASLR offset for such early s390 dumps.
With a new s390 kernel patch, the KASLR offset will be stored in the lowcore
memory during early boot and then overwritten after vmcoreinfo is
initialized.
This patch allows crash to identify the KASLR offset stored in lowcore
memory for s390 dumps.

Signed-off-by: Mikhail Zaslonko <zaslonko at linux.ibm.com>
---
 s390x.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/s390x.c b/s390x.c
index 4a1a466..d2c6702 100644
--- a/s390x.c
+++ b/s390x.c
@@ -46,6 +46,8 @@
 
 #define S390X_PSW_MASK_PSTATE	0x0001000000000000UL
 
+#define S390X_LC_VMCORE_INFO	0xe0c
+
 /*
  * Flags for Region and Segment table entries.
  */
@@ -460,6 +462,8 @@ static void s390x_check_live(void)
 void
 s390x_init(int when)
 {
+	ulong s390x_lc_kaslr;
+
 	switch (when)
 	{
 	case SETUP_ENV:
@@ -486,6 +490,23 @@ s390x_init(int when)
 		machdep->verify_paddr = generic_verify_paddr;
 		machdep->get_kvaddr_ranges = s390x_get_kvaddr_ranges;
 		machdep->ptrs_per_pgd = PTRS_PER_PGD;
+		if (!(kt->flags & RELOC_SET)) {
+			/* Read the value from well-known lowcore location*/
+			readmem(S390X_LC_VMCORE_INFO, PHYSADDR, &s390x_lc_kaslr,
+				sizeof(s390x_lc_kaslr), "s390x_lc_kaslr",
+				FAULT_ON_ERROR);
+			/* Check for explicit kaslr offset flag */
+			if (s390x_lc_kaslr & 0x1UL) {
+				/* Drop the last bit to get an offset value */
+				s390x_lc_kaslr &= ~(0x1UL);
+				/* Make sure that the offset is aligned by 0x1000 */
+				if (s390x_lc_kaslr && !(s390x_lc_kaslr & 0xfff)) {
+					kt->relocate = s390x_lc_kaslr * (-1);
+					kt->flags |= RELOC_SET;
+					kt->flags2 |= KASLR;
+				}
+			}
+		}
 		break;
 
 	case PRE_GDB:
-- 
2.17.1





More information about the Crash-utility mailing list