[binutils-gdb/binutils-2_44-branch] loongson buffer overflow

Alan Modra amodra@sourceware.org
Mon Jan 27 21:12:41 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4ab1e3728b29b14b0e5dce787475ddb3cd590a3f

commit 4ab1e3728b29b14b0e5dce787475ddb3cd590a3f
Author: Alan Modra <amodra@gmail.com>
Date:   Sun Jan 26 13:12:45 2025 +1030

    loongson buffer overflow
    
    bfd_elfNN_loongarch_set_data_segment_info can be called from the target
    after_allocation function with a non-ELF hash table.  This is seen in
    the ld-elf pr21884 testcase.  Fix the problem by first checking the
    hash table type before writing to a loongarch_elf_hash_table field.
    
    (cherry picked from commit 59ba00f21f7d48780e92a9fb66ed4abbedc3bd28)

Diff:
---
 bfd/elfnn-loongarch.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index 80d2c445d03..fc1cbbea71a 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -5264,8 +5264,9 @@ void
 bfd_elfNN_loongarch_set_data_segment_info (struct bfd_link_info *info,
 				     int *data_segment_phase)
 {
-  struct loongarch_elf_link_hash_table *htab = loongarch_elf_hash_table (info);
-  htab->data_segment_phase = data_segment_phase;
+  if (is_elf_hash_table (info->hash)
+      && elf_hash_table_id (elf_hash_table (info)) == LARCH_ELF_DATA)
+    loongarch_elf_hash_table (info)->data_segment_phase = data_segment_phase;
 }
 
 /* Implement R_LARCH_ALIGN by deleting excess alignment NOPs.


More information about the Binutils-cvs mailing list