Skip to content

Commit 7278212

Browse files
committed
Merge tag 'modules-6.16-rc6.fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/modules/linux
Pull modules fixes from Daniel Gomez: "This includes two fixes: one introduced in the current release cycle and another introduced back in v6.4-rc1. Additionally, as Petr and Luis mentioned in previous pull requests, add myself (Daniel Gomez) to the list of modules maintainers. The first was reported by Intel's kernel test robot, and it addresses a crash exposed by Sebastian's commit c50d295 ("rds: Use nested-BH locking for rds_page_remainder") by allowing relocations for the per-CPU section even if it lacks the SHF_ALLOC flag. Petr and Sebastian went down to the archive history (before Git) and found the commit that broke it at [1] / [2] ("Don't relocate non-allocated regions in modules."). The second fix, reported and fixed by Petr (with additional cleanup), resolves a memory leak by ensuring proper deallocation if module loading fails. We couldn't find a reproducer other than forcing it manually or leveraging eBPF. So, I tested it by enabling error injection in the codetag functions through the error path that produces the leak and made it fail until execmem is unable to allocate more memory" Link: https://git.kernel.org/pub/scm/linux/kernel/git/mpe/linux-fullhistory.git/commit/?id=b3b91325f3c7 [1] Link: https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/?id=1a6100caae [2] * tag 'modules-6.16-rc6.fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/modules/linux: MAINTAINERS: update Daniel Gomez's role and email address module: Make sure relocations are applied to the per-CPU section module: Avoid unnecessary return value initialization in move_module() module: Fix memory deallocation on error path in move_module()
2 parents 2dbae28 + af1ccf5 commit 7278212

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16824,8 +16824,8 @@ F: include/dt-bindings/clock/mobileye,eyeq5-clk.h
1682416824
MODULE SUPPORT
1682516825
M: Luis Chamberlain <[email protected]>
1682616826
M: Petr Pavlu <[email protected]>
16827+
M: Daniel Gomez <[email protected]>
1682716828
R: Sami Tolvanen <[email protected]>
16828-
R: Daniel Gomez <[email protected]>
1682916829
1683016830
1683116831
S: Maintained

kernel/module/main.c

Lines changed: 11 additions & 6 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)
@@ -2696,9 +2702,8 @@ static int find_module_sections(struct module *mod, struct load_info *info)
26962702

26972703
static int move_module(struct module *mod, struct load_info *info)
26982704
{
2699-
int i;
2700-
enum mod_mem_type t = 0;
2701-
int ret = -ENOMEM;
2705+
int i, ret;
2706+
enum mod_mem_type t = MOD_MEM_NUM_TYPES;
27022707
bool codetag_section_found = false;
27032708

27042709
for_each_mod_mem_type(type) {
@@ -2776,7 +2781,7 @@ static int move_module(struct module *mod, struct load_info *info)
27762781
return 0;
27772782
out_err:
27782783
module_memory_restore_rox(mod);
2779-
for (t--; t >= 0; t--)
2784+
while (t--)
27802785
module_memory_free(mod, t);
27812786
if (codetag_section_found)
27822787
codetag_free_module_sections(mod);

0 commit comments

Comments
 (0)