diff --git a/executer/include/uprotocol.h b/executer/include/uprotocol.h index bcb2681f..88a19316 100644 --- a/executer/include/uprotocol.h +++ b/executer/include/uprotocol.h @@ -65,6 +65,7 @@ struct program_load_desc { int cpu; int pid; int err; + int stack_prot; unsigned long entry; unsigned long user_start; unsigned long user_end; diff --git a/executer/user/mcexec.c b/executer/user/mcexec.c index 1d809cff..c9d64a3a 100644 --- a/executer/user/mcexec.c +++ b/executer/user/mcexec.c @@ -159,6 +159,7 @@ struct program_load_desc *load_elf(FILE *fp, char **interp_pathp) fseek(fp, hdr.e_phoff, SEEK_SET); j = 0; desc->num_sections = nhdrs; + desc->stack_prot = PROT_READ | PROT_WRITE | PROT_EXEC; /* default */ for (i = 0; i < hdr.e_phnum; i++) { if (fread(&phdr, sizeof(phdr), 1, fp) < 1) { __eprintf("Loading phdr failed (%d)\n", i); @@ -205,6 +206,12 @@ struct program_load_desc *load_elf(FILE *fp, char **interp_pathp) load_addr = phdr.p_vaddr - phdr.p_offset; } } + if (phdr.p_type == PT_GNU_STACK) { + desc->stack_prot = PROT_NONE; + desc->stack_prot |= (phdr.p_flags & PF_R)? PROT_READ: 0; + desc->stack_prot |= (phdr.p_flags & PF_W)? PROT_WRITE: 0; + desc->stack_prot |= (phdr.p_flags & PF_X)? PROT_EXEC: 0; + } } desc->pid = getpid(); desc->entry = hdr.e_entry; diff --git a/kernel/include/syscall.h b/kernel/include/syscall.h index bb945e1c..1eea16fb 100644 --- a/kernel/include/syscall.h +++ b/kernel/include/syscall.h @@ -109,6 +109,7 @@ struct program_load_desc { int cpu; int pid; int err; + int stack_prot; unsigned long entry; unsigned long user_start; unsigned long user_end; diff --git a/kernel/process.c b/kernel/process.c index d0b194d0..60cfa649 100644 --- a/kernel/process.c +++ b/kernel/process.c @@ -1333,8 +1333,8 @@ int init_process_stack(struct process *process, struct program_load_desc *pn, start = end - size; vrflag = VR_STACK | VR_DEMAND_PAGING; - vrflag |= VR_PROT_READ | VR_PROT_WRITE | VR_PROT_EXEC; - vrflag |= VRFLAG_PROT_TO_MAXPROT(vrflag); + vrflag |= PROT_TO_VR_FLAG(pn->stack_prot); + vrflag |= VR_MAXPROT_READ | VR_MAXPROT_WRITE | VR_MAXPROT_EXEC; #define NOPHYS ((uintptr_t)-1) if ((rc = add_process_memory_range(process, start, end, NOPHYS, vrflag, NULL, 0)) != 0) {