Skip to content

Commit d356864

Browse files
Maria Yuctmarinas
authored andcommitted
arm64: module: Fix PLT counting when CONFIG_RANDOMIZE_BASE=n
The counting of module PLTs has been broken when CONFIG_RANDOMIZE_BASE=n since commit: 3e35d30 ("arm64: module: rework module VA range selection") Prior to that commit, when CONFIG_RANDOMIZE_BASE=n, the kernel image and all modules were placed within a 128M region, and no PLTs were necessary for B or BL. Hence count_plts() and partition_branch_plt_relas() skipped handling B and BL when CONFIG_RANDOMIZE_BASE=n. After that commit, modules can be placed anywhere within a 2G window regardless of CONFIG_RANDOMIZE_BASE, and hence PLTs may be necessary for B and BL even when CONFIG_RANDOMIZE_BASE=n. Unfortunately that commit failed to update count_plts() and partition_branch_plt_relas() accordingly. Due to this, module_emit_plt_entry() may fail if an insufficient number of PLT entries have been reserved, resulting in modules failing to load with -ENOEXEC. Fix this by counting PLTs regardless of CONFIG_RANDOMIZE_BASE in count_plts() and partition_branch_plt_relas(). Fixes: 3e35d30 ("arm64: module: rework module VA range selection") Signed-off-by: Maria Yu <quic_aiquny@quicinc.com> Cc: <stable@vger.kernel.org> # 6.5.x Acked-by: Ard Biesheuvel <ardb@kernel.org> Fixes: 3e35d30 ("arm64: module: rework module VA range selection") Reviewed-by: Mark Rutland <mark.rutland@arm.com> Link: https://lore.kernel.org/r/20231024010954.6768-1-quic_aiquny@quicinc.com Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent c54e52f commit d356864

File tree

1 file changed

+0
-6
lines changed

1 file changed

+0
-6
lines changed

arch/arm64/kernel/module-plts.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ static unsigned int count_plts(Elf64_Sym *syms, Elf64_Rela *rela, int num,
167167
switch (ELF64_R_TYPE(rela[i].r_info)) {
168168
case R_AARCH64_JUMP26:
169169
case R_AARCH64_CALL26:
170-
if (!IS_ENABLED(CONFIG_RANDOMIZE_BASE))
171-
break;
172-
173170
/*
174171
* We only have to consider branch targets that resolve
175172
* to symbols that are defined in a different section.
@@ -269,9 +266,6 @@ static int partition_branch_plt_relas(Elf64_Sym *syms, Elf64_Rela *rela,
269266
{
270267
int i = 0, j = numrels - 1;
271268

272-
if (!IS_ENABLED(CONFIG_RANDOMIZE_BASE))
273-
return 0;
274-
275269
while (i < j) {
276270
if (branch_rela_needs_plt(syms, &rela[i], dstidx))
277271
i++;

0 commit comments

Comments
 (0)