Date: Thu, 18 Jan 2024 22:26:04 GMT From: John Baldwin <jhb@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: cec0bae09eae - stable/14 - kldxref: Workaround incorrect PT_DYNAMIC in existing powerpc kernels Message-ID: <202401182226.40IMQ4HB089683@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=cec0bae09eaedff61b4e296e662a1c87757b8af9 commit cec0bae09eaedff61b4e296e662a1c87757b8af9 Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2024-01-09 18:57:48 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2024-01-18 21:32:12 +0000 kldxref: Workaround incorrect PT_DYNAMIC in existing powerpc kernels Existing powerpc kernels include additional sections beyond .dynamic in the PT_DYNAMIC segment. Relax the requirement for an exact size match of the section and segment for PowerPC files as a workaround. Reported by: jrtc27 Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D43123 (cherry picked from commit 6631e2f9b49e08f53c7beb560ee8509c343b3927) --- usr.sbin/kldxref/ef.c | 11 ++++++++++- usr.sbin/kldxref/ef.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/usr.sbin/kldxref/ef.c b/usr.sbin/kldxref/ef.c index fd0782ff1dd0..1ef27f2bc54a 100644 --- a/usr.sbin/kldxref/ef.c +++ b/usr.sbin/kldxref/ef.c @@ -248,8 +248,17 @@ ef_parse_dynamic(elf_file_t ef, const GElf_Phdr *phdyn) dynamic_idx = -1; for (i = 0; i < nshdr; i++) { if (shdr[i].sh_type == SHT_DYNAMIC) { + /* + * PowerPC kernels contain additional sections + * beyond .dynamic in PT_DYNAMIC due to a linker + * script bug. Permit a section with a smaller + * size as a workaround. + */ if (shdr[i].sh_offset != phdyn->p_offset || - shdr[i].sh_size != phdyn->p_filesz) { + ((elf_machine(ef->ef_efile) == EM_PPC || + elf_machine(ef->ef_efile) == EM_PPC64) ? + shdr[i].sh_size > phdyn->p_filesz : + shdr[i].sh_size != phdyn->p_filesz)) { warnx(".dynamic section doesn't match phdr"); error = EFTYPE; goto out; diff --git a/usr.sbin/kldxref/ef.h b/usr.sbin/kldxref/ef.h index 2909704bf2d1..25dc5216b169 100644 --- a/usr.sbin/kldxref/ef.h +++ b/usr.sbin/kldxref/ef.h @@ -100,6 +100,7 @@ struct elf_file { int ef_fd; }; +#define elf_machine(ef) ((ef)->ef_hdr.e_machine) #define elf_class(ef) ((ef)->ef_hdr.e_ident[EI_CLASS]) #define elf_encoding(ef) ((ef)->ef_hdr.e_ident[EI_DATA])
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202401182226.40IMQ4HB089683>