aboutsummaryrefslogtreecommitdiff
path: root/fesvr/elfloader.cc
diff options
context:
space:
mode:
authorAlexander Lent <git@xanderlent.com>2020-01-25 23:25:05 -0500
committerAndrew Waterman <andrew@sifive.com>2020-01-25 20:25:05 -0800
commit80b5b2f52541bb073fcfb3697651aeca0e8edcad (patch)
tree9b821badfa88ab4a3e1d2413558b85ccaed2692a /fesvr/elfloader.cc
parent455b8493320163c74b5443b2aed3c452aa92bc68 (diff)
downloadspike-80b5b2f52541bb073fcfb3697651aeca0e8edcad.zip
spike-80b5b2f52541bb073fcfb3697651aeca0e8edcad.tar.gz
spike-80b5b2f52541bb073fcfb3697651aeca0e8edcad.tar.bz2
Refuse to load non-EXEC/non-RISC-V/non-V1 ELFs (#388)
Stricter validation of ELF binaries improves usability with informative assertions. This prevents users from loading ELF relocatable files and binaries compiled for their (non-RISC-V) workstations, for example. Without this patch, spike would attempt to load nearly any ELF given, but it would usually fail with an error about debug module accesses, since the given ELF causes accesses in the debug module's memory space. Even if spike successfully loaded the ELF file, it would still misbehave during simulation, for example in the case of ELF relocatable files. ELF magic numbers come from official ELF documents: TIS ELF spec v1.2, via Linux Foundation Referenced Specifications See: https://refspecs.linuxbase.org/ RISC-V magic number comes from official RISC-V ELF documents: See: riscv/riscv-elf-psabi-doc@60c25981b62c0b43d16142f8a12c8b1e98e60d4d
Diffstat (limited to 'fesvr/elfloader.cc')
-rw-r--r--fesvr/elfloader.cc3
1 files changed, 3 insertions, 0 deletions
diff --git a/fesvr/elfloader.cc b/fesvr/elfloader.cc
index 610e520..fe0fbf0 100644
--- a/fesvr/elfloader.cc
+++ b/fesvr/elfloader.cc
@@ -32,6 +32,9 @@ std::map<std::string, uint64_t> load_elf(const char* fn, memif_t* memif, reg_t*
const Elf64_Ehdr* eh64 = (const Elf64_Ehdr*)buf;
assert(IS_ELF32(*eh64) || IS_ELF64(*eh64));
assert(IS_ELFLE(*eh64));
+ assert(IS_ELF_EXEC(*eh64));
+ assert(IS_ELF_RISCV(*eh64));
+ assert(IS_ELF_VCURRENT(*eh64));
std::vector<uint8_t> zeros;
std::map<std::string, uint64_t> symbols;