Skip to content

Commit 570db4b

Browse files
Sebastian Andrzej Siewiordkruces
authored andcommitted
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 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 <[email protected]> Closes: https://lore.kernel.org/oe-lkp/[email protected] Fixes: 1a6100caae425 ("Don't relocate non-allocated regions in modules.") #v2.6.1-rc3 Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Reviewed-by: Petr Pavlu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Daniel Gomez <[email protected]> Message-ID: <[email protected]>
1 parent eb0994a commit 570db4b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

kernel/module/main.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,8 +1573,14 @@ static int apply_relocations(struct module *mod, const struct load_info *info)
15731573
if (infosec >= info->hdr->e_shnum)
15741574
continue;
15751575

1576-
/* Don't bother with non-allocated sections */
1577-
if (!(info->sechdrs[infosec].sh_flags & SHF_ALLOC))
1576+
/*
1577+
* Don't bother with non-allocated sections.
1578+
* An exception is the percpu section, which has separate allocations
1579+
* for individual CPUs. We relocate the percpu section in the initial
1580+
* ELF template and subsequently copy it to the per-CPU destinations.
1581+
*/
1582+
if (!(info->sechdrs[infosec].sh_flags & SHF_ALLOC) &&
1583+
(!infosec || infosec != info->index.pcpu))
15781584
continue;
15791585

15801586
if (info->sechdrs[i].sh_flags & SHF_RELA_LIVEPATCH)

0 commit comments

Comments
 (0)