]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libelf: Add n_namesz offset overflow check to gelf_get_note.
authorMark Wielaard <mark@klomp.org>
Wed, 1 May 2019 13:52:24 +0000 (15:52 +0200)
committerMark Wielaard <mark@klomp.org>
Sat, 4 May 2019 19:31:08 +0000 (21:31 +0200)
During fuzzing of the new xlate_notes testcase I noticed that
gelf_get_note didn't check whether the n_namesz of a note was
too big. This could lead to offset wrapping around. Causing an
infinite loop going over all ELF notes. Fix by adding an overflow
check before updating offset.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libelf/ChangeLog
libelf/gelf_getnote.c

index 5eadaf76bbed9b9d7b6c409e204f17a0ba7a7c43..924ff5917a5058de6eb6445199e6e2e395dc5b7d 100644 (file)
@@ -1,3 +1,8 @@
+2019-05-01  Mark Wielaard  <mark@klomp.org>
+
+       * gelf_getnote.c (gelf_getnote): Check n_namesz doesn't overflow
+       offset.
+
 2019-04-30  Mark Wielaard  <mark@klomp.org>
 
        * note_xlate.h (elf_cvt_note): Indicate we only translated the note
index 6d33b3558b746fc499d9d20a0c1ba5b48bf4ccae..0f7b9d682b31c62a48be989dc7daf62adf812b8c 100644 (file)
@@ -80,11 +80,12 @@ gelf_getnote (Elf_Data *data, size_t offset, GElf_Nhdr *result,
             the offset, after adding the namesz, and include padding
             in descsz to get to the end.  */
          *name_offset = offset;
-         offset += n->n_namesz;
-         if (offset > data->d_size)
+         if (n->n_namesz > data->d_size
+             || offset > data->d_size - n->n_namesz)
            offset = 0;
          else
            {
+             offset += n->n_namesz;
              /* Include padding.  Check below for overflow.  */
              GElf_Word descsz = (data->d_type == ELF_T_NHDR8
                                  ? NOTE_ALIGN8 (n->n_descsz)