From: Mark Wielaard Date: Sun, 19 Dec 2021 23:31:33 +0000 (+0100) Subject: libdwfl: Handle unaligned Phdr in dwfl_segment_report_module X-Git-Tag: elfutils-0.187~48 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c1c8bbe8a04697203e18f92c09827defdcf7d204;p=platform%2Fupstream%2Felfutils.git libdwfl: Handle unaligned Phdr in dwfl_segment_report_module 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). Signed-off-by: Mark Wielaard --- diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 6c7e0c4..ac0fbe0 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,6 +1,12 @@ 2021-12-19 Mark Wielaard * dwfl_segment_report_module.c (dwfl_segment_report_module): Copy + ph_buffer and set xlatefrom.d_buf to phdrsp when ph_buffer is not + aligned. + +2021-12-19 Mark Wielaard + + * dwfl_segment_report_module.c (dwfl_segment_report_module): Copy buffer and set xlatefrom.d_buf to ehdr when buffer is not aligned. 2021-12-19 Mark Wielaard diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c index 7f75639..de190e9 100644 --- a/libdwfl/dwfl_segment_report_module.c +++ b/libdwfl/dwfl_segment_report_module.c @@ -461,6 +461,18 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name, xlateto.d_buf = phdrsp; xlateto.d_size = phdrsp_bytes; + /* ph_ buffer 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). */ + size_t phdr_align = (class32 + ? __alignof__ (Elf32_Phdr) + : __alignof__ (Elf64_Phdr)); + if (((uintptr_t) ph_buffer & (phdr_align - 1)) != 0) + { + memcpy (phdrsp, ph_buffer, phdrsp_bytes); + xlatefrom.d_buf = phdrsp; + } + /* Track the bounds of the file visible in memory. */ GElf_Off file_trimmed_end = 0; /* Proper p_vaddr + p_filesz end. */ GElf_Off file_end = 0; /* Rounded up to effective page size. */