mirror of https://github.com/ipxe/ipxe.git
[elf] Avoid attempting to load 64-bit ELF binaries
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/6/head
parent
275fdae9bb
commit
61851e685d
|
@ -38,6 +38,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
typedef Elf32_Ehdr Elf_Ehdr;
|
typedef Elf32_Ehdr Elf_Ehdr;
|
||||||
typedef Elf32_Phdr Elf_Phdr;
|
typedef Elf32_Phdr Elf_Phdr;
|
||||||
typedef Elf32_Off Elf_Off;
|
typedef Elf32_Off Elf_Off;
|
||||||
|
#define ELFCLASS ELFCLASS32
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load ELF segment into memory
|
* Load ELF segment into memory
|
||||||
|
@ -121,6 +122,13 @@ static int elf_load_segment ( struct image *image, Elf_Phdr *phdr,
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
int elf_load ( struct image *image, physaddr_t *entry ) {
|
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_Ehdr ehdr;
|
||||||
Elf_Phdr phdr;
|
Elf_Phdr phdr;
|
||||||
Elf_Off phoff;
|
Elf_Off phoff;
|
||||||
|
@ -129,7 +137,8 @@ int elf_load ( struct image *image, physaddr_t *entry ) {
|
||||||
|
|
||||||
/* Read ELF header */
|
/* Read ELF header */
|
||||||
copy_from_user ( &ehdr, image->data, 0, sizeof ( ehdr ) );
|
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 );
|
DBGC ( image, "ELF %p has invalid signature\n", image );
|
||||||
return -ENOEXEC;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue