Skip to contentSkip to conversation

Only search page_offset_base when KASLR mm code is compiled in

PATCH In review Baoquan He 2 participants 3 messages Feb 24, 2017 – Mar 2, 2017

Subsystems (2)
lore
Share & tools
lore

Baoquan He

author
#0 lore raw

PATCH 1/1 Only search page_offset_base when KASLR mm code is compiled in

Otherwise it will print false positve message as below. So add a check when do the search.

"Cannot get kernel page_offset_base symbol address"

---
 kexec/arch/i386/crashdump-x86.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
kexec/arch/i386/crashdump-x86.c +4 -2
index 88aeee3..b2c1be5 100644
@@ -150,8 +150,6 @@ static int get_kernel_vaddr_and_size(struct kexec_info *UNUSED(info),
 	off_t size;
 	uint32_t elf_flags = 0;
 	uint64_t stext_sym;
-	const unsigned long long pud_mask = ~((1 << 30) - 1);
-	unsigned long long vaddr, lowest_vaddr = 0;
 
 	if (elf_info->machine != EM_X86_64)
 		return 0;
@@ -181,8 +179,11 @@ static int get_kernel_vaddr_and_size(struct kexec_info *UNUSED(info),
 
 	end_phdr = &ehdr.e_phdr[ehdr.e_phnum];
 
+#ifdef CONFIG_RANDOMIZE_MEMORY
 	/* Search for the real PAGE_OFFSET when KASLR memory randomization
 	 * is enabled */
+	const unsigned long long pud_mask = ~((1 << 30) - 1);
+	unsigned long long vaddr, lowest_vaddr = 0;
 	if (get_kernel_sym("page_offset_base") != 0) {
 		for(phdr = ehdr.e_phdr; phdr != end_phdr; phdr++) {
 			if (phdr->p_type == PT_LOAD) {
@@ -194,6 +195,7 @@ static int get_kernel_vaddr_and_size(struct kexec_info *UNUSED(info),
 		if (lowest_vaddr != 0)
 			elf_info->page_offset = lowest_vaddr;
 	}
+#endif
 
 	/* Traverse through the Elf headers and find the region where
 	 * _stext symbol is located in. That's where kernel is mapped */
Signature · 7 lines
2.5.5


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw
Quoted 24 lines · Baoquan He

Otherwise it will print false positve message as below. So add a check when do the search.

"Cannot get kernel page_offset_base symbol address"

---
 kexec/arch/i386/crashdump-x86.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
kexec/arch/i386/crashdump-x86.c +0 -2
index 88aeee3..b2c1be5 100644
@@ -150,8 +150,6 @@ static int get_kernel_vaddr_and_size(struct kexec_info *UNUSED(info),
 	off_t size;
 	uint32_t elf_flags = 0;
 	uint64_t stext_sym;
-	const unsigned long long pud_mask = ~((1 << 30) - 1);
-	unsigned long long vaddr, lowest_vaddr = 0;
 
 	if (elf_info->machine != EM_X86_64)
 		return 0;

kexec/arch/i386/crashdump-x86.c static int get_kernel_vaddr_and_size(struct kexec_info *UNUSED(info), · line 182

Quoted 4 lines
kexec/arch/i386/crashdump-x86.c +1 -0
@@ -181,8 +179,11 @@ static int get_kernel_vaddr_and_size(struct kexec_info *UNUSED(info),
 
 	end_phdr = &ehdr.e_phdr[ehdr.e_phnum];
 
+#ifdef CONFIG_RANDOMIZE_MEMORY

It does not work in userspace code.

Maybe mute the error message or move it to kexec --debug is more reasonable..

Quoted 23 lines
kexec/arch/i386/crashdump-x86.c +3 -0
 	/* Search for the real PAGE_OFFSET when KASLR memory randomization
 	 * is enabled */
+	const unsigned long long pud_mask = ~((1 << 30) - 1);
+	unsigned long long vaddr, lowest_vaddr = 0;
 	if (get_kernel_sym("page_offset_base") != 0) {
 		for(phdr = ehdr.e_phdr; phdr != end_phdr; phdr++) {
 			if (phdr->p_type == PT_LOAD) {
@@ -194,6 +195,7 @@ static int get_kernel_vaddr_and_size(struct kexec_info *UNUSED(info),
 		if (lowest_vaddr != 0)
 			elf_info->page_offset = lowest_vaddr;
 	}
+#endif
 
 	/* Traverse through the Elf headers and find the region where
 	 * _stext symbol is located in. That's where kernel is mapped */
Signature · 7 lines
2.5.5


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Thanks
Dave

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

author
#2 lore raw
Quoted 26 lines · Dave Young
Quoted 25 lines · Baoquan He

Otherwise it will print false positve message as below. So add a check when do the search.

"Cannot get kernel page_offset_base symbol address"

---
 kexec/arch/i386/crashdump-x86.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
kexec/arch/i386/crashdump-x86.c +0 -2
index 88aeee3..b2c1be5 100644
@@ -150,8 +150,6 @@ static int get_kernel_vaddr_and_size(struct kexec_info *UNUSED(info),
 	off_t size;
 	uint32_t elf_flags = 0;
 	uint64_t stext_sym;
-	const unsigned long long pud_mask = ~((1 << 30) - 1);
-	unsigned long long vaddr, lowest_vaddr = 0;
 
 	if (elf_info->machine != EM_X86_64)
 		return 0;
@@ -181,8 +179,11 @@ static int get_kernel_vaddr_and_size(struct kexec_info *UNUSED(info),
 
Quoted 5 lines

kexec/arch/i386/crashdump-x86.c static int get_kernel_vaddr_and_size(struct kexec_info *UNUSED(info), · line 182

Quoted 3 lines
kexec/arch/i386/crashdump-x86.c +1 -0
 	end_phdr = &ehdr.e_phdr[ehdr.e_phnum];
 
+#ifdef CONFIG_RANDOMIZE_MEMORY

It does not work in userspace code.

Could be it only works when make header and install. Otherwise it can't be seen by user space. I built a rhel kernel package and test passed.

Anyway, since it doesn't work in all cases, I have made another way to fix it, just take out the error message and put it where get_kernel_sym is called.

Quoted 31 lines

Maybe mute the error message or move it to kexec --debug is more reasonable..

Quoted 23 lines
kexec/arch/i386/crashdump-x86.c +3 -0
 	/* Search for the real PAGE_OFFSET when KASLR memory randomization
 	 * is enabled */
+	const unsigned long long pud_mask = ~((1 << 30) - 1);
+	unsigned long long vaddr, lowest_vaddr = 0;
 	if (get_kernel_sym("page_offset_base") != 0) {
 		for(phdr = ehdr.e_phdr; phdr != end_phdr; phdr++) {
 			if (phdr->p_type == PT_LOAD) {
@@ -194,6 +195,7 @@ static int get_kernel_vaddr_and_size(struct kexec_info *UNUSED(info),
 		if (lowest_vaddr != 0)
 			elf_info->page_offset = lowest_vaddr;
 	}
+#endif
 
 	/* Traverse through the Elf headers and find the region where
 	 * _stext symbol is located in. That's where kernel is mapped */
Signature · 7 lines
2.5.5


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Thanks
Dave

Quoted 4 lines

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec