Skip to content

Commit

Permalink
[PowerPC][Book-E] Fix missing load base in elf_cpu_parse_dynamic().
Browse files Browse the repository at this point in the history
When I implemented MD DYNAMIC parsing, I was originally passing a
linker_file_t so that the MD code could relocate pointers.

However, it turns out this isn't even filled in until later, so it was
always 0.

Just pass the load base (ef->address) directly, as that's really the only
thing we were interested in in the first place.

This fixes a crash on RB800 where it was trying to write to an unmapped
address when updating the GOT.

Reviewed by:	jhibbits
Sponsored by:	Tag1 Consulting, Inc.
Differential Revision:	https://reviews.freebsd.org/D24105
  • Loading branch information
bdragon28 committed Mar 18, 2020
1 parent 0a70e97 commit 3069380
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion sys/amd64/amd64/elf_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ elf_cpu_unload_file(linker_file_t lf __unused)
}

int
elf_cpu_parse_dynamic(linker_file_t lf __unused, Elf_Dyn *dynamic __unused)
elf_cpu_parse_dynamic(caddr_t loadbase __unused, Elf_Dyn *dynamic __unused)
{

return (0);
Expand Down
2 changes: 1 addition & 1 deletion sys/arm/arm/elf_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ elf_cpu_load_file(linker_file_t lf)
}

int
elf_cpu_parse_dynamic(linker_file_t lf __unused, Elf_Dyn *dynamic __unused)
elf_cpu_parse_dynamic(caddr_t loadbase __unused, Elf_Dyn *dynamic __unused)
{

return (0);
Expand Down
2 changes: 1 addition & 1 deletion sys/arm64/arm64/elf_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ elf_cpu_unload_file(linker_file_t lf __unused)
}

int
elf_cpu_parse_dynamic(linker_file_t lf __unused, Elf_Dyn *dynamic __unused)
elf_cpu_parse_dynamic(caddr_t loadbase __unused, Elf_Dyn *dynamic __unused)
{

return (0);
Expand Down
2 changes: 1 addition & 1 deletion sys/i386/i386/elf_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ elf_cpu_unload_file(linker_file_t lf __unused)
}

int
elf_cpu_parse_dynamic(linker_file_t lf __unused, Elf_Dyn *dynamic __unused)
elf_cpu_parse_dynamic(caddr_t loadbase __unused, Elf_Dyn *dynamic __unused)
{

return (0);
Expand Down
2 changes: 1 addition & 1 deletion sys/kern/link_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ parse_dynamic(elf_file_t ef)
ef->ddbstrtab = ef->strtab;
ef->ddbstrcnt = ef->strsz;

return elf_cpu_parse_dynamic(&ef->lf, ef->dynamic);
return elf_cpu_parse_dynamic(ef->address, ef->dynamic);
}

#define LS_PADDING 0x90909090
Expand Down
2 changes: 1 addition & 1 deletion sys/mips/mips/elf_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ elf_cpu_unload_file(linker_file_t lf __unused)
}

int
elf_cpu_parse_dynamic(linker_file_t lf __unused, Elf_Dyn *dynamic __unused)
elf_cpu_parse_dynamic(caddr_t loadbase __unused, Elf_Dyn *dynamic __unused)
{

return (0);
Expand Down
4 changes: 2 additions & 2 deletions sys/powerpc/powerpc/elf32_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ ppc32_runtime_resolve()
}

int
elf_cpu_parse_dynamic(linker_file_t lf, Elf_Dyn *dynamic)
elf_cpu_parse_dynamic(caddr_t loadbase, Elf_Dyn *dynamic)
{
Elf_Dyn *dp;
bool has_plt = false;
Expand All @@ -414,7 +414,7 @@ elf_cpu_parse_dynamic(linker_file_t lf, Elf_Dyn *dynamic)
switch (dp->d_tag) {
case DT_PPC_GOT:
secure_plt = true;
got = (Elf_Addr *)(lf->address + dp->d_un.d_ptr);
got = (Elf_Addr *)(loadbase + dp->d_un.d_ptr);
/* Install runtime resolver canary. */
got[1] = (Elf_Addr)ppc32_runtime_resolve;
got[2] = (Elf_Addr)0;
Expand Down
2 changes: 1 addition & 1 deletion sys/powerpc/powerpc/elf64_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ elf_cpu_unload_file(linker_file_t lf __unused)
}

int
elf_cpu_parse_dynamic(linker_file_t lf __unused, Elf_Dyn *dynamic __unused)
elf_cpu_parse_dynamic(caddr_t loadbase __unused, Elf_Dyn *dynamic __unused)
{

return (0);
Expand Down
2 changes: 1 addition & 1 deletion sys/riscv/riscv/elf_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ elf_cpu_unload_file(linker_file_t lf __unused)
}

int
elf_cpu_parse_dynamic(linker_file_t lf __unused, Elf_Dyn *dynamic __unused)
elf_cpu_parse_dynamic(caddr_t loadbase __unused, Elf_Dyn *dynamic __unused)
{

return (0);
Expand Down
2 changes: 1 addition & 1 deletion sys/sys/linker.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ int linker_ctf_get(linker_file_t, linker_ctf_t *);

int elf_cpu_load_file(linker_file_t);
int elf_cpu_unload_file(linker_file_t);
int elf_cpu_parse_dynamic(linker_file_t, Elf_Dyn *);
int elf_cpu_parse_dynamic(caddr_t, Elf_Dyn *);

/* values for type */
#define ELF_RELOC_REL 1
Expand Down

0 comments on commit 3069380

Please sign in to comment.