module.lds,codetag: force 0 sh_addr for sections
Subsystems (3)
PATCH v2 1/1 module.lds,codetag: force 0 sh_addr for sections
Commit 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros") added .text and made .data, .bss, and .rodata sections unconditional in the module linker script, but without an explicit address like the other sections in the same file.
When linking modules with ld.bfd -r, sections defined without an address inherit the location counter, resulting in non-zero sh_addr values in the .ko. Relocatable objects are expected to have sh_addr=0 for these sections and these non-zero addresses confuse elfutils and have been reported to cause segmentation faults in SystemTap [1].
Add the 0 address specifier to all sections in module.lds, including the .codetag.* sections via MOD_SEPARATE_CODETAG_SECTIONS macro.
--- include/asm-generic/codetag.lds.h | 2 +- scripts/module.lds.S | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-)
v2:
- Update the MOD_SEPARATE_CODETAG_SECTION for .codetag.* as well [Petr]
v1: https://lore.kernel.org/lkml/[email protected]
include/asm-generic/codetag.lds.h +1 -1
@@ -18,7 +18,7 @@ IF_MEM_ALLOC_PROFILING(SECTION_WITH_BOUNDARIES(alloc_tags))#define MOD_SEPARATE_CODETAG_SECTION (_name) \ - .codetag.##_name : { \ + .codetag.##_name 0 : { \ SECTION_WITH_BOUNDARIES(_name) \ }
scripts/module.lds.S +6 -6
@@ -32,30 +32,30 @@ SECTIONS { __jump_table 0 : ALIGN(8) { KEEP(*(__jump_table)) } __ex_table 0 : ALIGN(4) { KEEP(*(__ex_table)) } - __patchable_function_entries : { *(__patchable_function_entries) } + __patchable_function_entries 0 : { *(__patchable_function_entries) } .init.klp_funcs 0 : ALIGN(8) { KEEP(*(.init.klp_funcs)) } .init.klp_objects 0 : ALIGN(8) { KEEP(*(.init.klp_objects)) } #ifdef CONFIG_ARCH_USES_CFI_TRAPS - __kcfi_traps : { KEEP(*(.kcfi_traps)) } + __kcfi_traps 0 : { KEEP(*(.kcfi_traps)) } #endif - .text : { + .text 0 : { *(.text .text.[0-9a-zA-Z_]*) } - .bss : { + .bss 0 : { *(.bss .bss.[0-9a-zA-Z_]*) *(.bss..L*) } - .data : { + .data 0 : { *(.data .data.[0-9a-zA-Z_]*) *(.data..L*) } - .rodata : { + .rodata 0 : { *(.rodata .rodata.[0-9a-zA-Z_]*) *(.rodata..L*) }
Signature · 1 line
2.53.0
Quoted 22 lines · Joe Lawrence
Commit
1ba9f8979426("vmlinux.lds: UnifyTEXT_MAIN,DATA_MAIN, and related macros") added .text and made .data, .bss, and .rodata sections unconditional in the module linker script, but without an explicit address like the other sections in the same file.When linking modules with ld.bfd -r, sections defined without an address inherit the location counter, resulting in non-zero
sh_addrvalues in the .ko. Relocatable objects are expected to have sh_addr=0 for these sections and these non-zero addresses confuse elfutils and have been reported to cause segmentation faults in SystemTap [1].Add the 0 address specifier to all sections in
module.lds, including the .codetag.* sections viaMOD_SEPARATE_CODETAG_SECTIONSmacro.Fixes 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros")Signed-off-by Joe Lawrence <[email protected]>--- include/asm-generic/codetag.lds.h | 2 +- scripts/module.lds.S | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-)
Quoted 4 lines
v2:
- Update theMOD_SEPARATE_CODETAG_SECTIONfor .codetag.* as well [Petr]
Thanks for the fix!
Signature · 1 line
Josh
Quoted 11 lines · Joe Lawrence
Commit
1ba9f8979426("vmlinux.lds: UnifyTEXT_MAIN,DATA_MAIN, and related macros") added .text and made .data, .bss, and .rodata sections unconditional in the module linker script, but without an explicit address like the other sections in the same file.When linking modules with ld.bfd -r, sections defined without an address inherit the location counter, resulting in non-zero
sh_addrvalues in the .ko. Relocatable objects are expected to have sh_addr=0 for these sections and these non-zero addresses confuse elfutils and have been reported to cause segmentation faults in SystemTap [1].
Quoted 6 lines
Add the 0 address specifier to all sections in
module.lds, including the .codetag.* sections viaMOD_SEPARATE_CODETAG_SECTIONSmacro.Fixes 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros")Signed-off-by Joe Lawrence <[email protected]>
Signature · 2 lines
Thanks, Petr
Sami Tolvanen
maintainerQuoted 17 lines · Joe Lawrence
Commit
1ba9f8979426("vmlinux.lds: UnifyTEXT_MAIN,DATA_MAIN, and related macros") added .text and made .data, .bss, and .rodata sections unconditional in the module linker script, but without an explicit address like the other sections in the same file.When linking modules with ld.bfd -r, sections defined without an address inherit the location counter, resulting in non-zero
sh_addrvalues in the .ko. Relocatable objects are expected to have sh_addr=0 for these sections and these non-zero addresses confuse elfutils and have been reported to cause segmentation faults in SystemTap [1].Add the 0 address specifier to all sections in
module.lds, including the .codetag.* sections viaMOD_SEPARATE_CODETAG_SECTIONSmacro.Fixes 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros")Signed-off-by Joe Lawrence <[email protected]>
Quoted 7 lines
--- include/asm-generic/codetag.lds.h | 2 +- scripts/module.lds.S | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-)v2:
- Update theMOD_SEPARATE_CODETAG_SECTIONfor .codetag.* as well [Petr]
Do we also need similar changes in any of the architecture-specific module linker scripts (arch/*/include/asm/module.lds.h)?
Sami
Quoted 23 lines · Sami Tolvanen
Quoted 22 lines · Joe Lawrence
Commit
1ba9f8979426("vmlinux.lds: UnifyTEXT_MAIN,DATA_MAIN, and related macros") added .text and made .data, .bss, and .rodata sections unconditional in the module linker script, but without an explicit address like the other sections in the same file.When linking modules with ld.bfd -r, sections defined without an address inherit the location counter, resulting in non-zero
sh_addrvalues in the .ko. Relocatable objects are expected to have sh_addr=0 for these sections and these non-zero addresses confuse elfutils and have been reported to cause segmentation faults in SystemTap [1].Add the 0 address specifier to all sections in
module.lds, including the .codetag.* sections viaMOD_SEPARATE_CODETAG_SECTIONSmacro.Fixes 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros")Signed-off-by Joe Lawrence <[email protected]>--- include/asm-generic/codetag.lds.h | 2 +- scripts/module.lds.S | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-)
Quoted 6 lines
Quoted 2 lines
v2:
- Update theMOD_SEPARATE_CODETAG_SECTIONfor .codetag.* as well [Petr]Do we also need similar changes in any of the architecture-specific module linker scripts (
arch/*/include/asm/module.lds.h)?
Hi Sami,
That is a good question that is unfortunately beyond my limited linker script knowledge. Some of those arch-specific module.lds.h do not specify address for several sections and have been that way for years ... so if I were to guess, I don't think 1ba9f8979426 changed their behavior one way or another.
--
Joe
Petr Pavlu
maintainerQuoted 23 lines · Sami Tolvanen
Quoted 22 lines · Joe Lawrence
Commit
1ba9f8979426("vmlinux.lds: UnifyTEXT_MAIN,DATA_MAIN, and related macros") added .text and made .data, .bss, and .rodata sections unconditional in the module linker script, but without an explicit address like the other sections in the same file.When linking modules with ld.bfd -r, sections defined without an address inherit the location counter, resulting in non-zero
sh_addrvalues in the .ko. Relocatable objects are expected to have sh_addr=0 for these sections and these non-zero addresses confuse elfutils and have been reported to cause segmentation faults in SystemTap [1].Add the 0 address specifier to all sections in
module.lds, including the .codetag.* sections viaMOD_SEPARATE_CODETAG_SECTIONSmacro.Fixes 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros")Signed-off-by Joe Lawrence <[email protected]>--- include/asm-generic/codetag.lds.h | 2 +- scripts/module.lds.S | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-)
Quoted 5 lines
Quoted 2 lines
v2:
- Update theMOD_SEPARATE_CODETAG_SECTIONfor .codetag.* as well [Petr]Do we also need similar changes in any of the architecture-specific module linker scripts (
arch/*/include/asm/module.lds.h)?
I overlooked these architecture-specific files. I believe we should do the same for them. For instance, riscv explicitly defines the .plt, .got and .got.plt sections, and they have misleading addresses:
$ readelf -t fs/xfs/xfs.ko
[...]
Section Headers:
[Nr] Name
Type Address Offset Link
Size EntSize Info Align
Flags
[...]
[48] __versions
PROGBITS 0000000000000000 0000000000194e90 0
0000000000007900 0000000000000000 0 8
[0000000000000002]: ALLOC
[49] .plt
PROGBITS 0000000000007900 000000000019c790 0
0000000000000001 0000000000000000 0 1
[0000000000000006]: ALLOC, EXEC
[50] .got
PROGBITS 0000000000007901 000000000019c791 0
0000000000000001 0000000000000000 0 1
[0000000000000003]: WRITE, ALLOC
[51] .got.plt
PROGBITS 0000000000007902 000000000019c792 0
0000000000000001 0000000000000000 0 1
[0000000000000002]: ALLOC
[...]Nonetheless, this can be done separately. I think fixes for these files should better go through architecture-specific trees anyway.
I can check the individual architectures and prepare the necessary patches, unless someone else is already looking into this or wants to take a look.
Signature · 2 lines
Thanks, Petr
Quoted 33 lines · Petr Pavlu
Quoted 2 lines
Do we also need similar changes in any of the architecture-specific module linker scripts (
arch/*/include/asm/module.lds.h)?I overlooked these architecture-specific files. I believe we should do the same for them. For instance, riscv explicitly defines the .plt, .got and .got.plt sections, and they have misleading addresses:
$ readelf -t fs/xfs/xfs.ko [...] Section Headers: [Nr] Name Type Address Offset Link Size EntSize Info Align Flags [...] [48] __versions PROGBITS 0000000000000000 0000000000194e90 0 0000000000007900 0000000000000000 0 8 [0000000000000002]: ALLOC [49] .plt PROGBITS 0000000000007900 000000000019c790 0 0000000000000001 0000000000000000 0 1 [0000000000000006]: ALLOC, EXEC [50] .got PROGBITS 0000000000007901 000000000019c791 0 0000000000000001 0000000000000000 0 1 [0000000000000003]: WRITE, ALLOC [51] .got.plt PROGBITS 0000000000007902 000000000019c792 0 0000000000000001 0000000000000000 0 1 [0000000000000002]: ALLOC [...]
Quoted 6 lines
Nonetheless, this can be done separately. I think fixes for these files should better go through architecture-specific trees anyway.
I can check the individual architectures and prepare the necessary patches, unless someone else is already looking into this or wants to take a look.
I agree those can be done separately. In the meantime do you plan to take this patch in the module tree?
Signature · 1 line
Josh
Sami Tolvanen
maintainerQuoted 10 lines · Josh Poimboeuf
Quoted 6 lines · Petr Pavlu
Nonetheless, this can be done separately. I think fixes for these files should better go through architecture-specific trees anyway.
I can check the individual architectures and prepare the necessary patches, unless someone else is already looking into this or wants to take a look.
I agree those can be done separately. In the meantime do you plan to take this patch in the module tree?
Yes, that's the plan.
Sami
Quoted 5 lines · Joe Lawrence
Commit
1ba9f8979426("vmlinux.lds: UnifyTEXT_MAIN,DATA_MAIN, and related macros") added .text and made .data, .bss, and .rodata sections unconditional in the module linker script, but without an explicit address like the other sections in the same file.
Quoted 7 lines
When linking modules with ld.bfd -r, sections defined without an address inherit the location counter, resulting in non-zero
sh_addrvalues in the .ko. Relocatable objects are expected to have sh_addr=0 for these sections and these non-zero addresses confuse elfutils and have been reported to cause segmentation faults in SystemTap [1].[...]
Applied to modules-next, thanks!
[1/1] module.lds,codetag: force 0 sh_addr for sections
commit: 4afc71bba8b7d7841681e7647ae02f5079aaf28f
Best regards,
Sami