public inbox for linux-modules@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] module.lds,codetag: force 0 sh_addr for sections
@ 2026-03-05  1:52 Joe Lawrence
  2026-03-05 19:55 ` Josh Poimboeuf
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Joe Lawrence @ 2026-03-05  1:52 UTC (permalink / raw)
  To: linux-modules, linux-kernel
  Cc: Luis Chamberlain, Petr Pavlu, Daniel Gomez, Sami Tolvanen,
	Aaron Tomlin, Petr Mladek, Josh Poimboeuf

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.

Link: https://sourceware.org/bugzilla/show_bug.cgi?id=33958
Fixes: 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros")
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
---
 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/20260304160611.143862-1-joe.lawrence@redhat.com

diff --git a/include/asm-generic/codetag.lds.h b/include/asm-generic/codetag.lds.h
index a14f4bdafdda..4948e5d4e9d9 100644
--- a/include/asm-generic/codetag.lds.h
+++ b/include/asm-generic/codetag.lds.h
@@ -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)	\
 	}
 
diff --git a/scripts/module.lds.S b/scripts/module.lds.S
index 054ef99e8288..e1cab3cee3f7 100644
--- a/scripts/module.lds.S
+++ b/scripts/module.lds.S
@@ -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*)
 	}
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] module.lds,codetag: force 0 sh_addr for sections
  2026-03-05  1:52 [PATCH v2] module.lds,codetag: force 0 sh_addr for sections Joe Lawrence
@ 2026-03-05 19:55 ` Josh Poimboeuf
  2026-03-06  8:15 ` Petr Pavlu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Josh Poimboeuf @ 2026-03-05 19:55 UTC (permalink / raw)
  To: Joe Lawrence
  Cc: linux-modules, linux-kernel, Luis Chamberlain, Petr Pavlu,
	Daniel Gomez, Sami Tolvanen, Aaron Tomlin, Petr Mladek

On Wed, Mar 04, 2026 at 08:52:37PM -0500, Joe Lawrence wrote:
> 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.
> 
> Link: https://sourceware.org/bugzilla/show_bug.cgi?id=33958
> Fixes: 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros")
> Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
> ---
>  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/20260304160611.143862-1-joe.lawrence@redhat.com

Thanks for the fix!

Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>

-- 
Josh

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] module.lds,codetag: force 0 sh_addr for sections
  2026-03-05  1:52 [PATCH v2] module.lds,codetag: force 0 sh_addr for sections Joe Lawrence
  2026-03-05 19:55 ` Josh Poimboeuf
@ 2026-03-06  8:15 ` Petr Pavlu
  2026-03-11 21:12 ` Sami Tolvanen
  2026-03-20 17:45 ` Sami Tolvanen
  3 siblings, 0 replies; 9+ messages in thread
From: Petr Pavlu @ 2026-03-06  8:15 UTC (permalink / raw)
  To: Joe Lawrence
  Cc: Luis Chamberlain, Daniel Gomez, Sami Tolvanen, Aaron Tomlin,
	Petr Mladek, Josh Poimboeuf, linux-modules, linux-kernel

On 3/5/26 2:52 AM, Joe Lawrence wrote:
> 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.
> 
> Link: https://sourceware.org/bugzilla/show_bug.cgi?id=33958
> Fixes: 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros")
> Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>

Reviewed-by: Petr Pavlu <petr.pavlu@suse.com>

-- 
Thanks,
Petr

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] module.lds,codetag: force 0 sh_addr for sections
  2026-03-05  1:52 [PATCH v2] module.lds,codetag: force 0 sh_addr for sections Joe Lawrence
  2026-03-05 19:55 ` Josh Poimboeuf
  2026-03-06  8:15 ` Petr Pavlu
@ 2026-03-11 21:12 ` Sami Tolvanen
  2026-03-12 21:02   ` Joe Lawrence
  2026-03-16 14:23   ` Petr Pavlu
  2026-03-20 17:45 ` Sami Tolvanen
  3 siblings, 2 replies; 9+ messages in thread
From: Sami Tolvanen @ 2026-03-11 21:12 UTC (permalink / raw)
  To: Joe Lawrence
  Cc: linux-modules, linux-kernel, Luis Chamberlain, Petr Pavlu,
	Daniel Gomez, Aaron Tomlin, Petr Mladek, Josh Poimboeuf

On Wed, Mar 04, 2026 at 08:52:37PM -0500, Joe Lawrence wrote:
> 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.
> 
> Link: https://sourceware.org/bugzilla/show_bug.cgi?id=33958
> Fixes: 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros")
> Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
> ---
>  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]

Do we also need similar changes in any of the architecture-specific module
linker scripts (arch/*/include/asm/module.lds.h)?

Sami

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] module.lds,codetag: force 0 sh_addr for sections
  2026-03-11 21:12 ` Sami Tolvanen
@ 2026-03-12 21:02   ` Joe Lawrence
  2026-03-16 14:23   ` Petr Pavlu
  1 sibling, 0 replies; 9+ messages in thread
