PR28055, segfault in bpf special reloc function

Alan Modra amodra@gmail.com
Tue Jul 6 01:14:28 GMT 2021


On Mon, Jul 05, 2021 at 10:37:35AM -0400, Simon Marchi wrote:
> On 2021-07-05 8:22 a.m., Alan Modra wrote:
> > The testcase in this PR tickled two bugs fixed here.  output_bfd is
> > NULL when a reloc special_function is called for final linking and
> > when called from bfd_generic_get_relocated_section_contents.  Clearly
> > using output_bfd is wrong as it results in segfaults.  Not only that,
> > the endianness of the reloc field really should be that of the input.
> > The second bug was not checking that the entire reloc field was
> > contained in the section contents.
> > 
> > I was going to add the following too, but it looks like this would
> > only be dead code since ld -r isn't supported in combination of input
> > and output that would see this special_function called.
> > 
> >   /* If this is a relocatable link (output_bfd test tells us), just
> >      call the generic function.  */
> >   if (abfd != output_bfd && output_bfd != NULL)
> >     return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
> > 				  input_section, output_bfd, error_message);
> > 
> > 
> > 	PR 28055
> > 	* elf64-bpf.c (bpf_elf_generic_reloc): Use correct bfd for bfd_put
> > 	and bfd_put_32 calls.  Correct section limit checks.
> 
> /home/simark/src/binutils-gdb/bfd/elf64-bpf.c: In function ‘bpf_elf_generic_reloc’:
> /home/simark/src/binutils-gdb/bfd/elf64-bpf.c:602:29: error: unused parameter ‘output_bfd’ [-Werror=unused-parameter]
>   602 |                        bfd *output_bfd,
>       |                        ~~~~~^~~~~~~~~~
> 

Oops.

	PR 28055
	* elf64-bpf.c (bpf_elf_generic_reloc): Add missing ATTRIBUTE_UNUSED.

diff --git a/bfd/elf64-bpf.c b/bfd/elf64-bpf.c
index 243df93ae82..beabad79aff 100644
--- a/bfd/elf64-bpf.c
+++ b/bfd/elf64-bpf.c
@@ -599,7 +599,7 @@ elf64_bpf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
 static bfd_reloc_status_type
 bpf_elf_generic_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
 		       void *data, asection *input_section,
-		       bfd *output_bfd,
+		       bfd *output_bfd ATTRIBUTE_UNUSED,
 		       char **error_message ATTRIBUTE_UNUSED)
 {



-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list