Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[elf] Avoid attempting to load 64-bit ELF binaries
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Apr 9, 2012
1 parent 275fdae commit 61851e6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/image/elf.c
Expand Up @@ -38,6 +38,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
typedef Elf32_Ehdr Elf_Ehdr;
typedef Elf32_Phdr Elf_Phdr;
typedef Elf32_Off Elf_Off;
#define ELFCLASS ELFCLASS32

/**
* Load ELF segment into memory
Expand Down Expand Up @@ -121,6 +122,13 @@ static int elf_load_segment ( struct image *image, Elf_Phdr *phdr,
* @ret rc Return status code
*/
int elf_load ( struct image *image, physaddr_t *entry ) {
static const uint8_t e_ident[] = {
[EI_MAG0] = ELFMAG0,
[EI_MAG1] = ELFMAG1,
[EI_MAG2] = ELFMAG2,
[EI_MAG3] = ELFMAG3,
[EI_CLASS] = ELFCLASS,
};
Elf_Ehdr ehdr;
Elf_Phdr phdr;
Elf_Off phoff;
Expand All @@ -129,7 +137,8 @@ int elf_load ( struct image *image, physaddr_t *entry ) {

/* Read ELF header */
copy_from_user ( &ehdr, image->data, 0, sizeof ( ehdr ) );
if ( memcmp ( &ehdr.e_ident[EI_MAG0], ELFMAG, SELFMAG ) != 0 ) {
if ( memcmp ( &ehdr.e_ident[EI_MAG0], e_ident,
sizeof ( e_ident ) ) != 0 ) {
DBGC ( image, "ELF %p has invalid signature\n", image );
return -ENOEXEC;
}
Expand Down

0 comments on commit 61851e6

Please sign in to comment.