Add naive bounds checking for elf loading

This commit is contained in:
K. Lange 2018-08-29 08:24:14 +09:00
parent fb91f95a4e
commit 358e70b616
2 changed files with 6 additions and 0 deletions

View File

@ -88,6 +88,9 @@ int exec_elf(char * path, fs_node_t * file, int argc, char ** argv, char ** env,
Elf32_Phdr phdr;
read_fs(file, header.e_phoff + x, sizeof(Elf32_Phdr), (uint8_t *)&phdr);
if (phdr.p_type == PT_LOAD) {
/* TODO: These virtual address bounds should be in a header somewhere */
if (phdr.p_vaddr < 0x20000000) return -EINVAL;
/* TODO Upper bounds */
for (uintptr_t i = phdr.p_vaddr; i < phdr.p_vaddr + phdr.p_memsz; i += 0x1000) {
/* This doesn't care if we already allocated this page */
alloc_frame(get_page(i, 1, current_directory), 0, 1);

View File

@ -638,6 +638,9 @@ static int sys_sysfunc(int fn, char ** args) {
{
/* Load pages to fit region. */
uintptr_t address = (uintptr_t)args[0];
/* TODO: These virtual address bounds should be in a header somewhere */
if (address < 0x20000000) return -EINVAL;
/* TODO: Upper bounds */
size_t size = (size_t)args[1];
/* TODO: Other arguments for read/write? */