loongson buffer overflow

Message ID Z5W74JAD90OJGwtk@squeak.grove.modra.org
State New
Headers
Series loongson buffer overflow |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Alan Modra Jan. 26, 2025, 4:36 a.m. UTC
  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.
  

Comments

mengqinggang Jan. 26, 2025, 12:46 p.m. UTC | #1
Hi Nick,

This patch (commit: 59ba00f21f7) needs to be applied to 2.44 branch.

Thanks!


在 2025/1/26 下午12:36, Alan Modra 写道:
> 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.
>
> diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
> index efa57184e44..c24b2600a9a 100644
> --- a/bfd/elfnn-loongarch.c
> +++ b/bfd/elfnn-loongarch.c
> @@ -5267,8 +5267,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.
>
  
Alan Modra Jan. 26, 2025, 9:42 p.m. UTC | #2
On Sun, Jan 26, 2025 at 08:46:52PM +0800, mengqinggang wrote:
> Hi Nick,
> 
> This patch (commit: 59ba00f21f7) needs to be applied to 2.44 branch.

Yes, and the fix for pr32599 too, commit fd45211245d0.

OK?

> 在 2025/1/26 下午12:36, Alan Modra 写道:
> > 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.
> > 
> > diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
> > index efa57184e44..c24b2600a9a 100644
> > --- a/bfd/elfnn-loongarch.c
> > +++ b/bfd/elfnn-loongarch.c
> > @@ -5267,8 +5267,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.
> >
  
Nick Clifton Jan. 27, 2025, 1:27 p.m. UTC | #3
Hi Alan, Hi mengqinggang

>> This patch (commit: 59ba00f21f7) needs to be applied to 2.44 branch.
> 
> Yes, and the fix for pr32599 too, commit fd45211245d0.

Ok to both.


Cheers
   Nick
  

Patch

diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index efa57184e44..c24b2600a9a 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -5267,8 +5267,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.