From: Mark Wielaard Date: Fri, 24 Dec 2021 00:44:57 +0000 (+0100) Subject: libdwfl: Call xlatetom on aligned buffers in dwfl_link_map_report X-Git-Tag: elfutils-0.187~44 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5b490793e2ab651df6bbf87f3a06e2552f48be81;p=platform%2Fupstream%2Felfutils.git libdwfl: Call xlatetom on aligned buffers in dwfl_link_map_report Make sure that when calling xlatetom for Phdrs and Dyns in dwfl_link_map_report the input buffer is correctly aligned by calling memcpy and setting in.d_buf to out.d_buf. https://sourceware.org/bugzilla/show_bug.cgi?id=28720 Signed-off-by: Mark Wielaard --- diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 49a35e4..73d8613 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,5 +1,10 @@ 2021-12-23 Mark Wielaard + * link_map.c (dwfl_link_map_report): Call memcpy and set in.d_buf to + out.d_buf before calling xlatetom for unaligned buffers. + +2021-12-23 Mark Wielaard + * core-file.c (dwfl_elf_phdr_memory_callback): Check start < elf->maximum_size and end - start < minread. diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c index c4f79f1..f57c558 100644 --- a/libdwfl/link_map.c +++ b/libdwfl/link_map.c @@ -922,11 +922,20 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size, return false; } } + bool is32 = (elfclass == ELFCLASS32); + size_t phdr_align = (is32 + ? __alignof__ (Elf32_Phdr) + : __alignof__ (Elf64_Phdr)); + if (!in_from_exec + && ((uintptr_t) in.d_buf & (phdr_align - 1)) != 0) + { + memcpy (out.d_buf, in.d_buf, in.d_size); + in.d_buf = out.d_buf; + } if (likely ((elfclass == ELFCLASS32 ? elf32_xlatetom : elf64_xlatetom) (&out, &in, elfdata) != NULL)) { - bool is32 = (elfclass == ELFCLASS32); for (size_t i = 0; i < phnum; ++i) { GElf_Word type = (is32 @@ -1044,6 +1053,14 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size, }; if (in.d_size > out.d_size) in.d_size = out.d_size; + size_t dyn_align = (elfclass == ELFCLASS32 + ? __alignof__ (Elf32_Dyn) + : __alignof__ (Elf64_Dyn)); + if (((uintptr_t) in.d_buf & (dyn_align - 1)) != 0) + { + memcpy (out.d_buf, in.d_buf, in.d_size); + in.d_buf = out.d_buf; + } if (likely ((elfclass == ELFCLASS32 ? elf32_xlatetom : elf64_xlatetom) (&out, &in, elfdata) != NULL))