Bug 239516

Summary: readelf -wf segfaults on most (all?) debug info files
Product: Base System Reporter: Mark Johnston <markj>
Component: binAssignee: Mark Johnston <markj>
Status: Closed FIXED    
Severity: Affects Only Me CC: emaste, me
Priority: --- Keywords: patch
Version: CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
Proposed patch
none
Robustness patch none

Description Mark Johnston freebsd_committer freebsd_triage 2019-07-29 19:25:15 UTC
> readelf -wf /usr/lib/debug/bin/cat.debug 

The section .eh_frame contains:

Segmentation fault (core dumped)
>
Comment 1 Paco Pascal 2019-08-24 07:39:16 UTC
Created attachment 206840 [details]
Proposed patch
Comment 2 Paco Pascal 2019-08-24 23:14:54 UTC
Created attachment 206867 [details]
Robustness patch

Adding logic similar to the "robustness patch" I provided may be worthwhile. If another programmer using libdwarf makes a similar mistake, having it fail gracefully may be preferable over a segfault. For example, running readelf without the "proposed patch" would yield:


$ readelf -wf /usr/lib/debug/bin/cat.debug

The section .eh_frame contains:

Assertion failed: (ds->ds_data != NULL), function _dwarf_frame_section_init, file /usr/src/contrib/elftoolchain/libdwarf/libdwarf_frame.c, line 465.
Abort trap
$
Comment 3 Mark Johnston freebsd_committer freebsd_triage 2020-07-11 18:51:12 UTC
(In reply to Paco Pascal from comment #2)
My apologies for not following up sooner!  I think you indeed found the root cause, thanks.  Thinking about this some more, I suspect that libdwarf should be handling this case itself, rather than forcing it into consumers.

I looked at SGI libdwarf, and it appears to handle this: dwarf_elf_object_access_load_section() looks for a NULL d_buf in the data descriptor of the target ELF section, which indicates that the section is SHT_NOBITS.  I proposed a patch here: https://reviews.freebsd.org/D25626
Comment 4 Paco Pascal 2020-07-16 04:17:52 UTC
(In reply to Mark Johnston from comment #3)
You're welcome and thanks for the reference on the review!

I agree. Not pushing this responsibility onto consumers is the better way to go.
Comment 5 commit-hook freebsd_committer freebsd_triage 2020-07-20 18:23:13 UTC
A commit references this bug:

Author: markj
Date: Mon Jul 20 18:22:38 UTC 2020
New revision: 363375
URL: https://svnweb.freebsd.org/changeset/base/363375

Log:
  libdwarf: Hide SHT_NOBITS sections.

  gnu_debuglink external debug files will contain an .eh_frame section of
  type SHT_NOBITS.  libdwarf does not handle such sections (or rather, it
  expects all debug sections to not have type SHT_NOBITS).  Avoid loading
  SHT_NOBITS sections, to be consistent with SGI libdwarf's handling of
  this case.

  PR:		239516
  Diagnosed by:	Paco Pascal <me@pacopascal.com>
  Reviewed by:	emaste (previous version)
  Event:		July 2020 Bugathon
  MFC after:	1 week
  Differential Revision:	https://reviews.freebsd.org/D25626

Changes:
  head/contrib/elftoolchain/libdwarf/libdwarf_elf_init.c
Comment 6 commit-hook freebsd_committer freebsd_triage 2020-07-27 14:09:24 UTC
A commit references this bug:

Author: markj
Date: Mon Jul 27 14:08:30 UTC 2020
New revision: 363600
URL: https://svnweb.freebsd.org/changeset/base/363600

Log:
  MFC r363375:
  libdwarf: Hide SHT_NOBITS sections.

  PR:	239516

Changes:
_U  stable/12/
  stable/12/contrib/elftoolchain/libdwarf/libdwarf_elf_init.c
Comment 7 commit-hook freebsd_committer freebsd_triage 2020-07-27 14:10:26 UTC
A commit references this bug:

Author: markj
Date: Mon Jul 27 14:09:38 UTC 2020
New revision: 363601
URL: https://svnweb.freebsd.org/changeset/base/363601

Log:
  MFC r363375:
  libdwarf: Hide SHT_NOBITS sections.

  PR:	239516

Changes:
_U  stable/11/
  stable/11/contrib/elftoolchain/libdwarf/libdwarf_elf_init.c