[kernel] Update kernel binary's header structure

The kernel's file header has not been verified for a long time. This
change returns file verification to the bootloader to make sure the ELF
loaded in position 0 is actually the kernel.
This commit is contained in:
Justin C. Miller
2021-05-28 14:44:13 -07:00
parent 910fde3b2c
commit 9fbbd8b954
6 changed files with 78 additions and 17 deletions

View File

@@ -113,5 +113,29 @@ load_program(
program.entrypoint = header->entrypoint;
}
void
verify_kernel_header(
init::program &program,
uefi::boot_services *bs)
{
status_line status(L"Verifying kernel header");
const init::header *header =
reinterpret_cast<const init::header *>(program.sections[0].phys_addr);
if (header->magic != init::header_magic)
error::raise(uefi::status::load_error, L"Bad kernel magic number");
if (header->length < sizeof(init::header))
error::raise(uefi::status::load_error, L"Bad kernel header length");
if (header->version < init::min_header_version)
error::raise(uefi::status::unsupported, L"Kernel header version not supported");
console::print(L" Loaded kernel vserion: %d.%d.%d %lx\r\n",
header->version_major, header->version_minor, header->version_patch,
header->version_gitsha);
}
} // namespace loader
} // namespace boot