This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] readelf: Check alignment of note section


gABI specifies that PT_NOTE alignment should be aligned to 4 bytes
for 32-bit objects and to 8 bytes for 64-bit objects.  But on Linux,
.note.ABI-tag and .note.gnu.build-id notes are always aligned to 4
bytes.  We allow either 4 byte or 8 byte alignments.

OK for master?

H.J.
---
	* readelf.c (process_notes_at): Return FALSE if alignment of
	note section isn't 4 nor 8 bytes.
---
 binutils/readelf.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/binutils/readelf.c b/binutils/readelf.c
index 739367d899..2c2ba63799 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -17910,6 +17910,7 @@ process_notes_at (Filedata *           filedata,
   Elf_External_Note * external;
   char * end;
   bfd_boolean res = TRUE;
+  bfd_vma align;
 
   if (length <= 0)
     return FALSE;
@@ -17929,6 +17930,15 @@ process_notes_at (Filedata *           filedata,
   if (pnotes == NULL)
     return FALSE;
 
+  /* gABI specifies that PT_NOTE alignment should be aligned to 4
+     bytes for 32-bit objects and to 8 bytes for 64-bit objects.
+     But on Linux, .note.ABI-tag and .note.gnu.build-id notes are
+     always aligned to 4 bytes.  We allow either 4 byte or 8 byte
+     alignments.  */
+  align = section->sh_addralign;
+  if (align != 4 || align != 8)
+    return FALSE;
+
   external = pnotes;
 
   if (section)
@@ -17971,11 +17981,11 @@ process_notes_at (Filedata *           filedata,
 	  inote.descsz   = BYTE_GET (external->descsz);
 	  inote.descdata = ((char *) external
 			    + ELF_NOTE_DESC_OFFSET (inote.namesz,
-						    section->sh_addralign));
+						    align));
 	  inote.descpos  = offset + (inote.descdata - (char *) pnotes);
 	  next = ((char *) external
 		  + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz,
-					  section->sh_addralign));
+					  align));
 	}
       else
 	{
-- 
2.14.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]