[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250604152707.CieD9tN0@linutronix.de>
Date: Wed, 4 Jun 2025 17:27:07 +0200
From: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
To: linux-modules@...r.kernel.org
Cc: oe-lkp@...ts.linux.dev, lkp@...el.com, linux-kernel@...r.kernel.org,
kernel test robot <oliver.sang@...el.com>,
Paolo Abeni <pabeni@...hat.com>,
Allison Henderson <allison.henderson@...cle.com>,
netdev@...r.kernel.org, linux-rdma@...r.kernel.org,
rds-devel@....oracle.com, Luis Chamberlain <mcgrof@...nel.org>,
Petr Pavlu <petr.pavlu@...e.com>,
Sami Tolvanen <samitolvanen@...gle.com>,
Daniel Gomez <da.gomez@...sung.com>,
Peter Zijlstra <peterz@...radead.org>,
Thomas Gleixner <tglx@...utronix.de>
Subject: [PATCH] module: Make sure relocations are applied to the per-CPU
section
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 it can't be dereferenced.
Such an assignment happens during compile time per-CPU lock
initialisation with lockdep enabled.
Add the SHF_ALLOC flag back for the per-CPU section after move_module().
Reported-by: kernel test robot <oliver.sang@...el.com>
Closes: https://lore.kernel.org/oe-lkp/202506041623.e45e4f7d-lkp@intel.com
Fixes: 8d8022e8aba85 ("module: do percpu allocation after uniqueness check. No, really!")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
---
kernel/module/main.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/module/main.c b/kernel/module/main.c
index 5c6ab20240a6d..35abb5f13d7dc 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -2816,6 +2816,9 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
if (err)
return ERR_PTR(err);
+ /* Add SHF_ALLOC back so that relocations are applied. */
+ info->sechdrs[info->index.pcpu].sh_flags |= SHF_ALLOC;
+
/* Module has been copied to its final place now: return it. */
mod = (void *)info->sechdrs[info->index.mod].sh_addr;
kmemleak_load_module(mod, info);
--
2.49.0
Powered by blists - more mailing lists