kasan: account for destructor sections
PATCH v2 1/1 kasan: account for destructor sections
If CONFIG_KASAN is enabled and gcc is configured with --disable-initfini-array, gcc emits .ctors/.dtors and .text.startup/.text.exit sections instead of .init_array/.fini_array.
.dtors section is not explicitly accounted in the linker script and messes vvar/percpu layout. Want:
ffffffff822bfd80 D _edataffffffff822c0000 D __vvar_beginning_hack ffffffff822c0000 A __vvar_page ffffffff822c0080 0000000000000098 D vsyscall_gtod_data ffffffff822c1000 A __init_begin ffffffff822c1000 D init_per_cpu__irq_stack_union ffffffff822c1000 A __per_cpu_load ffffffff822d3000 D init_per_cpu__gdt_page
Got:
ffffffff8279a600 D _edataffffffff8279b000 A __vvar_page ffffffff8279c000 A __init_begin ffffffff8279c000 D init_per_cpu__irq_stack_union ffffffff8279c000 A __per_cpu_load ffffffff8279e000 D __vvar_beginning_hack ffffffff8279e080 0000000000000098 D vsyscall_gtod_data ffffffff827ae000 D init_per_cpu__gdt_page
This happens because __vvar_page and .vvar get different addresses in arch/x86/kernel/vmlinux.lds.S:
. = ALIGN(PAGE_SIZE);
__vvar_page = .;
.vvar : AT(ADDR(.vvar) - LOAD_OFFSET) {
/* work around gold bug 13023 */
__vvar_beginning_hack = .;Discard .dtors/.fini_array/.text.exit, since we don't call dtors. Merge .text.startup into init text.
---
Changes since v1:
- discard .dtors
- don't define .mem sections
--- include/asm-generic/vmlinux.lds.h | 4 ++++ 1 file changed, 4 insertions(+)
include/asm-generic/vmlinux.lds.h +4 -0
@@ -542,15 +542,19 @@#define INIT_TEXT \ *(.init.text) \ + *(.text.startup) \ MEM_DISCARD(init.text)#define EXIT_DATA \ *(.exit.data) \ + *(.fini_array) \ + *(.dtors) \ MEM_DISCARD(exit.data) \ MEM_DISCARD(exit.rodata)#define EXIT_TEXT \ *(.exit.text) \ + *(.text.exit) \ MEM_DISCARD(exit.text)#define EXIT_CALL \
Signature · 1 line
2.8.0.rc3.226.g39d4020
2016-06-23 19:06 GMT+03:00 Dmitry Vyukov <[email protected]>:
Subsystem prefix in subject is wrong. Change it to vmlinux.lds
Quoted 6 lines
If
CONFIG_KASANis enabled and gcc is configured with --disable-initfini-array, gcc emits .ctors/.dtors and .text.startup/.text.exit sections instead of .init_array/.fini_array.
.dtors section is not explicitly accounted in the linker script and messes vvar/percpu layout. Want:
As far as I found out this happens if gold linker has been used. Gcc configuration is irrelevant here.
Quoted 71 lines
ffffffff822bfd80D_edataffffffff822c0000D__vvar_beginning_hackffffffff822c0000A__vvar_pageffffffff822c00800000000000000098 Dvsyscall_gtod_dataffffffff822c1000A__init_beginffffffff822c1000Dinit_per_cpu__irq_stack_unionffffffff822c1000A__per_cpu_loadffffffff822d3000Dinit_per_cpu__gdt_pageGot:
ffffffff8279a600D_edataffffffff8279b000A__vvar_pageffffffff8279c000A__init_beginffffffff8279c000Dinit_per_cpu__irq_stack_unionffffffff8279c000A__per_cpu_loadffffffff8279e000D__vvar_beginning_hackffffffff8279e0800000000000000098 Dvsyscall_gtod_dataffffffff827ae000Dinit_per_cpu__gdt_pageThis happens because
__vvar_pageand .vvar get different addresses inarch/x86/kernel/vmlinux.lds.S:. = ALIGN(PAGE_SIZE); __vvar_page = .; .vvar : AT(ADDR(.vvar) - LOAD_OFFSET) { /* work around gold bug 13023 */ __vvar_beginning_hack = .;Discard .dtors/.fini_array/.text.exit, since we don't call dtors. Merge .text.startup into init text.
Signed-off-by Dmitry Vyukov <[email protected]>---
Changes since v1:
- discard .dtors
- don't define .mem sections--- include/asm-generic/vmlinux.lds.h | 4 ++++ 1 file changed, 4 insertions(+)include/asm-generic/vmlinux.lds.h +4
-1@@ -542,15 +542,19 @@#define INIT_TEXT \ *(.init.text) \ + *(.text.startup) \ MEM_DISCARD(init.text)#define EXIT_DATA \ *(.exit.data) \ + *(.fini_array) \ + *(.dtors) \ MEM_DISCARD(exit.data) \ MEM_DISCARD(exit.rodata)#define EXIT_TEXT \ *(.exit.text) \ + *(.text.exit) \ MEM_DISCARD(exit.text)#define EXIT_CALL \ --2.8.0.rc3.226.g39d4020