get MODULES_VADDR by KERNEL_IMAGE_SIZE for x86_64
Subsystems (2)
PATCH v2 1/1 get MODULES_VADDR by KERNEL_IMAGE_SIZE for x86_64
In x86_64, since v2.6.26 the KERNEL_IMAGE_SIZE is changed to 512M, and accordingly the MODULES_VADDR is changed to 0xffffffffa0000000. Before that, KERNEL_IMAGE_SIZE is 128M, and MODULES_VADDR is 0xffffffff88000000.
However, in v3.12 Kees Cook introduced kaslr to randomise the location of kernel. And the kernel text mapping addr space is enlarged from 512M to 1G. That means now KERNEL_IMAGE_SIZE is variable, its value is 512M with kaslr support not compiled in and 1G with kaslr support compiled in. Accordingly the MODULES_VADDR is changed too to be:
So when kaslr is compiled in and enabled, the kernel text mapping addr space and modules vaddr space need be adjusted. Otherwise makedumpfile will collapse since the addr for some symbols is not correct.
Hence KERNEL_IMAGE_SIZE need be exported to vmcoreinfo and got in makedumpfile to help calculate MODULES_VADDR.
v1->v2:
Fix a code bug Atsushi found.
--- makedumpfile.c | 10 ++++++++++ makedumpfile.h | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-)
makedumpfile.c +10 -0
@@ -1564,6 +1564,14 @@ get_value_for_old_linux(void)NUMBER (PAGE_BUDDY_MAPCOUNT_VALUE ) = PAGE_BUDDY_MAPCOUNT_VALUE_v2_6_39_to_latest_version; } +#ifdef __x86_64__ +if (NUMBER (KERNEL_IMAGE_SIZE ) ==NOT_FOUND_NUMBER ) { +if (info->kernel_version <KERNEL_VERSION (2 ,6 ,26 )) +NUMBER (KERNEL_IMAGE_SIZE ) =KERNEL_IMAGE_SIZE_ORIG ; +else +NUMBER (KERNEL_IMAGE_SIZE ) =KERNEL_IMAGE_SIZE_2_6_26 ; + } +#endif if (SIZE (pageflags) ==NOT_FOUND_STRUCTURE ) {if (info->kernel_version >=KERNEL_VERSION (2 ,6 ,27 )) SIZE(pageflags) =
@@ -1813,6 +1821,7 @@ write_vmcoreinfo_data(void)WRITE_NUMBER ("PG_hwpoison" , PG_hwpoison);WRITE_NUMBER ("PAGE_BUDDY_MAPCOUNT_VALUE" ,PAGE_BUDDY_MAPCOUNT_VALUE ); +WRITE_NUMBER ("KERNEL_IMAGE_SIZE" ,KERNEL_IMAGE_SIZE );/* * write the source file of 1st kernel
@@ -2147,6 +2156,7 @@ read_vmcoreinfo(void)READ_SRCFILE ("pud_t" , pud_t);READ_NUMBER ("PAGE_BUDDY_MAPCOUNT_VALUE" ,PAGE_BUDDY_MAPCOUNT_VALUE ); +READ_NUMBER ("KERNEL_IMAGE_SIZE" ,KERNEL_IMAGE_SIZE );return TRUE; }
makedumpfile.h +4 -1
@@ -549,7 +549,9 @@ do { \#define VMEMMAP_END_2_6_31 (0xffffeaffffffffff)/* 2.6.31, or later */ #define __START_KERNEL_map (0xffffffff80000000) -#define MODULES_VADDR (0xffffffff88000000) +#define KERNEL_IMAGE_SIZE_ORIG (0x0000000008000000)/* 2.6.25, or former */ +#define KERNEL_IMAGE_SIZE_2_6_26 (0x0000000020000000)/* 2.6.26, or later */ +#define MODULES_VADDR (__START_KERNEL_map + NUMBER(KERNEL_IMAGE_SIZE))#define MODULES_END (0xfffffffffff00000)#define KVBASE PAGE_OFFSET#define _SECTION_SIZE_BITS (27)
@@ -1531,6 +1533,7 @@ struct number_table {long PG_hwpoison;long PAGE_BUDDY_MAPCOUNT_VALUE ; +long KERNEL_IMAGE_SIZE ;long SECTION_SIZE_BITS ;long MAX_PHYSMEM_BITS ; };
Signature · 7 lines
1.8.5.3 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Hello Baoquan,
This patch looks good to me, I'll merge it into v1.5.8.
Thanks
Atsushi Kumagai
Quoted 85 lines
In
x86_64, since v2.6.26 theKERNEL_IMAGE_SIZEis changed to 512M, and accordingly theMODULES_VADDRis changed to0xffffffffa0000000. Before that,KERNEL_IMAGE_SIZEis 128M, andMODULES_VADDRis0xffffffff88000000.However, in v3.12 Kees Cook introduced kaslr to randomise the location of kernel. And the kernel text mapping addr space is enlarged from 512M to 1G. That means now
KERNEL_IMAGE_SIZEis variable, its value is 512M with kaslr support not compiled in and 1G with kaslr support compiled in. Accordingly theMODULES_VADDRis changed too to be:So when kaslr is compiled in and enabled, the kernel text mapping addr space and modules vaddr space need be adjusted. Otherwise makedumpfile will collapse since the addr for some symbols is not correct.
Hence
KERNEL_IMAGE_SIZEneed be exported to vmcoreinfo and got in makedumpfile to help calculateMODULES_VADDR.
v1->v2:
Fix a code bug Atsushi found.Signed-off-by Baoquan He <[email protected]>---
makedumpfile.c| 10 ++++++++++makedumpfile.h| 5 ++++-2 files changed, 14 insertions(+), 1 deletion(-)makedumpfile.c +10
-0@@ -1564,6 +1564,14 @@ get_value_for_old_linux(void)NUMBER (PAGE_BUDDY_MAPCOUNT_VALUE ) = PAGE_BUDDY_MAPCOUNT_VALUE_v2_6_39_to_latest_version; } +#ifdef __x86_64__ +if (NUMBER (KERNEL_IMAGE_SIZE ) ==NOT_FOUND_NUMBER ) { +if (info->kernel_version <KERNEL_VERSION (2 ,6 ,26 )) +NUMBER (KERNEL_IMAGE_SIZE ) =KERNEL_IMAGE_SIZE_ORIG ; +else +NUMBER (KERNEL_IMAGE_SIZE ) =KERNEL_IMAGE_SIZE_2_6_26 ; + } +#endif if (SIZE (pageflags) ==NOT_FOUND_STRUCTURE ) {if (info->kernel_version >=KERNEL_VERSION (2 ,6 ,27 )) SIZE(pageflags) =@@ -1813,6 +1821,7 @@ write_vmcoreinfo_data(void)WRITE_NUMBER ("PG_hwpoison" , PG_hwpoison);WRITE_NUMBER ("PAGE_BUDDY_MAPCOUNT_VALUE" ,PAGE_BUDDY_MAPCOUNT_VALUE ); +WRITE_NUMBER ("KERNEL_IMAGE_SIZE" ,KERNEL_IMAGE_SIZE );/* * write the source file of 1st kernel @@ -2147,6 +2156,7 @@ read_vmcoreinfo(void)READ_SRCFILE ("pud_t" , pud_t);READ_NUMBER ("PAGE_BUDDY_MAPCOUNT_VALUE" ,PAGE_BUDDY_MAPCOUNT_VALUE ); +READ_NUMBER ("KERNEL_IMAGE_SIZE" ,KERNEL_IMAGE_SIZE );return TRUE; }makedumpfile.h +4
-2@@ -549,7 +549,9 @@ do { \#define VMEMMAP_END_2_6_31 (0xffffeaffffffffff)/* 2.6.31, or later */ #define __START_KERNEL_map (0xffffffff80000000) -#define MODULES_VADDR (0xffffffff88000000) +#define KERNEL_IMAGE_SIZE_ORIG (0x0000000008000000)/* 2.6.25, or former */ +#define KERNEL_IMAGE_SIZE_2_6_26 (0x0000000020000000)/* 2.6.26, or later */ +#define MODULES_VADDR (__START_KERNEL_map + NUMBER(KERNEL_IMAGE_SIZE))#define MODULES_END (0xfffffffffff00000)#define KVBASE PAGE_OFFSET#define _SECTION_SIZE_BITS (27)@@ -1531,6 +1533,7 @@ struct number_table {long PG_hwpoison;long PAGE_BUDDY_MAPCOUNT_VALUE ; +long KERNEL_IMAGE_SIZE ;long SECTION_SIZE_BITS ;long MAX_PHYSMEM_BITS ; }; --
Quoted 1 line
1.8.5.3
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 3 lines · Atsushi Kumagai
Hello Baoquan,
This patch looks good to me, I'll merge it into v1.5.8.
Thanks, Atsushi!
Quoted 84 lines
Thanks
Atsushi KumagaiQuoted 79 lines
In
x86_64, since v2.6.26 theKERNEL_IMAGE_SIZEis changed to 512M, and accordingly theMODULES_VADDRis changed to0xffffffffa0000000. Before that,KERNEL_IMAGE_SIZEis 128M, andMODULES_VADDRis0xffffffff88000000.However, in v3.12 Kees Cook introduced kaslr to randomise the location of kernel. And the kernel text mapping addr space is enlarged from 512M to 1G. That means now
KERNEL_IMAGE_SIZEis variable, its value is 512M with kaslr support not compiled in and 1G with kaslr support compiled in. Accordingly theMODULES_VADDRis changed too to be:So when kaslr is compiled in and enabled, the kernel text mapping addr space and modules vaddr space need be adjusted. Otherwise makedumpfile will collapse since the addr for some symbols is not correct.
Hence
KERNEL_IMAGE_SIZEneed be exported to vmcoreinfo and got in makedumpfile to help calculateMODULES_VADDR.
v1->v2:
Fix a code bug Atsushi found.Signed-off-by Baoquan He <[email protected]>---
makedumpfile.c| 10 ++++++++++makedumpfile.h| 5 ++++-2 files changed, 14 insertions(+), 1 deletion(-)makedumpfile.c +10
-0@@ -1564,6 +1564,14 @@ get_value_for_old_linux(void)NUMBER (PAGE_BUDDY_MAPCOUNT_VALUE ) = PAGE_BUDDY_MAPCOUNT_VALUE_v2_6_39_to_latest_version; } +#ifdef __x86_64__ +if (NUMBER (KERNEL_IMAGE_SIZE ) ==NOT_FOUND_NUMBER ) { +if (info->kernel_version <KERNEL_VERSION (2 ,6 ,26 )) +NUMBER (KERNEL_IMAGE_SIZE ) =KERNEL_IMAGE_SIZE_ORIG ; +else +NUMBER (KERNEL_IMAGE_SIZE ) =KERNEL_IMAGE_SIZE_2_6_26 ; + } +#endif if (SIZE (pageflags) ==NOT_FOUND_STRUCTURE ) {if (info->kernel_version >=KERNEL_VERSION (2 ,6 ,27 )) SIZE(pageflags) =@@ -1813,6 +1821,7 @@ write_vmcoreinfo_data(void)WRITE_NUMBER ("PG_hwpoison" , PG_hwpoison);WRITE_NUMBER ("PAGE_BUDDY_MAPCOUNT_VALUE" ,PAGE_BUDDY_MAPCOUNT_VALUE ); +WRITE_NUMBER ("KERNEL_IMAGE_SIZE" ,KERNEL_IMAGE_SIZE );/* * write the source file of 1st kernel @@ -2147,6 +2156,7 @@ read_vmcoreinfo(void)READ_SRCFILE ("pud_t" , pud_t);READ_NUMBER ("PAGE_BUDDY_MAPCOUNT_VALUE" ,PAGE_BUDDY_MAPCOUNT_VALUE ); +READ_NUMBER ("KERNEL_IMAGE_SIZE" ,KERNEL_IMAGE_SIZE );return TRUE; }makedumpfile.h +3
-1@@ -549,7 +549,9 @@ do { \#define VMEMMAP_END_2_6_31 (0xffffeaffffffffff)/* 2.6.31, or later */ #define __START_KERNEL_map (0xffffffff80000000) -#define MODULES_VADDR (0xffffffff88000000) +#define KERNEL_IMAGE_SIZE_ORIG (0x0000000008000000)/* 2.6.25, or former */ +#define KERNEL_IMAGE_SIZE_2_6_26 (0x0000000020000000)/* 2.6.26, or later */ +#define MODULES_VADDR (__START_KERNEL_map + NUMBER(KERNEL_IMAGE_SIZE))#define MODULES_END (0xfffffffffff00000)#define KVBASE PAGE_OFFSET#define _SECTION_SIZE_BITS (27)@@ -1531,6 +1533,7 @@ struct number_table {long PG_hwpoison;
Quoted 7 lines
Quoted 7 lines
makedumpfile.h +1
-1long PAGE_BUDDY_MAPCOUNT_VALUE ; +long KERNEL_IMAGE_SIZE ;long SECTION_SIZE_BITS ;long MAX_PHYSMEM_BITS ; }; --1.8.5.3
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 9 lines · Atsushi Kumagai
Quoted 8 lines
Quoted 8 lines
makedumpfile.c +0
-0@@ -1564,6 +1564,14 @@ get_value_for_old_linux(void)NUMBER (PAGE_BUDDY_MAPCOUNT_VALUE ) = PAGE_BUDDY_MAPCOUNT_VALUE_v2_6_39_to_latest_version; }
Quoted 8 lines
Quoted 8 lines
makedumpfile.c get_value_for_old_linux(void) · line 1574
Quoted 8 lines
makedumpfile.c +8
-0+#ifdef __x86_64__ +if (NUMBER (KERNEL_IMAGE_SIZE ) ==NOT_FOUND_NUMBER ) { +if (info->kernel_version <KERNEL_VERSION (2 ,6 ,26 )) +NUMBER (KERNEL_IMAGE_SIZE ) =KERNEL_IMAGE_SIZE_ORIG ; +else +NUMBER (KERNEL_IMAGE_SIZE ) =KERNEL_IMAGE_SIZE_2_6_26 ; + } +#endif
I noticed that this fix is incomplete because get_value_for_old_linux() is too late as shown below:
initial()
+ read_vmcoreinfo_from_vmcore() // get KERNEL_IMAGE_SIZE from VMCOREINFO (only for new kernels)
+ get_mem_map() // refer KERNEL_IMAGE_SIZE via is_vmalloc_addr_x86_64()
+ get_value_for_old_linux() // initialize KERNEL_IMAGE_SIZE for old kernelsSo I'll fix this issue with the patch below.
Thanks,
Atsushi Kumagai
From: Atsushi Kumagai <[email protected]>
Date: Mon, 20 Oct 2014 16:04:57 +0900
Subject: [PATCH] Initialize symbols early for old kernels.
It's best to invoke get_value_for_old_linux() immediately after reading VMCOREINFO since some functions require the symbols which are initialized in it.
This change is safe because get_value_for_old_linux() doesn't overwrite any values.
--- makedumpfile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
makedumpfile.c +3 -3
@@ -3203,6 +3203,9 @@ initial(void) debug_info = TRUE; } +if (!get_value_for_old_linux ()) +return FALSE; + out:if (!info->page_size) {/*
@@ -3306,9 +3309,6 @@ out:return FALSE; } -if (!get_value_for_old_linux ()) -return FALSE; -/* use buddy identification of free pages whether cyclic or not */ /* (this can reduce pages scan of 1TB memory from 60sec to 30sec) */ if (info->dump_level &DL_EXCLUDE_FREE )
Signature · 6 lines
1.9.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Quoted 21 lines · Atsushi Kumagai
Quoted 9 lines · Atsushi Kumagai
Quoted 8 lines
Quoted 8 lines
makedumpfile.c +0
-0@@ -1564,6 +1564,14 @@ get_value_for_old_linux(void)NUMBER (PAGE_BUDDY_MAPCOUNT_VALUE ) = PAGE_BUDDY_MAPCOUNT_VALUE_v2_6_39_to_latest_version; }Quoted 8 lines
Quoted 8 lines
makedumpfile.c get_value_for_old_linux(void) · line 1574
Quoted 8 lines
makedumpfile.c +8
-0+#ifdef __x86_64__ +if (NUMBER (KERNEL_IMAGE_SIZE ) ==NOT_FOUND_NUMBER ) { +if (info->kernel_version <KERNEL_VERSION (2 ,6 ,26 )) +NUMBER (KERNEL_IMAGE_SIZE ) =KERNEL_IMAGE_SIZE_ORIG ; +else +NUMBER (KERNEL_IMAGE_SIZE ) =KERNEL_IMAGE_SIZE_2_6_26 ; + } +#endif I noticed that this fix is incomplete because
get_value_for_old_linux()is too late as shown below:
Quoted 4 lines
initial()+ read_vmcoreinfo_from_vmcore() // get KERNEL_IMAGE_SIZE from VMCOREINFO (only for new kernels) + get_mem_map() // refer KERNEL_IMAGE_SIZE via is_vmalloc_addr_x86_64() + get_value_for_old_linux() // initialize KERNEL_IMAGE_SIZE for old kernels
Yes, this is a good catch. Thanks for fixing it.
Quoted 49 lines
So I'll fix this issue with the patch below.
Thanks,
Atsushi KumagaiFrom: Atsushi Kumagai <[email protected]>
Date: Mon, 20 Oct 2014 16:04:57 +0900
Subject: [PATCH] Initialize symbols early for old kernels.It's best to invoke
get_value_for_old_linux()immediately after reading VMCOREINFO since some functions require the symbols which are initialized in it.
This change is safe becauseget_value_for_old_linux()doesn't overwrite any values.Signed-off-by Atsushi Kumagai <[email protected]>--- makedumpfile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)makedumpfile.c +3
-3@@ -3203,6 +3203,9 @@ initial(void) debug_info = TRUE; } +if (!get_value_for_old_linux ()) +return FALSE; + out:if (!info->page_size) {/* @@ -3306,9 +3309,6 @@ out:return FALSE; } -if (!get_value_for_old_linux ()) -return FALSE; -/* use buddy identification of free pages whether cyclic or not */ /* (this can reduce pages scan of 1TB memory from 60sec to 30sec) */ if (info->dump_level &DL_EXCLUDE_FREE )Signature · 1 line
1.9.0
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec