Skip to content

Commit

Permalink
kldxref: Workaround incorrect PT_DYNAMIC in existing powerpc kernels
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bsdjhb committed Mar 14, 2024
2 parents 6a6ce1a + 6631e2f commit 891b896
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion usr.sbin/kldxref/ef.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,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;
Expand Down
1 change: 1 addition & 0 deletions usr.sbin/kldxref/ef.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ struct elf_file {
bool ef_cheriabi;
};

#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])
#define elf_machine(ef) ((ef)->ef_hdr.e_machine)
Expand Down

0 comments on commit 891b896

Please sign in to comment.