Kaynağa Gözat

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

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 yıl önce
ebeveyn
işleme
61851e685d
1 değiştirilmiş dosya ile 10 ekleme ve 1 silme
  1. 10
    1
      src/image/elf.c

+ 10
- 1
src/image/elf.c Dosyayı Görüntüle

@@ -38,6 +38,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
38 38
 typedef Elf32_Ehdr	Elf_Ehdr;
39 39
 typedef Elf32_Phdr	Elf_Phdr;
40 40
 typedef Elf32_Off	Elf_Off;
41
+#define ELFCLASS	ELFCLASS32
41 42
 
42 43
 /**
43 44
  * Load ELF segment into memory
@@ -121,6 +122,13 @@ static int elf_load_segment ( struct image *image, Elf_Phdr *phdr,
121 122
  * @ret rc		Return status code
122 123
  */
123 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 132
 	Elf_Ehdr ehdr;
125 133
 	Elf_Phdr phdr;
126 134
 	Elf_Off phoff;
@@ -129,7 +137,8 @@ int elf_load ( struct image *image, physaddr_t *entry ) {
129 137
 
130 138
 	/* Read ELF header */
131 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 142
 		DBGC ( image, "ELF %p has invalid signature\n", image );
134 143
 		return -ENOEXEC;
135 144
 	}

Loading…
İptal
Kaydet