]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libebl: Check NT_PLATFORM core notes contain a zero terminated string.
authorMark Wielaard <mark@klomp.org>
Wed, 16 Jan 2019 14:41:31 +0000 (15:41 +0100)
committerMark Wielaard <mark@klomp.org>
Wed, 16 Jan 2019 14:41:31 +0000 (15:41 +0100)
Most strings in core notes are fixed size. But NT_PLATFORM contains just
a variable length string. Check that it is actually zero terminated
before passing to readelf to print.

https://sourceware.org/bugzilla/show_bug.cgi?id=24089

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdwfl/ChangeLog
libdwfl/linux-core-attach.c
libebl/ChangeLog
libebl/eblcorenote.c
libebl/libebl.h
src/ChangeLog
src/readelf.c

index b96cebf21c719cfddbc226dc7732fdeea26f331f..c295fa7d66f864e163414ec9d2ec08d071cf35d0 100644 (file)
@@ -1,3 +1,8 @@
+2019-01-16  Mark Wielaard  <mark@klomp.org>
+
+       * linux-core-attach.c (core_next_thread): Pass desc to ebl_core_note.
+       (core_set_initial_registers): Likewise.
+
 2018-10-23  Mark Wielaard  <mark@klomp.org>
 
        * relocate.c (relocate_section): Only sanity check mmapped Elf files
