[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.
This commit is contained in:
Dmitrii Kuvaiskii
2019-07-19 01:03:41 -07:00
parent b0619cb7a6
commit f556a0676d
+4 -26
View File
@@ -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";