From: deraadt Date: Thu, 16 Feb 2023 04:42:06 +0000 (+0000) Subject: Add pinsyscall(2). With this you can tell the kernel the location X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=47565b742e7af3a7965ea58d06375098439da77b;p=openbsd Add pinsyscall(2). With this you can tell the kernel the location (start,len) of the syscall stub in libc.so for a specified syscall (using SYS_* notation). Only SYS_execve is supported at this time. ok gnezdo mortimer kettenis --- diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index d799adcc9b2..67a5424af2f 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -1,4 +1,4 @@ -; $OpenBSD: syscalls.master,v 1.243 2023/02/14 08:34:49 mvs Exp $ +; $OpenBSD: syscalls.master,v 1.244 2023/02/16 04:42:06 deraadt Exp $ ; $NetBSD: syscalls.master,v 1.32 1996/04/23 10:24:21 mycroft Exp $ ; @(#)syscalls.master 8.2 (Berkeley) 1/13/94 @@ -284,7 +284,7 @@ 143 STD { int sys_setthrname(pid_t tid, const char *name); } 144 OBSOL ogetrlimit 145 OBSOL osetrlimit -146 OBSOL okillpg +146 STD NOLOCK { int sys_pinsyscall(int syscall, void *addr, size_t len); } 147 STD { int sys_setsid(void); } 148 STD { int sys_quotactl(const char *path, int cmd, \ int uid, char *arg); } diff --git a/sys/uvm/uvm_extern.h b/sys/uvm/uvm_extern.h index 6f4ddc5327a..994957f7c9e 100644 --- a/sys/uvm/uvm_extern.h +++ b/sys/uvm/uvm_extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_extern.h,v 1.166 2022/11/17 18:53:05 deraadt Exp $ */ +/* $OpenBSD: uvm_extern.h,v 1.167 2023/02/16 04:42:07 deraadt Exp $ */ /* $NetBSD: uvm_extern.h,v 1.57 2001/03/09 01:02:12 chs Exp $ */ /* @@ -214,6 +214,8 @@ struct vmspace { caddr_t vm_daddr; /* [I] user virtual address of data */ caddr_t vm_maxsaddr; /* [I] user VA at max stack growth */ caddr_t vm_minsaddr; /* [I] user VA at top of stack */ + vaddr_t vm_execve; /* [v] execve systemcall stub region */ + vaddr_t vm_execve_end; /* [v] execve systemcall stub region */ }; /* diff --git a/sys/uvm/uvm_mmap.c b/sys/uvm/uvm_mmap.c index e3dcd41089e..db0adcfdcc4 100644 --- a/sys/uvm/uvm_mmap.c +++ b/sys/uvm/uvm_mmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_mmap.c,v 1.178 2023/02/11 23:22:19 deraadt Exp $ */ +/* $OpenBSD: uvm_mmap.c,v 1.179 2023/02/16 04:42:08 deraadt Exp $ */ /* $NetBSD: uvm_mmap.c,v 1.49 2001/02/18 21:19:08 chs Exp $ */ /* @@ -68,6 +68,7 @@ #include /* for __LDPGSZ */ +#include #include #include @@ -615,6 +616,38 @@ sys_msyscall(struct proc *p, void *v, register_t *retval) return uvm_map_syscall(&p->p_vmspace->vm_map, addr, addr+size); } +/* + * sys_pinsyscall + */ +int +sys_pinsyscall(struct proc *p, void *v, register_t *retval) +{ + struct sys_pinsyscall_args /* { + syscallarg(int) syscall; + syscallarg(void *) addr; + syscallarg(size_t) len; + } */ *uap = v; + struct vmspace *vm = p->p_vmspace; + vm_map_t map = &p->p_vmspace->vm_map; + vaddr_t start, end; + + if (SCARG(uap, syscall) != SYS_execve) + return (EINVAL); + start = (vaddr_t)SCARG(uap, addr); + end = start + (vsize_t)SCARG(uap, len); + if (start >= end || start < map->min_offset || end > map->max_offset) + return (EFAULT); + vm_map_lock(map); + if (vm->vm_execve) { + vm_map_unlock(map); + return (EPERM); + } + vm->vm_execve = start; + vm->vm_execve_end = end; + vm_map_unlock(map); + return (0); +} + /* * sys_mimmutable: the mimmutable system call */