diff options
author | Kazuhito Hagio <k-hagio@ab.jp.nec.com> | 2019-12-17 11:12:50 -0500 |
---|---|---|
committer | Kazuhito Hagio <k-hagio-ab@nec.com> | 2020-01-07 11:00:28 -0500 |
commit | c6992684b51ba9604d50016f36c9139bf54ae03b (patch) | |
tree | 5c53d19d209968982561398eb87695897735f047 | |
parent | 49baecc7c13fbfc62679021bc006103dd01c7eb3 (diff) |
[PATCH] Generalize get_kaslr_offset_arm64() for other architectures
Generalize the get_kaslr_offset_arm64() and rename it to
get_kaslr_offset_general() for use by other architectures
supporting KASLR.
Also, modify the confusing comment in the function and its
x86_64 version.
Signed-off-by: Kazuhito Hagio <k-hagio@ab.jp.nec.com>
-rw-r--r-- | arch/arm64.c | 61 | ||||
-rw-r--r-- | arch/x86_64.c | 8 | ||||
-rw-r--r-- | makedumpfile.c | 60 | ||||
-rw-r--r-- | makedumpfile.h | 4 |
4 files changed, 66 insertions, 67 deletions
diff --git a/arch/arm64.c b/arch/arm64.c index 3516b34..43164cc 100644 --- a/arch/arm64.c +++ b/arch/arm64.c @@ -205,67 +205,6 @@ get_phys_base_arm64(void) return FALSE; } -unsigned long -get_kaslr_offset_arm64(unsigned long vaddr) -{ - unsigned int i; - char buf[BUFSIZE_FGETS], *endp; - static unsigned long _text = NOT_FOUND_SYMBOL; - static unsigned long _end = NOT_FOUND_SYMBOL; - - if (!info->kaslr_offset && info->file_vmcoreinfo) { - if (fseek(info->file_vmcoreinfo, 0, SEEK_SET) < 0) { - ERRMSG("Can't seek the vmcoreinfo file(%s). %s\n", - info->name_vmcoreinfo, strerror(errno)); - return FALSE; - } - - while (fgets(buf, BUFSIZE_FGETS, info->file_vmcoreinfo)) { - i = strlen(buf); - if (!i) - break; - if (buf[i - 1] == '\n') - buf[i - 1] = '\0'; - if (strncmp(buf, STR_KERNELOFFSET, - strlen(STR_KERNELOFFSET)) == 0) { - info->kaslr_offset = - strtoul(buf+strlen(STR_KERNELOFFSET),&endp,16); - DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset); - } - } - } - if (!info->kaslr_offset) - return 0; - - if (_text == NOT_FOUND_SYMBOL) { - /* - * Currently, the return value of this function is used in - * resolve_config_entry() only, and in that case, we must - * have a vmlinux. - */ - if (info->name_vmlinux) { - _text = get_symbol_addr("_text"); - _end = get_symbol_addr("_end"); - } - DEBUG_MSG("_text: %lx, _end: %lx\n", _text, _end); - if (_text == NOT_FOUND_SYMBOL || _end == NOT_FOUND_SYMBOL) { - ERRMSG("Cannot determine _text and _end address\n"); - return FALSE; - } - } - - if (_text <= vaddr && vaddr <= _end) { - DEBUG_MSG("info->kaslr_offset: %lx\n", info->kaslr_offset); - return info->kaslr_offset; - } else { - /* - * TODO: we need to check if it is vmalloc/vmmemmap/module - * address, we will have different offset - */ - return 0; - } -} - ulong get_stext_symbol(void) { diff --git a/arch/x86_64.c b/arch/x86_64.c index 876644f..7a2c05c 100644 --- a/arch/x86_64.c +++ b/arch/x86_64.c @@ -77,14 +77,14 @@ get_kaslr_offset_x86_64(unsigned long vaddr) else kernel_image_size = KERNEL_IMAGE_SIZE_KASLR_ORIG; + /* + * Returns the kaslr offset only if the vaddr needs it to be added, + * i.e. only kernel text address for now. Otherwise returns 0. + */ if (vaddr >= __START_KERNEL_map && vaddr < __START_KERNEL_map + kernel_image_size) return info->kaslr_offset; else - /* - * TODO: we need to check if it is vmalloc/vmmemmap/module - * address, we will have different offset - */ return 0; } diff --git a/makedumpfile.c b/makedumpfile.c index 7586d7c..332b804 100644 --- a/makedumpfile.c +++ b/makedumpfile.c @@ -3945,6 +3945,66 @@ free_for_parallel() } } +unsigned long +get_kaslr_offset_general(unsigned long vaddr) +{ + unsigned int i; + char buf[BUFSIZE_FGETS], *endp; + static unsigned long _text = NOT_FOUND_SYMBOL; + static unsigned long _end = NOT_FOUND_SYMBOL; + + if (!info->kaslr_offset && info->file_vmcoreinfo) { + if (fseek(info->file_vmcoreinfo, 0, SEEK_SET) < 0) { + ERRMSG("Can't seek the vmcoreinfo file(%s). %s\n", + info->name_vmcoreinfo, strerror(errno)); + return FALSE; + } + + while (fgets(buf, BUFSIZE_FGETS, info->file_vmcoreinfo)) { + i = strlen(buf); + if (!i) + break; + if (buf[i - 1] == '\n') + buf[i - 1] = '\0'; + if (strncmp(buf, STR_KERNELOFFSET, + strlen(STR_KERNELOFFSET)) == 0) { + info->kaslr_offset = strtoul(buf + + strlen(STR_KERNELOFFSET), &endp, 16); + DEBUG_MSG("info->kaslr_offset: %lx\n", + info->kaslr_offset); + } + } + } + if (!info->kaslr_offset) + return 0; + + if (_text == NOT_FOUND_SYMBOL) { + /* + * Currently, the return value of this function is used in + * resolve_config_entry() only, and in that case, we must + * have a vmlinux. + */ + if (info->name_vmlinux) { + _text = get_symbol_addr("_text"); + _end = get_symbol_addr("_end"); + } + DEBUG_MSG("_text: %lx, _end: %lx\n", _text, _end); + if (_text == NOT_FOUND_SYMBOL || _end == NOT_FOUND_SYMBOL) { + ERRMSG("Cannot determine _text and _end address\n"); + return FALSE; + } + } + + /* + * Returns the kaslr offset only if the vaddr needs it to be added, + * i.e. only kernel text address for now. Otherwise returns 0. + */ + if (_text <= vaddr && vaddr <= _end) + return info->kaslr_offset; + else + return 0; +} + int find_kaslr_offsets() { diff --git a/makedumpfile.h b/makedumpfile.h index ac11e90..067fa48 100644 --- a/makedumpfile.h +++ b/makedumpfile.h @@ -964,6 +964,7 @@ typedef unsigned long pgd_t; static inline int stub_true() { return TRUE; } static inline int stub_true_ul(unsigned long x) { return TRUE; } static inline int stub_false() { return FALSE; } +unsigned long get_kaslr_offset_general(unsigned long vaddr); #define paddr_to_vaddr_general(X) ((X) + PAGE_OFFSET) #ifdef __aarch64__ @@ -973,7 +974,6 @@ unsigned long long vaddr_to_paddr_arm64(unsigned long vaddr); int get_versiondep_info_arm64(void); int get_xen_basic_info_arm64(void); int get_xen_info_arm64(void); -unsigned long get_kaslr_offset_arm64(unsigned long vaddr); #define paddr_to_vaddr_arm64(X) (((X) - info->phys_base) | PAGE_OFFSET) #define find_vmemmap() stub_false() @@ -982,7 +982,7 @@ unsigned long get_kaslr_offset_arm64(unsigned long vaddr); #define get_phys_base() get_phys_base_arm64() #define get_machdep_info() get_machdep_info_arm64() #define get_versiondep_info() get_versiondep_info_arm64() -#define get_kaslr_offset(X) get_kaslr_offset_arm64(X) +#define get_kaslr_offset(X) get_kaslr_offset_general(X) #define get_xen_basic_info_arch(X) get_xen_basic_info_arm64(X) #define get_xen_info_arch(X) get_xen_info_arm64(X) #define is_phys_addr(X) stub_true_ul(X) |