public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/4] libdwfl: make dwfl_addrmodule work for Linux kernel modules
@ 2019-12-12  1:29 Omar Sandoval
  2019-12-12  1:30 ` [PATCH 2/4] libdwfl: remove broken coalescing logic in dwfl_report_segment Omar Sandoval
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Omar Sandoval @ 2019-12-12  1:29 UTC (permalink / raw)
  To: elfutils-devel

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-12-18 20:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-12  1:29 [PATCH 0/4] libdwfl: make dwfl_addrmodule work for Linux kernel modules Omar Sandoval
2019-12-12  1:30 ` [PATCH 2/4] libdwfl: remove broken coalescing logic in dwfl_report_segment Omar Sandoval
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-13  5:03 ` [PATCH 0/4] libdwfl: make dwfl_addrmodule work for Linux kernel modules Omar Sandoval
2019-12-18 20:28   ` Mark Wielaard

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).