asan: buffer overflow in loongarch_elf_rtype_to_howto
authorAlan Modra <amodra@gmail.com>
Tue, 26 Dec 2023 12:16:56 +0000 (22:46 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 27 Dec 2023 06:06:23 +0000 (16:36 +1030)
commit3bb1944a5a0527a38702084ac301d9933b0130bb
tree2582c76c696e90b536d58a279f6397190d0d8d8a
parent145c21056abeace6b3f6cafb65c29a7812036852
asan: buffer overflow in loongarch_elf_rtype_to_howto

Seen when running ld-loongarch-elf/tlsdesc-dso test.
elfxx-loongarch.c:1844:32: runtime error: index 125 out of bounds for
type 'loongarch_reloc_howto_type [124]'

So either the loongarch_howto_table needs three more
LOONGARCH_EMPTY_HOWTO entries, or loongarch_elf_rtype_to_howto should
be testing for r_type < ARRAY_SIZE (loongarch_howto_table).  I figure
it's worth wasting a little more space to get faster lookup.

* elfxx-loongarch.c (loongarch_howto_table): Add
LOONGARCH_EMPTY_HOWTO entries for 121..123.
(loongarch_elf_rtype_to_howto): Don't support slow lookup.
Assert exact table size and r_type indexing.  Omit return cast.
(loongarch_reloc_name_lookup): Omit assertion and return cast.
(loongarch_reloc_type_lookup): Likewise.
bfd/elfxx-loongarch.c