Browse Source

[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.
Dmitrii Kuvaiskii 6 years ago
parent
commit
f556a0676d
1 changed files with 4 additions and 26 deletions
  1. 4 26
      LibOS/shim/src/elf/shim_rtld.c

+ 4 - 26
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";