[PATCH 1/2] LoongArch: Avoid heap-buffer-overflow in loongarch_elf_relocate_section

Xi Ruoyao xry111@xry111.site
Thu Sep 15 06:13:45 GMT 2022


On Thu, 2022-09-15 at 11:54 +0800, liuzhensong wrote:

> > > > diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
> > > > index a9bb66a1e04..1e8ecb2b8e2 100644
> > > > --- a/bfd/elfnn-loongarch.c
> > > > +++ b/bfd/elfnn-loongarch.c
> > > > @@ -3129,6 +3129,7 @@ loongarch_elf_relocate_section (bfd
> > > > *output_bfd, struct bfd_link_info *info,
> > > >               BFD_ASSERT (rel->r_addend == 0);
> > > >    
> > > >               bfd_vma got_off = 0;
> > > > +             bool fill_got_entry = true;
> > > >               if (h != NULL)
> > > >                 {
> > > >                   /* GOT ref or ifunc.  */
> > > > @@ -3141,6 +3142,10 @@ loongarch_elf_relocate_section (bfd
> > > > *output_bfd, struct bfd_link_info *info,
> > > >                   if (h->got.offset == MINUS_ONE && h->type ==
> > > > STT_GNU_IFUNC)
> > > >                     {
> > > >                       bfd_vma idx;
> > > > +
> > > > +                     /* An IFUNC is always resolved at
> > > > runtime.  */
> Not correct, anything can be filled if h->got.offset != MINUS_ONE.
> There is no space for ifunc to fill got.

Alright, I'm not familiar with BFD and I don't want to spend too much
time (and brain cell deaths) learning it.  So I'll test your change and
if it works let's just do it in your way...

In the meantime please take a look of the 2nd patch, they are different
(and unrelated) issues.


-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University


More information about the Binutils mailing list