Re: [PATCH v2] elf: Set this_idx to -1 for invalid relocations
"H.J. Lu" <[email protected]> Tue, 4 Aug 2026 16:57:45 +0800
| Newsgroups | gmane.comp.gnu.binutils |
|---|---|
| Message-ID | <CAMe9rOoAZSvYQ8Yb-yZa1W69k=g4OKjmCfjvHYNiYO-U5MPCSw@mail.gmail.com> |
On Tue, Aug 4, 2026 at 3:42=E2=80=AFPM Jan Beulich <[email protected]> wrot= e: > > On 04.08.2026 00:20, H.J. Lu wrote: > > On Mon, Aug 3, 2026 at 8:51=E2=80=AFPM Alan Modra <[email protected]> wr= ote: > >> > >> On Mon, Aug 03, 2026 at 07:58:27AM +0800, H.J. Lu wrote: > >>> On Mon, Aug 3, 2026 at 7:43=E2=80=AFAM Alan Modra <[email protected]> = wrote: > >>>> > >>>> On Sun, Aug 02, 2026 at 08:55:00AM +0800, H.J. Lu wrote: > >>>>> On Sun, Aug 2, 2026 at 6:18=E2=80=AFAM H.J. Lu <[email protected]= > wrote: > >>>>>> > >>>>>> When invalid relocation is reported by elf_link_read_relocs_from_s= ection > >>>>>> called from lang_gc_sections: > >>>>>> > >>>>>> ld: pr34448-bug_18.o: bad reloc symbol index (0xf2000005 >=3D 0x13= ) for > >>>>>> offset 0x4 in section `.text.get_tls[get_tls]' > >>>>>> > >>>>>> the same error is reported again: > >>>>>> > >>>>>> ld: pr34448-bug_18.o: bad reloc symbol index (0xf2000005 >=3D 0x13= ) for > >>>>>> offset 0x4 in section `.text.get_tls[get_tls]' > >>>> > >>>> Using this_idx as a flag is a bad idea. > >>>> > >>>> I also think that no one should be too concerned about error message= s > >>>> from fuzzed object files, so if you are going to fix this minor > >>>> problem do so in a way that won't potentially break the linker. > >>>> > >>> > >>> Then should linker stop when seeing a fuzzed object file, instead of = keep > >>> going and crash later? > >> > >> How is this relevant to a patch about duplicate error messages? > > > > If we don't care too much about fuzzed object files, why doesn't linker > > stop when seeing them? > > How would you (non-heuristically, i.e. entirely reliably) tell a fuzzed o= bject > from a "real" one? > > Jan When linker reaches the following code if (nsyms > 0) { if ((size_t) r_symndx >=3D nsyms) { _bfd_error_handler /* xgettext:c-format */ (_("%pB: bad reloc symbol index (%#" PRIx64 " >=3D %#lx)" " for offset %#" PRIx64 " in section `%pA'"), abfd, (uint64_t) r_symndx, (unsigned long) nsyms, (uint64_t) irela->r_offset, sec); elf_section_data (sec)->this_idx =3D ELF_SECTION_WITH_INVALID_RELOCATION; bfd_set_error (bfd_error_bad_value); return false; } } else if (r_symndx !=3D STN_UNDEF) { _bfd_error_handler /* xgettext:c-format */ (_("%pB: non-zero symbol index (%#" PRIx64 ")" " for offset %#" PRIx64 " in section `%pA'" " when the object file has no symbol table"), abfd, (uint64_t) r_symndx, (uint64_t) irela->r_offset, sec); elf_section_data (sec)->this_idx =3D ELF_SECTION_WITH_INVALID_RELOCATION; bfd_set_error (bfd_error_bad_value); return false; } in elf_link_read_relocs_from_section, the input isn't a valid ELF object file. It could be a fuzzed object. --=20 H.J.