* [PATCH v3] module: Make sure relocations are applied to the per-CPU section
@ 2025-06-10 16:33 Sebastian Andrzej Siewior
2025-06-12 11:47 ` Petr Pavlu
2025-07-01 13:40 ` Daniel Gomez
0 siblings, 2 replies; 3+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-06-10 16:33 UTC (permalink / raw)
To: linux-modules
Cc: Petr Pavlu, Luis Chamberlain, Sami Tolvanen, Daniel Gomez,
Peter Zijlstra, Thomas Gleixner
The per-CPU data section is handled differently than the other sections.
The memory allocations requires a special __percpu pointer and then the
section is copied into the view of each CPU. Therefore the SHF_ALLOC
flag is removed to ensure move_module() skips it.
Later, relocations are applied and apply_relocations() skips sections
without SHF_ALLOC because they have not been copied. This also skips the
per-CPU data section.
The missing relocations result in a NULL pointer on x86-64 and very
small values on x86-32. This results in a crash because it is not
skipped like NULL pointer would and can't be dereferenced.
Such an assignment happens during static per-CPU lock initialisation
with lockdep enabled.
Allow relocation processing for the per-CPU section even if SHF_ALLOC is
missing.
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202506041623.e45e4f7d-lkp@intel.com
Fixes: 1a6100caae425 ("Don't relocate non-allocated regions in modules.") #v2.6.1-rc3
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
v2…v3: https://lore.kernel.org/all/20250605060738.SzA3UESe@linutronix.de/
- Check for assigned per-CPU section instead of adding the SHF_ALLOC
flag back.
v1…v2: https://lore.kernel.org/all/20250604152707.CieD9tN0@linutronix.de/
- Add the flag back only on SMP if the per-CPU section was found.
kernel/module/main.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/kernel/module/main.c b/kernel/module/main.c
index 413ac6ea37021..cb281e82226cd 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -1573,8 +1573,14 @@ static int apply_relocations(struct module *mod, const struct load_info *info)
if (infosec >= info->hdr->e_shnum)
continue;
- /* Don't bother with non-allocated sections */
- if (!(info->sechdrs[infosec].sh_flags & SHF_ALLOC))
+ /*
+ * Don't bother with non-allocated sections.
+ * An exception is the percpu section, which has separate allocations
+ * for individual CPUs. We relocate the percpu section in the initial
+ * ELF template and subsequently copy it to the per-CPU destinations.
+ */
+ if (!(info->sechdrs[infosec].sh_flags & SHF_ALLOC) &&
+ (!infosec || infosec != info->index.pcpu))
continue;
if (info->sechdrs[i].sh_flags & SHF_RELA_LIVEPATCH)
--
2.49.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v3] module: Make sure relocations are applied to the per-CPU section
2025-06-10 16:33 [PATCH v3] module: Make sure relocations are applied to the per-CPU section Sebastian Andrzej Siewior
@ 2025-06-12 11:47 ` Petr Pavlu
2025-07-01 13:40 ` Daniel Gomez
1 sibling, 0 replies; 3+ messages in thread
From: Petr Pavlu @ 2025-06-12 11:47 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: Luis Chamberlain, Sami Tolvanen, Daniel Gomez, Peter Zijlstra,
Thomas Gleixner, linux-modules
On 6/10/25 6:33 PM, Sebastian Andrzej Siewior wrote:
> The per-CPU data section is handled differently than the other sections.
> The memory allocations requires a special __percpu pointer and then the
> section is copied into the view of each CPU. Therefore the SHF_ALLOC
> flag is removed to ensure move_module() skips it.
>
> Later, relocations are applied and apply_relocations() skips sections
> without SHF_ALLOC because they have not been copied. This also skips the
> per-CPU data section.
> The missing relocations result in a NULL pointer on x86-64 and very
> small values on x86-32. This results in a crash because it is not
> skipped like NULL pointer would and can't be dereferenced.
>
> Such an assignment happens during static per-CPU lock initialisation
> with lockdep enabled.
>
> Allow relocation processing for the per-CPU section even if SHF_ALLOC is
> missing.
>
> Reported-by: kernel test robot <oliver.sang@intel.com>
> Closes: https://lore.kernel.org/oe-lkp/202506041623.e45e4f7d-lkp@intel.com
> Fixes: 1a6100caae425 ("Don't relocate non-allocated regions in modules.") #v2.6.1-rc3
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Reviewed-by: Petr Pavlu <petr.pavlu@suse.com>
--
Thanks,
Petr
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v3] module: Make sure relocations are applied to the per-CPU section
2025-06-10 16:33 [PATCH v3] module: Make sure relocations are applied to the per-CPU section Sebastian Andrzej Siewior
2025-06-12 11:47 ` Petr Pavlu
@ 2025-07-01 13:40 ` Daniel Gomez
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Gomez @ 2025-07-01 13:40 UTC (permalink / raw)
To: linux-modules, Sebastian Andrzej Siewior
Cc: Petr Pavlu, Luis Chamberlain, Sami Tolvanen, Peter Zijlstra,
Thomas Gleixner
On Tue, 10 Jun 2025 18:33:28 +0200, Sebastian Andrzej Siewior wrote:
> The per-CPU data section is handled differently than the other sections.
> The memory allocations requires a special __percpu pointer and then the
> section is copied into the view of each CPU. Therefore the SHF_ALLOC
> flag is removed to ensure move_module() skips it.
>
> Later, relocations are applied and apply_relocations() skips sections
> without SHF_ALLOC because they have not been copied. This also skips the
> per-CPU data section.
> The missing relocations result in a NULL pointer on x86-64 and very
> small values on x86-32. This results in a crash because it is not
> skipped like NULL pointer would and can't be dereferenced.
>
> [...]
Applied, thanks!
[1/1] module: Make sure relocations are applied to the per-CPU section
commit: 6c7ceed3f375bf9e2b093623af76df3094c88871
Best regards,
--
Daniel Gomez <da.gomez@samsung.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-01 13:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-10 16:33 [PATCH v3] module: Make sure relocations are applied to the per-CPU section Sebastian Andrzej Siewior
2025-06-12 11:47 ` Petr Pavlu
2025-07-01 13:40 ` Daniel Gomez
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).