From f556a0676d99afb0aebc8fe8d575158d539d123d Mon Sep 17 00:00:00 2001 From: Dmitrii Kuvaiskii Date: Fri, 12 Jul 2019 15:46:16 -0700 Subject: [PATCH] [LibOS] Allow dyn loading of ELF binaries with OS ABI == ELFOSABI_LINUX Sometimes apps are built with the ELF header containing OS ABI == ELFOSABI_LINUX (GCC is one example). Previously, LibOS dynamic loader only allowed OS ABI == ELFOSABI_SYSV (most apps are built with it) and failed on ELFOSABI_LINUX. This commit teaches LibOS loader to accept ELFOSABI_LINUX binaries and removes some redundant checks on ELF header. New implementation is now in line with dynamic loader of PAL. --- LibOS/shim/src/elf/shim_rtld.c | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/LibOS/shim/src/elf/shim_rtld.c b/LibOS/shim/src/elf/shim_rtld.c index 2fd3af7f..18e7e93b 100644 --- a/LibOS/shim/src/elf/shim_rtld.c +++ b/LibOS/shim/src/elf/shim_rtld.c @@ -875,45 +875,23 @@ static int __check_elf_header (void * fbp, size_t len) [EI_CLASS] = ELFW(CLASS), [EI_DATA] = byteorder, [EI_VERSION] = EV_CURRENT, - [EI_OSABI] = ELFOSABI_SYSV, - [EI_ABIVERSION] = 0 + [EI_OSABI] = 0, }; /* See whether the ELF header is what we expect. */ - if (__builtin_expect (memcmp (ehdr->e_ident, expected, EI_ABIVERSION) != - 0, 0)) { + if (__builtin_expect(memcmp(ehdr->e_ident, expected, EI_OSABI) != 0 || + (ehdr->e_ident[EI_OSABI] != ELFOSABI_SYSV && + ehdr->e_ident[EI_OSABI] != ELFOSABI_LINUX), 0)) { errstring = "ELF file with invalid header"; goto verify_failed; } - /* Check whether the ELF header use the right endian */ - if (ehdr->e_ident[EI_DATA] != byteorder) { - if (__BYTE_ORDER == __BIG_ENDIAN) { - errstring = "ELF file data encoding not big-endian"; - goto verify_failed; - } else { - errstring = "ELF file data encoding not little-endian"; - goto verify_failed; - } - } - - /* checking the header is of the right version */ - if (ehdr->e_ident[EI_VERSION] != EV_CURRENT) { - errstring = "ELF file version ident does not match current one"; - goto verify_failed; - } - if (memcmp(&ehdr->e_ident[EI_PAD], &expected[EI_PAD], EI_NIDENT - EI_PAD) != 0) { errstring = "nonzero padding in e_ident"; goto verify_failed; } - if (__builtin_expect (ehdr->e_version, EV_CURRENT) != EV_CURRENT) { - errstring = "ELF file version does not match current one"; - goto verify_failed; - } - /* Now we check if the host match the elf machine profile */ if (! __builtin_expect (elf_machine_matches_host (ehdr), 1)) { errstring = "ELF file does not match with the host";