From: Mark Wielaard Date: Sun, 31 May 2015 18:49:23 +0000 (+0200) Subject: libdwfl: Don't assume auxv or r_debug data is properly aligned in link_map. X-Git-Tag: elfutils-0.162~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=616489da5005c63fe572df422f1936529c4743f5;p=thirdparty%2Felfutils.git libdwfl: Don't assume auxv or r_debug data is properly aligned in link_map. core file data isn't guaranteed to be alligned properly. Use read_(4|8)ubyte_unaligned_noncvt to read values, types and addresses. Signed-off-by: Mark Wielaard --- diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index ffb34c034..f4e7484b5 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,10 @@ +2015-05-30 Mark Wielaard + + * link_map.c (check32): Use read_4ubyte_unaligned_noncvt to read + type and value. + (read_addrs): Use read_(4|8)ubyte_unaligned_noncvt or to read + adresses. + 2015-05-30 Mark Wielaard * find-debuginfo.c (dwfl_standard_find_debuginfo): Check file_name is diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c index a5a696872..030c6002a 100644 --- a/libdwfl/link_map.c +++ b/libdwfl/link_map.c @@ -58,8 +58,7 @@ auxv_format_probe (const void *auxv, size_t size, inline bool check64 (size_t i) { /* The AUXV pointer might not even be naturally aligned for 64-bit - data, because note payloads in a core file are not aligned. - But we assume the data is 32-bit aligned. */ + data, because note payloads in a core file are not aligned. */ uint64_t type = read_8ubyte_unaligned_noncvt (&u->a64[i].a_type); uint64_t val = read_8ubyte_unaligned_noncvt (&u->a64[i].a_un.a_val); @@ -83,15 +82,21 @@ auxv_format_probe (const void *auxv, size_t size, inline bool check32 (size_t i) { - if (u->a32[i].a_type == BE32 (PROBE_TYPE) - && u->a32[i].a_un.a_val == BE32 (PROBE_VAL32)) + /* The AUXV pointer might not even be naturally aligned for 32-bit + data, because note payloads in a core file are not aligned. */ + + uint32_t type = read_4ubyte_unaligned_noncvt (&u->a32[i].a_type); + uint32_t val = read_4ubyte_unaligned_noncvt (&u->a32[i].a_un.a_val); + + if (type == BE32 (PROBE_TYPE) + && val == BE32 (PROBE_VAL32)) { *elfdata = ELFDATA2MSB; return true; } - if (u->a32[i].a_type == LE32 (PROBE_TYPE) - && u->a32[i].a_un.a_val == LE32 (PROBE_VAL32)) + if (type == LE32 (PROBE_TYPE) + && val == LE32 (PROBE_VAL32)) { *elfdata = ELFDATA2LSB; return true; @@ -285,19 +290,19 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata, { if (elfdata == ELFDATA2MSB) for (size_t i = 0; i < n; ++i) - addrs[i] = BE32 (in->a32[i]); + addrs[i] = BE32 (read_4ubyte_unaligned_noncvt (&in->a32[i])); else for (size_t i = 0; i < n; ++i) - addrs[i] = LE32 (in->a32[i]); + addrs[i] = LE32 (read_4ubyte_unaligned_noncvt (&in->a32[i])); } else { if (elfdata == ELFDATA2MSB) for (size_t i = 0; i < n; ++i) - addrs[i] = BE64 (in->a64[i]); + addrs[i] = BE64 (read_8ubyte_unaligned_noncvt (&in->a64[i])); else for (size_t i = 0; i < n; ++i) - addrs[i] = LE64 (in->a64[i]); + addrs[i] = LE64 (read_8ubyte_unaligned_noncvt (&in->a64[i])); } return false;