Skip to content

Commit 1208b44

Browse files
prudo1gregkh
authored andcommitted
s390/kexec_file: fix error handling when applying relocations
[ Upstream commit 41967a3 ] arch_kexec_apply_relocations_add currently ignores all errors returned by arch_kexec_do_relocs. This means that every unknown relocation is silently skipped causing unpredictable behavior while the relocated code runs. Fix this by checking for errors and fail kexec_file_load if an unknown relocation type is encountered. The problem was found after gcc changed its behavior and used R_390_PLT32DBL relocations for brasl instruction and relied on ld to resolve the relocations in the final link in case direct calls are possible. As the purgatory code is only linked partially (option -r) ld didn't resolve the relocations leaving them for arch_kexec_do_relocs. But arch_kexec_do_relocs doesn't know how to handle R_390_PLT32DBL relocations so they were silently skipped. This ultimately caused an endless loop in the purgatory as the brasl instructions kept branching to itself. Fixes: 7140688 ("s390/kexec_file: Add kexec_file_load system call") Reported-by: Tao Liu <ltao@redhat.com> Signed-off-by: Philipp Rudo <prudo@redhat.com> Link: https://lore.kernel.org/r/20211208130741.5821-3-prudo@redhat.com Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent c058c54 commit 1208b44

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎arch/s390/kernel/machine_kexec_file.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
277277
{
278278
Elf_Rela *relas;
279279
int i, r_type;
280+
int ret;
280281

281282
relas = (void *)pi->ehdr + relsec->sh_offset;
282283

@@ -311,7 +312,11 @@ int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
311312
addr = section->sh_addr + relas[i].r_offset;
312313

313314
r_type = ELF64_R_TYPE(relas[i].r_info);
314-
arch_kexec_do_relocs(r_type, loc, val, addr);
315+
ret = arch_kexec_do_relocs(r_type, loc, val, addr);
316+
if (ret) {
317+
pr_err("Unknown rela relocation: %d\n", r_type);
318+
return -ENOEXEC;
319+
}
315320
}
316321
return 0;
317322
}

0 commit comments

Comments
 (0)