diff options
author | Marvin Borner | 2021-04-06 22:20:58 +0200 |
---|---|---|
committer | Marvin Borner | 2021-04-06 22:35:13 +0200 |
commit | 64ec8aa157e5d5d09372def37cbab00628e1e5f5 (patch) | |
tree | 13d0c864780a62506d40266fa6f2ab9571cbd216 /kernel/features | |
parent | 9326d3970fe6eedbcb042ac68aca3074aacef32f (diff) |
Made exec syscall relative using app name
My plan is to implement a mobile-OS-like sandboxing using manifests
and permission middlewares. Let's see if I can manage to do this
without sacrificing too much performance.
I'm also wondering whether I should implement open/close syscalls
which would result in a cleaner block/unblock mechanism. I need to
think. Hmmm.. Naa
Diffstat (limited to 'kernel/features')
-rw-r--r-- | kernel/features/fs.c | 4 | ||||
-rw-r--r-- | kernel/features/load.c | 20 | ||||
-rw-r--r-- | kernel/features/proc.c | 4 |
3 files changed, 16 insertions, 12 deletions
diff --git a/kernel/features/fs.c b/kernel/features/fs.c index 47e7891..b5bb2a4 100644 --- a/kernel/features/fs.c +++ b/kernel/features/fs.c @@ -565,7 +565,7 @@ static res read_inode(struct ext2_inode *in, void *buf, u32 offset, u32 count, s static u32 find_inode(const char *name, u32 dir_inode, struct device *dev) { - if (!dir_inode) + if ((signed)dir_inode <= 0) return (unsigned)-1; struct ext2_inode i = { 0 }; @@ -624,7 +624,7 @@ static struct ext2_inode *find_inode_by_path(const char *path, struct ext2_inode current_inode = find_inode(path_cp, current_inode, dev); path_cp[i] = '/'; - if (current_inode == 0) { + if ((signed)current_inode <= 0) { free(init); return NULL; } diff --git a/kernel/features/load.c b/kernel/features/load.c index d87bb94..91954b1 100644 --- a/kernel/features/load.c +++ b/kernel/features/load.c @@ -9,11 +9,19 @@ #include <random.h> #include <str.h> -res elf_load(const char *path, struct proc *proc) +res elf_load(const char *name, struct proc *proc) { - if (!memory_valid(path)) + if (!memory_valid(name)) return -EFAULT; + stac(); + char path[64] = { "/apps/" }; + strlcat(path, name, sizeof(path)); + strlcpy(proc->dir, path, sizeof(proc->dir)); + strlcat(path, "/exec", sizeof(path)); + strlcpy(proc->name, name, sizeof(proc->name)); + clac(); + struct stat s = { 0 }; memory_bypass_enable(); res stat = vfs_stat(path, &s); @@ -32,10 +40,6 @@ res elf_load(const char *path, struct proc *proc) if (read != sizeof(header)) return -ENOEXEC; - stac(); - strlcpy(proc->name, path, sizeof(proc->name)); - clac(); - // Valid? u8 *magic = header.ident; u8 valid_magic = magic[ELF_IDENT_MAG0] == ELF_MAG0 && magic[ELF_IDENT_MAG1] == ELF_MAG1 && @@ -86,8 +90,8 @@ res elf_load(const char *path, struct proc *proc) virtual_map(proc->page_dir, prange, vrange.base, MEMORY_CLEAR | MEMORY_USER); memory_bypass_enable(); - if ((u32)vfs_read(proc->name, (void *)((u32)program.vaddr + rand_off), - program.offset, program.filesz) != program.filesz) { + if ((u32)vfs_read(path, (void *)((u32)program.vaddr + rand_off), program.offset, + program.filesz) != program.filesz) { memory_bypass_disable(); memory_switch_dir(prev); return -ENOEXEC; diff --git a/kernel/features/proc.c b/kernel/features/proc.c index f547193..479427c 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -559,7 +559,7 @@ NORETURN void proc_init(void) // Idle proc // TODO: Reimplement hlt privileges in idle proc (SMEP!) struct proc *kernel_proc = proc_make(PROC_PRIV_NONE); - assert(elf_load("/bin/idle", kernel_proc) == EOK); + assert(elf_load("idle", kernel_proc) == EOK); proc_stack_push(kernel_proc, 0); proc_stack_push(kernel_proc, 0); kernel_proc->state = PROC_BLOCKED; @@ -570,7 +570,7 @@ NORETURN void proc_init(void) // Init proc (root) struct proc *init = proc_make(PROC_PRIV_ROOT); - assert(elf_load("/bin/init", init) == EOK); + assert(elf_load("init", init) == EOK); proc_stack_push(init, 0); proc_stack_push(init, 0); current = list_first_data(proc_list_running, init); |