Skip to content

Commit e5d5d23

Browse files
committed
Merge tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux
Pull arm64 fixes from Catalin Marinas: - Incorrect __BITS_PER_LONG as 64 when compiling the compat vDSO - Unreachable PLT for ftrace_caller() in a module's .init.text following past reworking of the module VA range selection - Memory leak in the ACPI iort_rmr_alloc_sids() after a failed krealloc_array() * tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux: arm64: ftrace: fix unreachable PLT for ftrace_caller in init_module with CONFIG_DYNAMIC_FTRACE ACPI/IORT: Fix memory leak in iort_rmr_alloc_sids() arm64: uapi: Provide correct __BITS_PER_LONG for the compat vDSO
2 parents 730c145 + a7ed7b9 commit e5d5d23

File tree

7 files changed

+42
-5
lines changed

7 files changed

+42
-5
lines changed

arch/arm64/include/asm/module.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct mod_arch_specific {
1919

2020
/* for CONFIG_DYNAMIC_FTRACE */
2121
struct plt_entry *ftrace_trampolines;
22+
struct plt_entry *init_ftrace_trampolines;
2223
};
2324

2425
u64 module_emit_plt_entry(struct module *mod, Elf64_Shdr *sechdrs,

arch/arm64/include/asm/module.lds.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ SECTIONS {
22
.plt 0 : { BYTE(0) }
33
.init.plt 0 : { BYTE(0) }
44
.text.ftrace_trampoline 0 : { BYTE(0) }
5+
.init.text.ftrace_trampoline 0 : { BYTE(0) }
56

67
#ifdef CONFIG_KASAN_SW_TAGS
78
/*

arch/arm64/include/uapi/asm/bitsperlong.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
#ifndef __ASM_BITSPERLONG_H
1818
#define __ASM_BITSPERLONG_H
1919

20+
#if defined(__KERNEL__) && !defined(__aarch64__)
21+
/* Used by the compat vDSO */
22+
#define __BITS_PER_LONG 32
23+
#else
2024
#define __BITS_PER_LONG 64
25+
#endif
2126

2227
#include <asm-generic/bitsperlong.h>
2328

arch/arm64/kernel/ftrace.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,17 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
258258
return ftrace_modify_code(pc, 0, new, false);
259259
}
260260

261-
static struct plt_entry *get_ftrace_plt(struct module *mod)
261+
static struct plt_entry *get_ftrace_plt(struct module *mod, unsigned long addr)
262262
{
263263
#ifdef CONFIG_MODULES
264-
struct plt_entry *plt = mod->arch.ftrace_trampolines;
264+
struct plt_entry *plt = NULL;
265+
266+
if (within_module_mem_type(addr, mod, MOD_INIT_TEXT))
267+
plt = mod->arch.init_ftrace_trampolines;
268+
else if (within_module_mem_type(addr, mod, MOD_TEXT))
269+
plt = mod->arch.ftrace_trampolines;
270+
else
271+
return NULL;
265272

266273
return &plt[FTRACE_PLT_IDX];
267274
#else
@@ -332,7 +339,7 @@ static bool ftrace_find_callable_addr(struct dyn_ftrace *rec,
332339
if (WARN_ON(!mod))
333340
return false;
334341

335-
plt = get_ftrace_plt(mod);
342+
plt = get_ftrace_plt(mod, pc);
336343
if (!plt) {
337344
pr_err("ftrace: no module PLT for %ps\n", (void *)*addr);
338345
return false;

arch/arm64/kernel/module-plts.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
283283
unsigned long core_plts = 0;
284284
unsigned long init_plts = 0;
285285
Elf64_Sym *syms = NULL;
286-
Elf_Shdr *pltsec, *tramp = NULL;
286+
Elf_Shdr *pltsec, *tramp = NULL, *init_tramp = NULL;
287287
int i;
288288

289289
/*
@@ -298,6 +298,9 @@ int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
298298
else if (!strcmp(secstrings + sechdrs[i].sh_name,
299299
".text.ftrace_trampoline"))
300300
tramp = sechdrs + i;
301+
else if (!strcmp(secstrings + sechdrs[i].sh_name,
302+
".init.text.ftrace_trampoline"))
303+
init_tramp = sechdrs + i;
301304
else if (sechdrs[i].sh_type == SHT_SYMTAB)
302305
syms = (Elf64_Sym *)sechdrs[i].sh_addr;
303306
}
@@ -363,5 +366,12 @@ int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
363366
tramp->sh_size = NR_FTRACE_PLTS * sizeof(struct plt_entry);
364367
}
365368

369+
if (init_tramp) {
370+
init_tramp->sh_type = SHT_NOBITS;
371+
init_tramp->sh_flags = SHF_EXECINSTR | SHF_ALLOC;
372+
init_tramp->sh_addralign = __alignof__(struct plt_entry);
373+
init_tramp->sh_size = NR_FTRACE_PLTS * sizeof(struct plt_entry);
374+
}
375+
366376
return 0;
367377
}

arch/arm64/kernel/module.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,17 @@ static int module_init_ftrace_plt(const Elf_Ehdr *hdr,
466466
__init_plt(&plts[FTRACE_PLT_IDX], FTRACE_ADDR);
467467

468468
mod->arch.ftrace_trampolines = plts;
469+
470+
s = find_section(hdr, sechdrs, ".init.text.ftrace_trampoline");
471+
if (!s)
472+
return -ENOEXEC;
473+
474+
plts = (void *)s->sh_addr;
475+
476+
__init_plt(&plts[FTRACE_PLT_IDX], FTRACE_ADDR);
477+
478+
mod->arch.init_ftrace_trampolines = plts;
479+
469480
#endif
470481
return 0;
471482
}

drivers/acpi/arm64/iort.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,10 @@ static u32 *iort_rmr_alloc_sids(u32 *sids, u32 count, u32 id_start,
937937

938938
new_sids = krealloc_array(sids, count + new_count,
939939
sizeof(*new_sids), GFP_KERNEL);
940-
if (!new_sids)
940+
if (!new_sids) {
941+
kfree(sids);
941942
return NULL;
943+
}
942944

943945
for (i = count; i < total_count; i++)
944946
new_sids[i] = id_start++;

0 commit comments

Comments
 (0)