Don't write uninitialised data in .note.gnu.property

Message ID adZQXgzxZkBNOnhX@squeak.grove.modra.org
State New
Headers
Series Don't write uninitialised data in .note.gnu.property |

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 April 8, 2026, 12:55 p.m. UTC
  Seen when running the binutils x86-64 pr23494 tests.
_bfd_elf_convert_gnu_properties doesn't initialise its "contents"
buffer, and elf_write_gnu_properties doesn't write to padding.
Fix this by initialising the padding and then dispense with zeroing
contents in _bfd_elf_link_setup_gnu_properties.

	* elf-properties.c (elf_write_gnu_properties): Init padding.
	(_bfd_elf_link_setup_gnu_properties): Don't init contents.
  

Patch

diff --git a/bfd/elf-properties.c b/bfd/elf-properties.c
index 988b7d0dd02..e0a830704fd 100644
--- a/bfd/elf-properties.c
+++ b/bfd/elf-properties.c
@@ -670,7 +670,12 @@  elf_write_gnu_properties (struct bfd_link_info *info,
       size += datasz;
 
       /* Align each property.  */
-      size = (size + (align_size - 1)) & ~ (align_size - 1);
+      datasz = -size & (align_size - 1);
+      if (datasz)
+	{
+	  memset (contents + size, 0, datasz);
+	  size += datasz;
+	}
     }
 }
 
@@ -933,7 +938,7 @@  _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
 
       /* Update .note.gnu.property section now.  */
       sec->size = size;
-      contents = (bfd_byte *) bfd_zalloc (first_pbfd, size);
+      contents = bfd_alloc (first_pbfd, size);
 
       elf_write_gnu_properties (info, first_pbfd, contents, list, size,
 				align_size);