diff --git a/arch/x86/kernel/syscall.c b/arch/x86/kernel/syscall.c index 509124ec..918617c7 100644 --- a/arch/x86/kernel/syscall.c +++ b/arch/x86/kernel/syscall.c @@ -1208,6 +1208,18 @@ set_signal(int sig, void *regs0, siginfo_t *info) do_kill(thread, thread->proc->pid, thread->tid, sig, info, 0); } +int +arch_range_check(unsigned long addr) +{ + struct thread *thread = cpu_local_var(current); + struct vm_regions *region = &thread->vm->region; + + if(addr < region->user_start || + addr > region->user_end) + return -EINVAL; + return 0; +} + SYSCALL_DECLARE(mmap) { const int supported_flags = 0 diff --git a/kernel/syscall.c b/kernel/syscall.c index ba03d427..c910879a 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -113,6 +113,7 @@ extern int ptrace_detach(int pid, int data); extern void debug_log(unsigned long); extern void free_all_process_memory_range(struct process_vm *vm); extern int arch_clear_host_user_space(); +extern int arch_range_check(unsigned long addr, unsigned long len); extern struct cpu_local_var *clv; int prepare_process_ranges_args_envs(struct thread *thread, @@ -1188,7 +1189,6 @@ SYSCALL_DECLARE(munmap) const uintptr_t addr = ihk_mc_syscall_arg0(ctx); const size_t len0 = ihk_mc_syscall_arg1(ctx); struct thread *thread = cpu_local_var(current); - struct vm_regions *region = &thread->vm->region; size_t len; int error; @@ -1197,11 +1197,8 @@ SYSCALL_DECLARE(munmap) len = (len0 + PAGE_SIZE - 1) & PAGE_MASK; if ((addr & (PAGE_SIZE - 1)) - || (addr < region->user_start) - || (region->user_end <= addr) - || (len == 0) - || (len > (region->user_end - region->user_start)) - || ((region->user_end - len) < addr)) { + || arch_range_check(addr, len) + || len <= 0) { error = -EINVAL; goto out; } @@ -1222,7 +1219,6 @@ SYSCALL_DECLARE(mprotect) const size_t len0 = ihk_mc_syscall_arg1(ctx); const int prot = ihk_mc_syscall_arg2(ctx); struct thread *thread = cpu_local_var(current); - struct vm_regions *region = &thread->vm->region; size_t len; intptr_t end; struct vm_range *first; @@ -1247,9 +1243,7 @@ SYSCALL_DECLARE(mprotect) return -EINVAL; } - if ((start < region->user_start) - || (region->user_end <= start) - || ((region->user_end - start) < len)) { + if (arch_range_check(start, len)) { ekprintf("[%d]sys_mprotect(%lx,%lx,%x): -ENOMEM\n", ihk_mc_get_processor_id(), start, len0, prot); return -ENOMEM; @@ -6473,7 +6467,8 @@ SYSCALL_DECLARE(mremap) error); goto out; } - if ((newstart < oldend) && (oldstart < newend)) { + if (((newstart < oldend) && (oldstart < newend)) || + arch_range_check(newstart, newsize)) { error = -EINVAL; ekprintf("sys_mremap(%#lx,%#lx,%#lx,%#x,%#lx):" "fixed:overlapped. %d\n",