[Crash-utility] [PATCH v3 1/2] Call x86_64_kvtop during symtab_init() for sadump

Takao Indoh indou.takao at jp.fujitsu.com
Thu Oct 19 09:39:30 UTC 2017


This patch changes x86_64_kvtop() so that it can be called during
symtab_init().

To solve kaslr problem of sadump, kaslr offset and phys_base need to be
calculated before symbol data is loaded. This calculation needs
translation of kernel virtual address to physical address. Current
x86_64_kvtop() implementation tries to use x86_64_VTOP for translation
at first, but this does not work for this purpose because x86_64_VTOP
uses phys_base. x86_64_kvtop() need to be changed to skip x86_64_VTOP()
during sadump initialization.

Signed-off-by: Takao Indoh <indou.takao at jp.fujitsu.com>
---
 x86_64.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/x86_64.c b/x86_64.c
index 6e60dda..2f9e6db 100644
--- a/x86_64.c
+++ b/x86_64.c
@@ -194,6 +194,9 @@ x86_64_init(int when)
 			machdep->machspec->kernel_image_size = dtol(string, QUIET, NULL);
 			free(string);
 		}
+		if (SADUMP_DUMPFILE())
+			/* Need for calculation of kaslr_offset and phys_base */
+			machdep->kvtop = x86_64_kvtop;
 		break;
 
 	case PRE_GDB:
@@ -2019,6 +2022,22 @@ x86_64_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbo
 	ulong pte;
 	physaddr_t physpage;
 
+	if (SADUMP_DUMPFILE() && !(machdep->flags & KSYMS_START)) {
+		/*
+		 * In the case of sadump, to calculate kaslr_offset and
+		 * phys_base, kvtop is called during symtab_init(). In this
+		 * stage phys_base is not initialized yet and x86_64_VTOP()
+		 * does not work. Jump to the code of pagetable translation.
+		 */
+		FILL_PML4();
+		pml4 = ((ulong *)machdep->machspec->pml4) + pml4_index(kvaddr);
+		if (verbose) {
+			fprintf(fp, "PML4 DIRECTORY: %lx\n", vt->kernel_pgd[0]);
+			fprintf(fp, "PAGE DIRECTORY: %lx\n", *pml4);
+		}
+		goto start_vtop_with_pagetable;
+	}
+
         if (!IS_KVADDR(kvaddr))
                 return FALSE;
 
@@ -2065,6 +2084,8 @@ x86_64_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbo
                		fprintf(fp, "PAGE DIRECTORY: %lx\n", *pml4);
 		}
 	}
+
+start_vtop_with_pagetable:
 	if (!(*pml4) & _PAGE_PRESENT)
 		goto no_kpage;
 	pgd_paddr = (*pml4) & PHYSICAL_PAGE_MASK;
-- 
2.9.5





More information about the Crash-utility mailing list