kernel/fs/exec.c
/*
 * CheckELFHeaders();
 *
 * Check that it is a genuine ELF executable.
 */
CheckELFHeaders();
Check that it is a genuine ELF executable.
CheckELFHeaders () ; Check that it is a genuine ELF executable .
static int CheckELFHeaders(struct ExecInfo *ei) {
  Elf32_EHdr ehdr;
  int rc;
  Info ("CheckELFHeaders");
  rc = ReadFile(ei, TRUE, 0, &ehdr, sizeof(Elf32_EHdr));
  if (rc == sizeof(Elf32_EHdr)) {
    if (ehdr.e_ident[EI_MAG0] == ELFMAG0 && ehdr.e_ident[EI_MAG1] == 'E' &&
        ehdr.e_ident[EI_MAG2] == 'L' && ehdr.e_ident[EI_MAG3] == 'F' &&
        ehdr.e_ident[EI_CLASS] == ELFCLASS32 &&
        ehdr.e_ident[EI_DATA] == ELFDATA2LSB && ehdr.e_type == ET_EXEC &&
        ehdr.e_phnum > 0) {
      return 0;
    } else {
      if (ehdr.e_ident[EI_MAG0] != ELFMAG0 || ehdr.e_ident[EI_MAG1] != 'E' ||
        ehdr.e_ident[EI_MAG2] != 'L' || ehdr.e_ident[EI_MAG3] != 'F') {
        Info("no ELF magic marker");
      }
      if (ehdr.e_ident[EI_CLASS] != ELFCLASS32) {
        Info ("Not ELF32 class");
      }
      if (ehdr.e_ident[EI_DATA] != ELFDATA2LSB) {
        Info ("Not ELF LSB");
      }
      if (ehdr.e_type != ET_EXEC) {
        Info ("Not ELF ET_EXEC");
      }
      if (ehdr.e_phnum == 0) {
        Info ("No ELF program headers");
      }
    }    
  } else {
    Info("CheckElfHeaders - kread failed %d", rc);
  }
  Info("FILE IS NOT EXECUTABLE");
  return -ENOEXEC;
}
static int CheckELFHeaders ( struct ExecInfo * ei ) { Elf32_EHdr ehdr ; int rc ; Info ( " " ) ; rc = ReadFile ( ei , TRUE , 0 , & ehdr , sizeof ( Elf32_EHdr ) ) ; if ( rc == sizeof ( Elf32_EHdr ) ) { if ( ehdr . e_ident [ EI_MAG0 ] == ELFMAG0 && ehdr . e_ident [ EI_MAG1 ] == ' ' && ehdr . e_ident [ EI_MAG2 ] == ' ' && ehdr . e_ident [ EI_MAG3 ] == ' ' && ehdr . e_ident [ EI_CLASS ] == ELFCLASS32 && ehdr . e_ident [ EI_DATA ] == ELFDATA2LSB && ehdr . e_type == ET_EXEC && ehdr . e_phnum > 0 ) { return 0 ; } else { if ( ehdr . e_ident [ EI_MAG0 ] != ELFMAG0 || ehdr . e_ident [ EI_MAG1 ] != ' ' || ehdr . e_ident [ EI_MAG2 ] != ' ' || ehdr . e_ident [ EI_MAG3 ] != ' ' ) { Info ( " " ) ; } if ( ehdr . e_ident [ EI_CLASS ] != ELFCLASS32 ) { Info ( " " ) ; } if ( ehdr . e_ident [ EI_DATA ] != ELFDATA2LSB ) { Info ( " " ) ; } if ( ehdr . e_type != ET_EXEC ) { Info ( " " ) ; } if ( ehdr . e_phnum == 0 ) { Info ( " " ) ; } } } else { Info ( " " , rc ) ; } Info ( " " ) ; return - ENOEXEC ; }
CheckELFHeaders();
 Check that it is a genuine ELF executable.
CheckELFHeaders () ; Check that it is a genuine ELF executable .
//      Info("CheckElfHeaders - Is ELF");