From: Joe Lawrence @ 2026-03-12 21:02 UTC (permalink / raw)
  To: Sami Tolvanen
  Cc: linux-modules, linux-kernel, Luis Chamberlain, Petr Pavlu,
	Daniel Gomez, Aaron Tomlin, Petr Mladek, Josh Poimboeuf

On Wed, Mar 11, 2026 at 09:12:07PM +0000, Sami Tolvanen wrote:
> On Wed, Mar 04, 2026 at 08:52:37PM -0500, Joe Lawrence wrote:
> > 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.
> > 
> > Link: https://sourceware.org/bugzilla/show_bug.cgi?id=33958
> > Fixes: 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros")
> > Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
> > ---
> >  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]
> 
> 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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] module.lds,codetag: force 0 sh_addr for sections
  2026-03-11 21:12 ` Sami Tolvanen
  2026-03-12 21:02   ` Joe Lawrence
@ 2026-03-16 14:23   ` Petr Pavlu
  2026-03-17 22:55     ` Josh Poimboeuf
  1 sibling, 1 reply; 9+ messages in thread
From: Petr Pavlu @ 2026-03-16 14:23 UTC (permalink / raw)
  To: Sami Tolvanen, Joe Lawrence
  Cc: linux-modules, linux-kernel, Luis Chamberlain, Daniel Gomez,
	Aaron Tomlin, Petr Mladek, Josh Poimboeuf

On 3/11/26 10:12 PM, Sami Tolvanen wrote:
> On Wed, Mar 04, 2026 at 08:52:37PM -0500, Joe Lawrence wrote:
>> 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.
>>
>> Link: https://sourceware.org/bugzilla/show_bug.cgi?id=33958
>> Fixes: 1ba9f8979426 ("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros")
>> Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
>> ---
>>  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]
> 
> 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.

-- 
Thanks,
Petr

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] module.lds,codetag: force 0 sh_addr for sections
  2026-03-16 14:23   ` Petr Pavlu
@ 2026-03-17 22:55     ` Josh Poimboeuf
  2026-03-17 23:10       ` Sami Tolvanen
  0 siblings, 1 reply; 9+ messages in thread
From: Josh Poimboeuf @ 2026-03-17 22:55 UTC (permalink / raw)
  To: Petr Pavlu
  Cc: Sami Tolvanen, Joe Lawrence, linux-modules, linux-kernel,
	Luis Chamberlain, Daniel Gomez, Aaron Tomlin, Petr Mladek

On Mon, Mar 16, 2026 at 03:23:20PM +0100, Petr Pavlu wrote:
> > 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.

I agree those can be done separately.  In the meantime do you plan to
take this patch in the module tree?

-- 
Josh

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] module.lds,codetag: force 0 sh_addr for sections
  2026-03-17 22:55     ` Josh Poimboeuf
@ 2026-03-17 23:10       ` Sami Tolvanen
  0 siblings, 0 replies; 9+ messages in thread
From: Sami Tolvanen @ 2026-03-17 23:10 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Petr Pavlu, Joe Lawrence, linux-modules, linux-kernel,
	Luis Chamberlain, Daniel Gomez, Aaron Tomlin, Petr Mladek

On Tue, Mar 17, 2026 at 03:55:57PM -0700, Josh Poimboeuf wrote:
> On Mon, Mar 16, 2026 at 03:23:20PM +0100, Petr Pavlu wrote:
> > 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] module.lds,codetag: force 0 sh_addr for sections
  2026-03-05  1:52 [PATCH v2] module.lds,codetag: force 0 sh_addr for sections Joe Lawrence
                   ` (2 preceding siblings ...)
  2026-03-11 21:12 ` Sami Tolvanen
@ 2026-03-20 17:45 ` Sami Tolvanen
  3 siblings, 0 replies; 9+ messages in thread
From: Sami Tolvanen @ 2026-03-20 17:45 UTC (permalink / raw)
  To: linux-modules, linux-kernel, Joe Lawrence
  Cc: Luis Chamberlain, Petr Pavlu, Daniel Gomez, Aaron Tomlin,
	Petr Mladek, Josh Poimboeuf

On Wed, 04 Mar 2026 20:52:37 -0500, Joe Lawrence wrote:
> 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].
> 
> [...]

Applied to modules-next, thanks!

[1/1] module.lds,codetag: force 0 sh_addr for sections
      commit: 4afc71bba8b7d7841681e7647ae02f5079aaf28f

Best regards,

	Sami



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-03-20 17:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-05  1:52 [PATCH v2] module.lds,codetag: force 0 sh_addr for sections Joe Lawrence
2026-03-05 19:55 ` Josh Poimboeuf
2026-03-06  8:15 ` Petr Pavlu
2026-03-11 21:12 ` Sami Tolvanen
2026-03-12 21:02   ` Joe Lawrence
2026-03-16 14:23   ` Petr Pavlu
2026-03-17 22:55     ` Josh Poimboeuf
2026-03-17 23:10       ` Sami Tolvanen
2026-03-20 17:45 ` Sami Tolvanen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox