summaryrefslogtreecommitdiffstats
path: root/src/image
diff options
context:
space:
mode:
authorMichael Brown2012-04-09 16:15:05 +0200
committerMichael Brown2012-04-09 16:15:05 +0200
commit61851e685de53045065e331830c32ebdef101f74 (patch)
tree912ae0b09ca5c788c7aa55a62c2c36d07f353d2c /src/image
parent[image] Fix use-after-free in debug messages (diff)
downloadipxe-61851e685de53045065e331830c32ebdef101f74.tar.gz
ipxe-61851e685de53045065e331830c32ebdef101f74.tar.xz
ipxe-61851e685de53045065e331830c32ebdef101f74.zip
[elf] Avoid attempting to load 64-bit ELF binaries
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/image')
-rw-r--r--src/image/elf.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/image/elf.c b/src/image/elf.c
index 406a8d47..f4ea4aab 100644
--- a/src/image/elf.c
+++ b/src/image/elf.c
@@ -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
@@ -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;
@@ -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;
}