public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Omar Sandoval <osandov@osandov.com>
To: elfutils-devel@sourceware.org
Subject: [PATCH 0/4] libdwfl: make dwfl_addrmodule work for Linux kernel modules
Date: Thu, 12 Dec 2019 01:29:00 -0000	[thread overview]
Message-ID: <cover.1576112311.git.osandov@fb.com> (raw)

From: Omar Sandoval <osandov@fb.com>

Hello,

I recently encountered a bug that dwfl_addrmodule doesn't work correctly
for Linux kernel modules. This is because each section of a kernel
module is allocated independently, so sections from different kernel
modules may be intermixed. For example:

# cd /sys/modules
# cat ext4/sections/.init.text
0xffffffffc0f0f000
# cat ext4/sections/.bss
0xffffffffc1303e80
# cat kvm/sections/.init.text
0xffffffffc0f06000
# cat kvm/sections/.bss
0xffffffffc10d2340

This confuses dwfl_addrmodule/dwfl_addrsegment, which builds a lookup
table based on mod->low_addr and mod->high_addr. For relocatable files,
we should be using the addresses of each section, instead.

Patch 4 makes this change, but it needs some preparation. Patch 1 allows
us to distinguish between unloaded sections and sections loaded at zero.
This is necessary so that dwfl_addrmodule doesn't map, e.g., 0x123 to a
module with an unloaded section of size 0x200. Because indexing every
section creates many more lookup entries than we previously had, patch 3
separates the module lookup table from the dwfl_report_segment lookup
table. Finally, patch 2 is the patch I sent yesterday, included in this
series because it would conflict with the later patches.

If these patches are the wrong way to go about this, please consider
this a bug report. I'd be happy to test alternative fixes.

Thanks!

Omar Sandoval (4):
  libdwfl: return error from __libdwfl_relocate_value for unloaded
    sections
  libdwfl: remove broken coalescing logic in dwfl_report_segment
  libdwfl: store module lookup table separately from segments
  libdwfl: use sections of relocatable files for dwfl_addrmodule

 .gitignore                             |   1 +
 libdwfl/ChangeLog                      |  30 +++++
 libdwfl/derelocate.c                   |  24 +---
 libdwfl/dwfl_addrmodule.c              | 106 ++++++++++++++-
 libdwfl/dwfl_getmodules.c              |  14 +-
 libdwfl/dwfl_module.c                  |  11 +-
 libdwfl/dwfl_module_getsym.c           |   3 +-
 libdwfl/libdwfl.h                      |  20 +--
 libdwfl/libdwflP.h                     |  42 ++++--
 libdwfl/link_map.c                     |   7 +-
 libdwfl/relocate.c                     |   9 +-
 libdwfl/segment.c                      | 178 +++----------------------
 tests/ChangeLog                        |   5 +
 tests/Makefile.am                      |   6 +-
 tests/dwfl-report-segment-contiguous.c |  82 ++++++++++++
 15 files changed, 305 insertions(+), 233 deletions(-)
 create mode 100644 tests/dwfl-report-segment-contiguous.c

-- 
2.24.0

             reply	other threads:[~2019-12-12  1:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-12  1:29 Omar Sandoval [this message]
2019-12-12  1:30 ` [PATCH 3/4] libdwfl: store module lookup table separately from segments Omar Sandoval
2019-12-12  1:30 ` [PATCH 1/4] libdwfl: return error from __libdwfl_relocate_value for unloaded sections Omar Sandoval
2019-12-12  1:30 ` [PATCH 4/4] libdwfl: use sections of relocatable files for dwfl_addrmodule Omar Sandoval
2019-12-12  1:30 ` [PATCH 2/4] libdwfl: remove broken coalescing logic in dwfl_report_segment Omar Sandoval
2019-12-13  5:03 ` [PATCH 0/4] libdwfl: make dwfl_addrmodule work for Linux kernel modules Omar Sandoval
2019-12-18 20:28   ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1576112311.git.osandov@fb.com \
    --to=osandov@osandov.com \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).