mirror of
https://github.com/tailix/kernel.git
synced 2024-11-20 11:16:10 -05:00
Validate ELF header
This commit is contained in:
parent
93d472f866
commit
4e9b88d428
1 changed files with 25 additions and 1 deletions
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "tasks.h"
|
||||
#include "elf.h"
|
||||
#include "logger.h"
|
||||
|
||||
static struct KernelMQ_Info kinfo;
|
||||
|
||||
|
@ -31,6 +32,29 @@ void init(const struct KernelMQ_Info *const kinfo_ptr)
|
|||
paging_load();
|
||||
|
||||
if (kinfo.modules_count > 0) {
|
||||
tasks_switch_to_user(kinfo.modules[0].base);
|
||||
const struct KernelMQ_ELF_Header *const elf_header =
|
||||
(void*)kinfo.modules[0].base;
|
||||
|
||||
const unsigned char is_elf_header_valid =
|
||||
elf_header->magic_0x7F == 0x7F &&
|
||||
elf_header->magic_E == 'E' &&
|
||||
elf_header->magic_L == 'L' &&
|
||||
elf_header->magic_F == 'F' &&
|
||||
elf_header->bitness == 1 &&
|
||||
elf_header->endianness == 1 &&
|
||||
elf_header->header_version == 1 &&
|
||||
elf_header->os_abi == 0 &&
|
||||
elf_header->obj_type == 2 &&
|
||||
elf_header->isa == 3 &&
|
||||
elf_header->elf_version == 1 &&
|
||||
elf_header->arch_flags == 0 &&
|
||||
elf_header->header_size == 52;
|
||||
|
||||
if (is_elf_header_valid) {
|
||||
tasks_switch_to_user(elf_header->entrypoint);
|
||||
}
|
||||
else {
|
||||
logger_warn_from("init", "Invalid ELF header");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue