From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] libdwfl: Handle unaligned Dyns in dwfl_segment_report_module
Date: Thu, 6 Jan 2022 17:37:17 +0100 [thread overview]
Message-ID: <20220106163717.116122-1-mark@klomp.org> (raw)
The xlate functions only handle correctly aligned buffers. But they do
handle src == dest. So if the source buffer isn't aligned correctly
just copy it first into the destination (which is already correctly
aligned).
https://sourceware.org/bugzilla/show_bug.cgi?id=28720
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
libdwfl/ChangeLog | 5 +++++
libdwfl/dwfl_segment_report_module.c | 12 ++++++++++++
2 files changed, 17 insertions(+)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index f8319f44..aace969f 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,8 @@
+2022-01-03 Mark Wielaard <mark@klomp.org>
+
+ * dwfl_segment_report_module.c (dwfl_segment_report_module): Copy
+ dyn_data and set xlatefrom.d_buf to dyns when dyns is not aligned.
+
2022-01-03 Mark Wielaard <mark@klomp.org>
* link_map.c (read_addrs): Fix buffer_available nb overflow.
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 5bef249e..1461ae26 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -844,7 +844,19 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
xlateto.d_buf = dyns;
xlateto.d_size = dyn_filesz;
+ /* dyn_data may be unaligned, in which case xlatetom would not work.
+ xlatetom does work when the in and out d_buf are equal (but not
+ for any other overlap). */
bool is32 = (ei_class == ELFCLASS32);
+ size_t dyn_align = (is32
+ ? __alignof__ (Elf32_Dyn)
+ : __alignof__ (Elf64_Dyn));
+ if (((uintptr_t) dyn_data & (dyn_align - 1)) != 0)
+ {
+ memcpy (dyns, dyn_data, dyn_filesz);
+ xlatefrom.d_buf = dyns;
+ }
+
if ((is32 && elf32_xlatetom (&xlateto, &xlatefrom, ei_data) != NULL)
|| (!is32 && elf64_xlatetom (&xlateto, &xlatefrom, ei_data) != NULL))
{
--
2.30.2
reply other threads:[~2022-01-06 16:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220106163717.116122-1-mark@klomp.org \
--to=mark@klomp.org \
--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).