index 6c99b9e27fccb8232059c4d8b736df6d304c298d..c0f1b0d0047ae95d39c738b7d3e246507144d541 100644 (file)
@@ -137,7 +137,7 @@ core_next_thread (Dwfl *dwfl __attribute__ ((unused)), void *dwfl_arg,
       const Ebl_Register_Location *reglocs;
       size_t nitems;
       const Ebl_Core_Item *items;
-      if (! ebl_core_note (core_arg->ebl, &nhdr, name,
+      if (! ebl_core_note (core_arg->ebl, &nhdr, name, desc,
                           &regs_offset, &nregloc, &reglocs, &nitems, &items))
        {
          /* This note may be just not recognized, skip it.  */
@@ -191,8 +191,9 @@ core_set_initial_registers (Dwfl_Thread *thread, void *thread_arg_voidp)
   const Ebl_Register_Location *reglocs;
   size_t nitems;
   const Ebl_Core_Item *items;
-  int core_note_err = ebl_core_note (core_arg->ebl, &nhdr, name, &regs_offset,
-                                    &nregloc, &reglocs, &nitems, &items);
+  int core_note_err = ebl_core_note (core_arg->ebl, &nhdr, name, desc,
+                                    &regs_offset, &nregloc, &reglocs,
+                                    &nitems, &items);
   /* __libdwfl_attach_state_for_core already verified the note is there.  */
   assert (core_note_err != 0);
   assert (nhdr.n_type == NT_PRSTATUS);
@@ -383,7 +384,7 @@ dwfl_core_file_attach (Dwfl *dwfl, Elf *core)
       const Ebl_Register_Location *reglocs;
       size_t nitems;
       const Ebl_Core_Item *items;
-      if (! ebl_core_note (ebl, &nhdr, name,
+      if (! ebl_core_note (ebl, &nhdr, name, desc,
                           &regs_offset, &nregloc, &reglocs, &nitems, &items))
        {
          /* This note may be just not recognized, skip it.  */
index 77c22746e3092c2ce435d4a88bf7a76edeeef7b3..9cdf8995e108b11df9fe0d4f8c577d0d093c2bd9 100644 (file)
@@ -1,3 +1,9 @@
+2019-01-16  Mark Wielaard  <mark@klomp.org>
+
+       * libebl.h (ebl_core_note): Add desc as argument.
+       * eblcorenote.c (ebl_core_note): Take desc as an argument, check
+       it contains a zero terminated string if it is an NT_PLATFORM note.
+
 2019-01-16  Mark Wielaard  <mark@klomp.org>
 
        * eblobjnte.c (ebl_object_note): Check pr_datasz isn't too large.
index 783f98151eee57f111babd741e8856f3f2724ce7..7fab39747095dc8119797b3702eca850de6a4fad 100644 (file)
 #include <inttypes.h>
 #include <stdio.h>
 #include <stddef.h>
+#include <string.h>
 #include <libeblP.h>
 
 
 int
 ebl_core_note (Ebl *ebl, const GElf_Nhdr *nhdr, const char *name,
+              const char *desc,
               GElf_Word *regs_offset, size_t *nregloc,
               const Ebl_Register_Location **reglocs, size_t *nitems,
               const Ebl_Core_Item **items)
@@ -51,28 +53,25 @@ ebl_core_note (Ebl *ebl, const GElf_Nhdr *nhdr, const char *name,
     {
       /* The machine specific function did not know this type.  */
 
-      *regs_offset = 0;
-      *nregloc = 0;
-      *reglocs = NULL;
-      switch (nhdr->n_type)
+      /* NT_PLATFORM is kind of special since it needs a zero terminated
+         string (other notes often have a fixed size string).  */
+      static const Ebl_Core_Item platform[] =
        {
-#define ITEMS(type, table)                             \
-         case type:                                    \
-           *items = table;                             \
-           *nitems = sizeof table / sizeof table[0];   \
-           result = 1;                                 \
-           break
+         {
+           .name = "Platform",
+           .type = ELF_T_BYTE, .count = 0, .format = 's'
+         }
+       };
 
-         static const Ebl_Core_Item platform[] =
-           {
-             {
-               .name = "Platform",
-               .type = ELF_T_BYTE, .count = 0, .format = 's'
-             }
-           };
-         ITEMS (NT_PLATFORM, platform);
-
-#undef ITEMS
+      if (nhdr->n_type == NT_PLATFORM
+         && memchr (desc, '\0', nhdr->n_descsz) != NULL)
+        {
+         *regs_offset = 0;
+         *nregloc = 0;
+         *reglocs = NULL;
+         *items = platform;
+         *nitems = 1;
+         result = 1;
        }
     }
 
index ca9b9fecb4f11886cc4d8a3b0e3e1f9a575a7f81..24922eb813c563dc816be989406e3be9ec623957 100644 (file)
@@ -319,7 +319,8 @@ typedef struct
 
 /* Describe the format of a core file note with the given header and NAME.
    NAME is not guaranteed terminated, it's NHDR->n_namesz raw bytes.  */
-extern int ebl_core_note (Ebl *ebl, const GElf_Nhdr *nhdr, const char *name,
+extern int ebl_core_note (Ebl *ebl, const GElf_Nhdr *nhdr,
+                         const char *name, const char *desc,
                          GElf_Word *regs_offset, size_t *nregloc,
                          const Ebl_Register_Location **reglocs,
                          size_t *nitems, const Ebl_Core_Item **items)
index 803ac95fbb296c3abc565bcf78aa7a7b3ab3f9dc..c0455f1cfc52dbbe9755ec827be3c0779e583f2e 100644 (file)
@@ -1,3 +1,7 @@
+2019-01-16  Mark Wielaard  <mark@klomp.org>
+
+       * readelf (handle_core_note): Pass desc to ebl_core_note.
+
 2018-11-10  Mark Wielaard  <mark@klomp.org>
 
        * elflint.c (check_program_header): Allow PT_GNU_EH_FRAME segment
index 3a73710ff0b8759b208c6221643256c25a474abb..71651e09175a47de2d63e6f40d48a75f884fe3b9 100644 (file)
@@ -12153,7 +12153,7 @@ handle_core_note (Ebl *ebl, const GElf_Nhdr *nhdr,
   size_t nitems;
   const Ebl_Core_Item *items;
 
-  if (! ebl_core_note (ebl, nhdr, name,
+  if (! ebl_core_note (ebl, nhdr, name, desc,
                       &regs_offset, &nregloc, &reglocs, &nitems, &items))
     return;