Return error if relocation offset + relocation size > section size.
bfd/
PR ld/32665
* elf32-i386.c (elf_i386_scan_relocs): Return error for invalid
relocation offset.
* elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise.
ld/
PR ld/32665
* testsuite/ld-x86-64/pr32665.err: New file.
* testsuite/ld-x86-64/pr32665.o.bz2: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run PR ld/32665 test.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
const char *name;
bool size_reloc;
bool no_dynreloc;
+ reloc_howto_type *howto;
r_symndx = ELF32_R_SYM (rel->r_info);
r_type = ELF32_R_TYPE (rel->r_info);
goto error_return;
}
+ howto = elf_i386_rtype_to_howto (r_type);
+ if (rel->r_offset + bfd_get_reloc_size (howto) > sec->size)
+ {
+ /* xgettext:c-format */
+ _bfd_error_handler
+ (_("%pB: bad reloc offset (%#" PRIx32 " > %#" PRIx32 ") for"
+ " section `%pA'"), abfd, (uint32_t) rel->r_offset,
+ (uint32_t) sec->size, sec);
+ goto error_return;
+ }
+
if (r_symndx < symtab_hdr->sh_info)
{
/* A local symbol. */
bool size_reloc;
bool converted_reloc;
bool no_dynreloc;
+ reloc_howto_type *howto;
r_symndx = htab->r_sym (rel->r_info);
r_type = ELF32_R_TYPE (rel->r_info);
goto error_return;
}
+ howto = elf_x86_64_rtype_to_howto (abfd, r_type);
+ if (rel->r_offset + bfd_get_reloc_size (howto) > sec->size)
+ {
+ /* xgettext:c-format */
+ _bfd_error_handler
+ (_("%pB: bad reloc offset (%#" PRIx64 " > %#" PRIx64 ") for"
+ " section `%pA'"), abfd, (uint64_t) rel->r_offset,
+ (uint64_t) sec->size, sec);
+ goto error_return;
+ }
+
if (r_symndx < symtab_hdr->sh_info)
{
/* A local symbol. */
--- /dev/null
+#...
+.*tmpdir/pr32665.o: bad reloc offset \(0xf2ffffff01bc > 0x574\) for section `.text'
+#...
{"Build textrel-1" "-no-pie -melf_x86_64 -z nocopyreloc --warn-textrel"
"tmpdir/textrel-1.so"
"--64" { textrel-1b.s } {{ld "textrel-1.err"}} "textrel-1"}
+ {"Build pr32665"
+ "-melf_x86_64"
+ "" ""
+ { pr32665.o.bz2 }
+ {{ld "pr32665.err"}} "pr32665"}
}
run_ld_link_tests $x86_64tests