Browse Source

[elf] Avoid attempting to load 64-bit ELF binaries

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
61851e685d
1 changed files with 10 additions and 1 deletions
  1. 10
    1
      src/image/elf.c

+ 10
- 1
src/image/elf.c View File

38
 typedef Elf32_Ehdr	Elf_Ehdr;
38
 typedef Elf32_Ehdr	Elf_Ehdr;
39
 typedef Elf32_Phdr	Elf_Phdr;
39
 typedef Elf32_Phdr	Elf_Phdr;
40
 typedef Elf32_Off	Elf_Off;
40
 typedef Elf32_Off	Elf_Off;
41
+#define ELFCLASS	ELFCLASS32
41
 
42
 
42
 /**
43
 /**
43
  * Load ELF segment into memory
44
  * Load ELF segment into memory
121
  * @ret rc		Return status code
122
  * @ret rc		Return status code
122
  */
123
  */
123
 int elf_load ( struct image *image, physaddr_t *entry ) {
124
 int elf_load ( struct image *image, physaddr_t *entry ) {
125
+	static const uint8_t e_ident[] = {
126
+		[EI_MAG0]	= ELFMAG0,
127
+		[EI_MAG1]	= ELFMAG1,
128
+		[EI_MAG2]	= ELFMAG2,
129
+		[EI_MAG3]	= ELFMAG3,
130
+		[EI_CLASS]	= ELFCLASS,
131
+	};
124
 	Elf_Ehdr ehdr;
132
 	Elf_Ehdr ehdr;
125
 	Elf_Phdr phdr;
133
 	Elf_Phdr phdr;
126
 	Elf_Off phoff;
134
 	Elf_Off phoff;
129
 
137
 
130
 	/* Read ELF header */
138
 	/* Read ELF header */
131
 	copy_from_user ( &ehdr, image->data, 0, sizeof ( ehdr ) );
139
 	copy_from_user ( &ehdr, image->data, 0, sizeof ( ehdr ) );
132
-	if ( memcmp ( &ehdr.e_ident[EI_MAG0], ELFMAG, SELFMAG ) != 0 ) {
140
+	if ( memcmp ( &ehdr.e_ident[EI_MAG0], e_ident,
141
+		      sizeof ( e_ident ) ) != 0 ) {
133
 		DBGC ( image, "ELF %p has invalid signature\n", image );
142
 		DBGC ( image, "ELF %p has invalid signature\n", image );
134
 		return -ENOEXEC;
143
 		return -ENOEXEC;
135
 	}
144
 	}

Loading…
Cancel
Save