summaryrefslogtreecommitdiffstats
path: root/libdwfl
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2021-12-24 01:44:57 +0100
committerMark Wielaard <mark@klomp.org>2022-01-04 00:36:52 +0100
commit5b490793e2ab651df6bbf87f3a06e2552f48be81 (patch)
tree9d8d8d3fe4d3e3674114758bb6800330a34461e7 /libdwfl
parentlibdwfl: Make sure dwfl_elf_phdr_memory_callback returns at least minread (diff)
downloadelfutils-5b490793e2ab651df6bbf87f3a06e2552f48be81.tar.gz
elfutils-5b490793e2ab651df6bbf87f3a06e2552f48be81.tar.bz2
elfutils-5b490793e2ab651df6bbf87f3a06e2552f48be81.tar.xz
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 <mark@klomp.org>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog5
-rw-r--r--libdwfl/link_map.c19
2 files changed, 23 insertions, 1 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 49a35e41..73d8613c 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,5 +1,10 @@
12021-12-23 Mark Wielaard <mark@klomp.org> 12021-12-23 Mark Wielaard <mark@klomp.org>
2 2
3 * link_map.c (dwfl_link_map_report): Call memcpy and set in.d_buf to
4 out.d_buf before calling xlatetom for unaligned buffers.
5
62021-12-23 Mark Wielaard <mark@klomp.org>
7
3 * core-file.c (dwfl_elf_phdr_memory_callback): Check start < 8 * core-file.c (dwfl_elf_phdr_memory_callback): Check start <
4 elf->maximum_size and end - start < minread. 9 elf->maximum_size and end - start < minread.
5 10
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index c4f79f11..f57c5585 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,
922 return false; 922 return false;
923 } 923 }
924 } 924 }
925 bool is32 = (elfclass == ELFCLASS32);
926 size_t phdr_align = (is32
927 ? __alignof__ (Elf32_Phdr)
928 : __alignof__ (Elf64_Phdr));
929 if (!in_from_exec
930 && ((uintptr_t) in.d_buf & (phdr_align - 1)) != 0)
931 {
932 memcpy (out.d_buf, in.d_buf, in.d_size);
933 in.d_buf = out.d_buf;
934 }
925 if (likely ((elfclass == ELFCLASS32 935 if (likely ((elfclass == ELFCLASS32
926 ? elf32_xlatetom : elf64_xlatetom) 936 ? elf32_xlatetom : elf64_xlatetom)
927 (&out, &in, elfdata) != NULL)) 937 (&out, &in, elfdata) != NULL))
928 { 938 {
929 bool is32 = (elfclass == ELFCLASS32);
930 for (size_t i = 0; i < phnum; ++i) 939 for (size_t i = 0; i < phnum; ++i)
931 { 940 {
932 GElf_Word type = (is32 941 GElf_Word type = (is32
@@ -1044,6 +1053,14 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
1044 }; 1053 };
1045 if (in.d_size > out.d_size) 1054 if (in.d_size > out.d_size)
1046 in.d_size = out.d_size; 1055 in.d_size = out.d_size;
1056 size_t dyn_align = (elfclass == ELFCLASS32
1057 ? __alignof__ (Elf32_Dyn)
1058 : __alignof__ (Elf64_Dyn));
1059 if (((uintptr_t) in.d_buf & (dyn_align - 1)) != 0)
1060 {
1061 memcpy (out.d_buf, in.d_buf, in.d_size);
1062 in.d_buf = out.d_buf;
1063 }
1047 if (likely ((elfclass == ELFCLASS32 1064 if (likely ((elfclass == ELFCLASS32
1048 ? elf32_xlatetom : elf64_xlatetom) 1065 ? elf32_xlatetom : elf64_xlatetom)
1049 (&out, &in, elfdata) != NULL)) 1066 (&out, &in, elfdata) != NULL))