fix a endian-ness bug
cover fix a endian-ness bug
.../endian-ness_handling_fix.patch | 47 ++++++++++++++++++++++
meta/recipes-core/glibc/ldconfig-native_2.12.1.bb | 1 + 2 files changed, 48 insertions(+)
Thanks
Shan Hai
PATCH 1/1 ldconfig-native: fix a endian-ness bug
Some header fields of ELF were read with wrong size on 64bit big-endian machine, fix it by reading the fields with read64 instead of read32.
--- .../endian-ness_handling_fix.patch | 47 ++++++++++++++++++++++ meta/recipes-core/glibc/ldconfig-native_2.12.1.bb | 1 + 2 files changed, 48 insertions(+) create mode 100644 meta/recipes-core/glibc/ldconfig-native-2.12.1/endian-ness_handling_fix.patch
meta/recipes-core/glibc/ldconfig-native-2.12.1/endian-ness_handling_fix.patch new file +47 -0
@@ -0,0 +1,47 @@ +Upstream-Status: Inappropriate [embedded specific] + +Fix problem during parsing of ELF headers for 64bit on big-endian. +Some header fields were read with wrong size. + +2014/10/24 +Par Olsson <[email protected]> +Shan Hai <[email protected]> + +diff --git a/readelflib.c b/readelflib.c +index 3f5b25b..0bf0de3 100644 +--- a/readelflib.c ++++ b/readelflib.c +@@ -261,8 +261,8 @@ process_elf_file64 (const char *file_name, const char *lib, int *flag, + int i; + unsigned int j; + Elf64_Addr loadaddr; +- unsigned int dynamic_addr; +- size_t dynamic_size; ++ Elf64_Addr dynamic_addr; ++ Elf64_Xword dynamic_size; + char *program_interpreter; + + Elf64_Ehdr *elf_header; +@@ -311,7 +311,7 @@ process_elf_file64 (const char *file_name, const char *lib, int *flag, + error (0, 0, _("more than one dynamic segment\n")); + + dynamic_addr = read64(segment->p_offset, be); +- dynamic_size = read32(segment->p_filesz, be); ++ dynamic_size = read64(segment->p_filesz, be); + break; + + case PT_INTERP: +@@ -329,11 +329,11 @@ process_elf_file64 (const char *file_name, const char *lib, int *flag, + break; + + case PT_NOTE: +- if (!*osversion && read32(segment->p_filesz, be) >= 32 && read32(segment->p_align, be) >= 4) ++ if (!*osversion && read64(segment->p_filesz, be) >= 32 && read64(segment->p_align, be) >= 4) + { + Elf64_Word *abi_note = (Elf64_Word *) (file_contents + + read64(segment->p_offset, be)); +- Elf64_Addr size = read32(segment->p_filesz, be); ++ Elf64_Xword size = read64(segment->p_filesz, be); + + while (read32(abi_note [0], be) != 4 || read32(abi_note [1], be) != 16 + || read32(abi_note [2], be) != 1
meta/recipes-core/glibc/ldconfig-native_2.12.1.bb +1 -0
@@ -12,6 +12,7 @@ SRC_URI = "file://ldconfig-native-2.12.1.tar.bz2 \ file://flag_fix.patch \ file://endianess-header.patch \ file://ldconfig-default-to-all-multilib-dirs.patch \ + file://endian-ness_handling_fix.patch \ " PR = "r2"
Signature · 1 line
1.8.5.2.233.g932f7e4
Re: [PATCH 1/1] ldconfig-native: fix a endian-ness bug
Quoted 4 lines · Shan Hai
Some header fields of ELF were read with wrong size on 64bit big-endian machine, fix it by reading the fields with read64 instead of read32.
For fixes like this which set of all sorts of alarm bells, please include more justification.
From a quick look at the code my interpretation is that the values in the segment structure are 64-bit but they were being read using 32-bit accessors (read32). On a little-endian 64-bit machine (x86-64, aarch64) when the values fit into a 32-bit value the right half was read and it still worked. Then someone tried a 64-bit big-endian build host (I'm guessing is a ppc64 or mips64), and the values read are either 0 (if the size fits in a 32-bit type) or corrupted (if larger).
Am I right? Either way, the commit log needs to be clear - the message should *why* it does something, not *what* it does.
Finally, do we really need to patch a fork? We've got the full source alongside the recipe, let's just fix it.
This also brings up the point that we really need to do something about ldconfig-native. CC'ing Khem, would anyone be able to liaise with upstream and either update our fork or see if upstream would care about our need for ldconfig-native?
Ross
Re: [PATCH 1/1] ldconfig-native: fix a endian-ness bug
Quoted 18 lines · Ross
Quoted 4 lines · Shan Hai
Some header fields of ELF were read with wrong size on 64bit big-endian machine, fix it by reading the fields with read64 instead of read32.
For fixes like this which set of all sorts of alarm bells, please include more justification.
From a quick look at the code my interpretation is that the values in the segment structure are 64-bit but they were being read using 32-bit accessors (read32). On a little-endian 64-bit machine (x86-64, aarch64) when the values fit into a 32-bit value the right half was read and it still worked. Then someone tried a 64-bit big-endian build host (I'm guessing is a ppc64 or mips64), and the values read are either 0 (if the size fits in a 32-bit type) or corrupted (if larger).
Quoted 3 lines
Am I right? Either way, the commit log needs to be clear - the message should *why* it does something, not *what* it does.
you are right. but I wonder if this patch is OK since section alignments change based on 32bit ABI or 64bit ABI
Quoted 7 lines
Finally, do we really need to patch a fork? We've got the full source alongside the recipe, let's just fix it.
This also brings up the point that we really need to do something about ldconfig-native. CC'ing Khem, would anyone be able to liaise with upstream and either update our fork or see if upstream would care about our need for ldconfig-native?
I think its fine idea, I haven't paid enough attention to it so assert if its right
for upstreaming in current shape but for 2.21 I should
Quoted 2 lines
Ross