]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ignore invalid DOF provider sections
authorJoel Brobecker <brobecker@adacore.com>
Thu, 6 Aug 2015 20:13:32 +0000 (22:13 +0200)
committerJoel Brobecker <brobecker@adacore.com>
Fri, 7 Aug 2015 15:17:52 +0000 (08:17 -0700)
On x86-solaris 10, we noticed that starting a program would sometimes
cause the debugger to crash. For instance:

    % gdb a
    (gdb) break adainit
    Breakpoint 1 at 0x8051f03
    (gdb) run
    Starting program: /[...]/a
    [Thread debugging using libthread_db enabled]
    zsh: 24398 segmentation fault (core dumped)  /[...]/gdb a

The exception occurs in dtrace_process_dof_probe, while trying
to process each probe referenced by a DTRACE_DOF_SECT_TYPE_PROVIDER
DOF section from /lib/libc.so.1. For reference, the ELF section
in that shared library providing the DOF data has the following
characteristics:

    Idx Name          Size      VMA       LMA       File off  Algn
     14 .SUNW_dof     0000109d  000b4398  000b4398  000b4398  2**3
                      CONTENTS, ALLOC, LOAD, READONLY, DATA

The function dtrace_process_dof gets passed the contents of that
ELF section, which allows it to determine the location of the table
where all DOF sections are described. I dumped the contents of
each DOF section as seen by GDB, and it seemed to be plausible,
because the offset of each DOF section was pretty much equal to
the sum of the offset and size of the previous DOF section. Also,
the offset + sum of the last section corresponds to the size of
the .SUNW_dof section.

Things start to break down when processing one of the DOF sections
that has a type of DTRACE_DOF_SECT_TYPE_PROVIDER. It gets the contents
of this DOF section via:

        struct dtrace_dof_provider *provider = (struct dtrace_dof_provider *)
          DTRACE_DOF_PTR (dof, DOF_UINT (dof, section->dofs_offset));

Said more simply, the struct dtrace_dof_provider data is at
section->dofs_offset of the entire DOF contents. Given that
the contents of SECTION seemed to make sense, so far so good.

However, what SECTION tells us is that our DOF provider section
is 40 bytes long:

    (gdb) print *section
    $36 = {dofs_type = 15, dofs_align = 4, dofs_flags = 1,
           dofs_entsize = 0, dofs_offset = 3264, dofs_size = 40}
                                                 ^^^^^^^^^^^^^^

But on the other hand:

    (gdb) p sizeof (struct dtrace_dof_provider)
    $54 = 44

In other words GDB expected a bigger DOF section and when we try to
fetch the value of the last field of that DOF section (dofpv_prenoffs)...

    eoffsets_s = DTRACE_DOF_SECT (dof,
                                  DOF_UINT (dof, provider->dofpv_prenoffs));

... we end up reading data that actually belongs to another DOF
section, and therefore irrelevant. This in turn means that the value
of eofftab gets incorrectly set, since it depends on eoffsets_s:

    eofftab = DTRACE_DOF_PTR (dof, DOF_UINT (dof, eoffsets_s->dofs_offset));

This invalid address quickly catches up to us when we pass it to
dtrace_process_dof_probe shortly after, where we crash because
we try to subscript it:

    Program received signal SIGSEGV, Segmentation fault.
    0x08155bba in dtrace_process_dof_probe ([...]) at [...]/dtrace-probe.c:378
    378             = ((uint32_t *) eofftab)[...];

This patch fixes the issue by detecting provider DOF sections
that are smaller than expected, and discarding the DOF data.

gdb/ChangeLog:

        * dtrace-probe.c (dtrace_process_dof): Ignore the objfile's DOF
        data if a DTRACE_DOF_SECT_TYPE_PROVIDER section is found to be
        smaller than expected.

gdb/ChangeLog
gdb/dtrace-probe.c

index ce42136bafa0f15e7ceafcb722bc1e75487b0845..67a61d8ca192901b38e8f3cae97a3b0a4fadba27 100644 (file)
@@ -1,3 +1,9 @@
+2015-08-07  Joel Brobecker  <brobecker@adacore.com>
+
+       * dtrace-probe.c (dtrace_process_dof): Ignore the objfile's DOF
+       data if a DTRACE_DOF_SECT_TYPE_PROVIDER section is found to be
+       smaller than expected.
+
 2015-08-07  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * stack.c (get_frame_language): Moved ...
index 3f2548ddc4c2796c2e898ceb80639b94c1ed378f..9816f0792a8ffe45fd3175ec086e344628be2a2a 100644 (file)
@@ -519,6 +519,14 @@ dtrace_process_dof (asection *sect, struct objfile *objfile,
        unsigned int entsize = DOF_UINT (dof, probes_s->dofs_entsize);
        int num_probes;
 
+       if (DOF_UINT (dof, section->dofs_size)
+           < sizeof (struct dtrace_dof_provider))
+         {
+           /* The section is smaller than expected, so do not use it.
+              This has been observed on x86-solaris 10.  */
+           goto invalid_dof_data;
+         }
+
        /* Very, unlikely, but could crash gdb if not handled
           properly.  */
        if (entsize == 0)