diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2023-12-12 15:30:57 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2023-12-12 15:30:57 +0000 |
commit | 8c7460c9897521d5f816ac3fda78a94555c9b9b8 (patch) | |
tree | a76554430df0c1549d7f9a58111ca1376d678b61 /sys | |
parent | d88a737e6a2d8df255f5eb84d88fdb69f559a924 (diff) |
remove support for syscall(2) -- the "indirection system call" because
it is a dangerous alternative entry point for all system calls, and thus
incompatible with the precision system call entry point scheme we are
heading towards. This has been a 3-year mission:
First perl needed a code-generated wrapper to fake syscall(2) as a giant
switch table, then all the ports were cleaned with relatively minor fixes,
except for "go". "go" required two fixes -- 1) a framework issue with
old library versions, and 2) like perl, a fake syscall(2) wrapper to
handle ioctl(2) and sysctl(2) because "syscall(SYS_ioctl" occurs all over
the place in the "go" ecosystem because the "go developers" are plan9-loving
unix-hating folk who tried to build an ecosystem without allowing "ioctl".
ok kettenis, jsing, afresh1, sthen
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/alpha/alpha/trap.c | 33 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/locore.S | 3 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/trap.c | 29 | ||||
-rw-r--r-- | sys/arch/arm/arm/syscall.c | 33 | ||||
-rw-r--r-- | sys/arch/arm64/arm64/syscall.c | 23 | ||||
-rw-r--r-- | sys/arch/hppa/hppa/trap.c | 36 | ||||
-rw-r--r-- | sys/arch/i386/i386/trap.c | 36 | ||||
-rw-r--r-- | sys/arch/m88k/m88k/trap.c | 37 | ||||
-rw-r--r-- | sys/arch/mips64/mips64/trap.c | 71 | ||||
-rw-r--r-- | sys/arch/powerpc/powerpc/trap.c | 30 | ||||
-rw-r--r-- | sys/arch/powerpc64/powerpc64/syscall.c | 28 | ||||
-rw-r--r-- | sys/arch/riscv64/riscv64/syscall.c | 30 | ||||
-rw-r--r-- | sys/arch/sh/sh/trap.c | 64 | ||||
-rw-r--r-- | sys/arch/sparc64/sparc64/trap.c | 54 | ||||
-rw-r--r-- | sys/kern/kern_ktrace.c | 4 | ||||
-rw-r--r-- | sys/kern/syscalls.master | 4 | ||||
-rw-r--r-- | sys/sys/ktrace.h | 4 | ||||
-rw-r--r-- | sys/sys/syscall_mi.h | 15 |
18 files changed, 152 insertions, 382 deletions
diff --git a/sys/arch/alpha/alpha/trap.c b/sys/arch/alpha/alpha/trap.c index abe69405852..fc697aadf41 100644 --- a/sys/arch/alpha/alpha/trap.c +++ b/sys/arch/alpha/alpha/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.108 2023/03/08 04:43:07 guenther Exp $ */ +/* $OpenBSD: trap.c,v 1.109 2023/12/12 15:30:55 deraadt Exp $ */ /* $NetBSD: trap.c,v 1.52 2000/05/24 16:48:33 thorpej Exp $ */ /*- @@ -497,17 +497,15 @@ dopanic: * a3, and v0 from the frame before returning to the user process. */ void -syscall(code, framep) - u_int64_t code; - struct trapframe *framep; +syscall(u_int64_t code, struct trapframe *framep) { - const struct sysent *callp; + const struct sysent *callp = sysent; struct proc *p; - int error, indirect = -1; + int error; u_int64_t opc; u_long rval[2]; u_long args[10]; /* XXX */ - u_int hidden, nargs; + u_int nargs; atomic_add_int(&uvmexp.syscalls, 1); p = curproc; @@ -515,24 +513,11 @@ syscall(code, framep) framep->tf_regs[FRAME_SP] = alpha_pal_rdusp(); opc = framep->tf_regs[FRAME_PC] - 4; - switch(code) { - case SYS_syscall: - indirect = code; - code = framep->tf_regs[FRAME_A0]; - hidden = 1; - break; - default: - hidden = 0; - } - - error = 0; - callp = sysent; - if (code >= SYS_MAXSYSCALL) - callp += SYS_syscall; - else + // XXX out of range stays on syscall0, which we assume is enosys + if (code >= 0 || code <= SYS_MAXSYSCALL) callp += code; - nargs = callp->sy_narg + hidden; + nargs = callp->sy_narg; switch (nargs) { default: if (nargs > 10) /* XXX */ @@ -559,7 +544,7 @@ syscall(code, framep) rval[0] = 0; rval[1] = 0; - error = mi_syscall(p, code, indirect, callp, args + hidden, rval); + error = mi_syscall(p, code, callp, args, rval); switch (error) { case 0: diff --git a/sys/arch/amd64/amd64/locore.S b/sys/arch/amd64/amd64/locore.S index b36ab19d853..b8b9c3274d8 100644 --- a/sys/arch/amd64/amd64/locore.S +++ b/sys/arch/amd64/amd64/locore.S @@ -1,4 +1,4 @@ -/* $OpenBSD: locore.S,v 1.143 2023/12/12 07:37:20 deraadt Exp $ */ +/* $OpenBSD: locore.S,v 1.144 2023/12/12 15:30:55 deraadt Exp $ */ /* $NetBSD: locore.S,v 1.13 2004/03/25 18:33:17 drochner Exp $ */ /* @@ -507,6 +507,7 @@ ENTRY(savectx) lfence END(savectx) +// XXX this should not behave like a nop IDTVEC(syscall32) sysret /* go away please */ END(Xsyscall32) diff --git a/sys/arch/amd64/amd64/trap.c b/sys/arch/amd64/amd64/trap.c index 8fc51b3961f..bccc016f790 100644 --- a/sys/arch/amd64/amd64/trap.c +++ b/sys/arch/amd64/amd64/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.101 2023/07/05 12:58:55 kn Exp $ */ +/* $OpenBSD: trap.c,v 1.102 2023/12/12 15:30:55 deraadt Exp $ */ /* $NetBSD: trap.c,v 1.2 2003/05/04 23:51:56 fvdl Exp $ */ /*- @@ -553,7 +553,7 @@ syscall(struct trapframe *frame) caddr_t params; const struct sysent *callp; struct proc *p; - int error, indirect = -1; + int error = ENOSYS; size_t argsize, argoff; register_t code, args[9], rval[2], *argp; @@ -570,26 +570,9 @@ syscall(struct trapframe *frame) argp = &args[0]; argoff = 0; - switch (code) { - case SYS_syscall: - /* - * Code is first argument, followed by actual args. - */ - indirect = code; - code = frame->tf_rdi; - argp = &args[1]; - argoff = 1; - break; - default: - break; - } - - callp = sysent; - if (code < 0 || code >= SYS_MAXSYSCALL) - callp += SYS_syscall; - else - callp += code; - + if (code <= 0 || code >= SYS_MAXSYSCALL) + goto bad; + callp = sysent + code; argsize = (callp->sy_argsize >> 3) + argoff; if (argsize) { switch (MIN(argsize, 6)) { @@ -620,7 +603,7 @@ syscall(struct trapframe *frame) rval[0] = 0; rval[1] = 0; - error = mi_syscall(p, code, indirect, callp, argp, rval); + error = mi_syscall(p, code, callp, argp, rval); switch (error) { case 0: diff --git a/sys/arch/arm/arm/syscall.c b/sys/arch/arm/arm/syscall.c index c23dcc32f2a..3879834e2ea 100644 --- a/sys/arch/arm/arm/syscall.c +++ b/sys/arch/arm/arm/syscall.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.c,v 1.26 2023/02/11 23:07:26 deraadt Exp $ */ +/* $OpenBSD: syscall.c,v 1.27 2023/12/12 15:30:55 deraadt Exp $ */ /* $NetBSD: syscall.c,v 1.24 2003/11/14 19:03:17 scw Exp $ */ /*- @@ -93,8 +93,8 @@ void swi_handler(trapframe_t *frame) { struct proc *p = curproc; - const struct sysent *callp; - int code, error, indirect = -1; + const struct sysent *callp = sysent; + int code, error; u_int nap = 4, nargs; register_t *ap, *args, copyargs[MAXARGS], rval[2]; @@ -103,31 +103,18 @@ swi_handler(trapframe_t *frame) /* Before enabling interrupts, save FPU state */ vfp_save(); - /* Re-enable interrupts if they were enabled previously */ - if (__predict_true((frame->tf_spsr & PSR_I) == 0)) - enable_interrupts(PSR_I); + enable_interrupts(PSR_I); p->p_addr->u_pcb.pcb_tf = frame; /* Skip over speculation-blocking barrier. */ frame->tf_pc += 8; - code = frame->tf_r12; - ap = &frame->tf_r0; - switch (code) { - case SYS_syscall: - indirect = code; - code = *ap++; - nap--; - break; - } - - callp = sysent; - if (code < 0 || code >= SYS_MAXSYSCALL) - callp += SYS_syscall; - else + code = frame->tf_r12; + // XXX out of range stays on syscall0, which we assume is enosys + if (code >= 0 || code <= SYS_MAXSYSCALL) callp += code; nargs = callp->sy_argsize / sizeof(register_t); @@ -145,27 +132,23 @@ swi_handler(trapframe_t *frame) rval[0] = 0; rval[1] = frame->tf_r1; - error = mi_syscall(p, code, indirect, callp, args, rval); + error = mi_syscall(p, code, callp, args, rval); switch (error) { case 0: frame->tf_r0 = rval[0]; frame->tf_r1 = rval[1]; - frame->tf_spsr &= ~PSR_C; /* carry bit */ break; - case ERESTART: /* * Reconstruct the pc to point at the swi. */ frame->tf_pc -= 12; break; - case EJUSTRETURN: /* nothing to do */ break; - default: bad: frame->tf_r0 = error; diff --git a/sys/arch/arm64/arm64/syscall.c b/sys/arch/arm64/arm64/syscall.c index 0f3b52f23bf..eec3777d2d8 100644 --- a/sys/arch/arm64/arm64/syscall.c +++ b/sys/arch/arm64/arm64/syscall.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.c,v 1.14 2023/04/13 02:19:04 jsg Exp $ */ +/* $OpenBSD: syscall.c,v 1.15 2023/12/12 15:30:55 deraadt Exp $ */ /* * Copyright (c) 2015 Dale Rahn <drahn@dalerahn.com> * @@ -33,7 +33,7 @@ svc_handler(trapframe_t *frame) { struct proc *p = curproc; const struct sysent *callp; - int code, error, indirect = -1; + int code, error = ENOSYS, indirect = -1; u_int nap = 8, nargs; register_t *ap, *args, copyargs[MAXARGS], rval[2]; @@ -50,20 +50,10 @@ svc_handler(trapframe_t *frame) ap = &frame->tf_x[0]; - switch (code) { - case SYS_syscall: - indirect = code; - code = *ap++; - nap--; - break; - } - - callp = sysent; if (code < 0 || code >= SYS_MAXSYSCALL) - callp += SYS_syscall; - else - callp += code; + goto bad; + callp = sysent + code; nargs = callp->sy_argsize / sizeof(register_t); if (nargs <= nap) { args = ap; @@ -79,25 +69,22 @@ svc_handler(trapframe_t *frame) rval[0] = 0; rval[1] = 0; - error = mi_syscall(p, code, indirect, callp, args, rval); + error = mi_syscall(p, code, callp, args, rval); switch (error) { case 0: frame->tf_x[0] = rval[0]; frame->tf_spsr &= ~PSR_C; /* carry bit */ break; - case ERESTART: /* * Reconstruct the pc to point at the svc. */ frame->tf_elr -= 12; break; - case EJUSTRETURN: /* nothing to do */ break; - default: bad: frame->tf_x[0] = error; diff --git a/sys/arch/hppa/hppa/trap.c b/sys/arch/hppa/hppa/trap.c index bebd3c072ba..2a92b7d7b40 100644 --- a/sys/arch/hppa/hppa/trap.c +++ b/sys/arch/hppa/hppa/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.161 2023/02/11 23:07:26 deraadt Exp $ */ +/* $OpenBSD: trap.c,v 1.162 2023/12/12 15:30:55 deraadt Exp $ */ /* * Copyright (c) 1998-2004 Michael Shalayeff @@ -764,8 +764,8 @@ void syscall(struct trapframe *frame) { struct proc *p = curproc; - const struct sysent *callp; - int retq, code, argsize, argoff, error, indirect = -1; + const struct sysent *callp = sysent; + int retq, code, argsize, argoff, error; register_t args[8], rval[2]; #ifdef DIAGNOSTIC int oldcpl = curcpu()->ci_cpl; @@ -779,27 +779,13 @@ syscall(struct trapframe *frame) p->p_md.md_regs = frame; argoff = 4; retq = 0; - switch (code = frame->tf_t1) { - case SYS_syscall: - indirect = code; - code = frame->tf_arg0; - args[0] = frame->tf_arg1; - args[1] = frame->tf_arg2; - args[2] = frame->tf_arg3; - argoff = 3; - break; - default: - args[0] = frame->tf_arg0; - args[1] = frame->tf_arg1; - args[2] = frame->tf_arg2; - args[3] = frame->tf_arg3; - break; - } + args[0] = frame->tf_arg0; + args[1] = frame->tf_arg1; + args[2] = frame->tf_arg2; + args[3] = frame->tf_arg3; - callp = sysent; - if (code < 0 || code >= SYS_MAXSYSCALL) - callp += SYS_syscall; - else + // XXX out of range stays on syscall0, which we assume is enosys + if (code >= 0 || code <= SYS_MAXSYSCALL) callp += code; if ((argsize = callp->sy_argsize)) { @@ -851,7 +837,7 @@ syscall(struct trapframe *frame) rval[0] = 0; rval[1] = frame->tf_ret1; - error = mi_syscall(p, code, indirect, callp, args, rval); + error = mi_syscall(p, code, callp, args, rval); switch (error) { case 0: @@ -872,7 +858,7 @@ syscall(struct trapframe *frame) break; } - ast(p); + ast(p); // XXX why? mi_syscall_return(p, code, error, rval); diff --git a/sys/arch/i386/i386/trap.c b/sys/arch/i386/i386/trap.c index 8208c89ffcb..69860df9030 100644 --- a/sys/arch/i386/i386/trap.c +++ b/sys/arch/i386/i386/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.162 2023/04/16 06:43:49 jsg Exp $ */ +/* $OpenBSD: trap.c,v 1.163 2023/12/12 15:30:55 deraadt Exp $ */ /* $NetBSD: trap.c,v 1.95 1996/05/05 06:50:02 mycroft Exp $ */ /*- @@ -516,9 +516,9 @@ void syscall(struct trapframe *frame) { caddr_t params; - const struct sysent *callp; - struct proc *p; - int error, indirect = -1; + const struct sysent *callp = sysent; + struct proc *p = curproc; + int error; register_t code, args[8], rval[2]; #ifdef DIAGNOSTIC int ocpl = lapic_tpr; @@ -540,38 +540,22 @@ syscall(struct trapframe *frame) } #endif - p = curproc; p->p_md.md_regs = frame; - code = frame->tf_eax; - - params = (caddr_t)frame->tf_esp + sizeof(int); - switch (code) { - case SYS_syscall: - /* - * Code is first argument, followed by actual args. - */ - indirect = code; - copyin(params, &code, sizeof(int)); - params += sizeof(int); - break; - default: - break; - } - - callp = sysent; - if (code < 0 || code >= SYS_MAXSYSCALL) - callp += SYS_syscall; - else + code = frame->tf_eax; + // XXX out of range stays on syscall0, which we assume is enosys + if (code >= 0 || code <= SYS_MAXSYSCALL) callp += code; + argsize = callp->sy_argsize; + params = (caddr_t)frame->tf_esp + sizeof(int); if (argsize && (error = copyin(params, args, argsize))) goto bad; rval[0] = 0; rval[1] = frame->tf_edx; - error = mi_syscall(p, code, indirect, callp, args, rval); + error = mi_syscall(p, code, callp, args, rval); switch (error) { case 0: diff --git a/sys/arch/m88k/m88k/trap.c b/sys/arch/m88k/m88k/trap.c index 11abfd2812f..fc37bc4b363 100644 --- a/sys/arch/m88k/m88k/trap.c +++ b/sys/arch/m88k/m88k/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.128 2023/08/02 06:14:46 miod Exp $ */ +/* $OpenBSD: trap.c,v 1.129 2023/12/12 15:30:56 deraadt Exp $ */ /* * Copyright (c) 2004, Miodrag Vallat. * Copyright (c) 1998 Steve Murphree, Jr. @@ -1153,9 +1153,9 @@ void m88100_syscall(register_t code, struct trapframe *tf) { int i, nap; - const struct sysent *callp; + const struct sysent *callp = sysent; struct proc *p = curproc; - int error, indirect = -1; + int error; register_t args[8] __aligned(8); register_t rval[2] __aligned(8); register_t *ap; @@ -1172,18 +1172,8 @@ m88100_syscall(register_t code, struct trapframe *tf) ap = &tf->tf_r[2]; nap = 8; /* r2-r9 */ - switch (code) { - case SYS_syscall: - indirect = code; - code = *ap++; - nap--; - break; - } - - callp = sysent; - if (code < 0 || code >= SYS_MAXSYSCALL) - callp += SYS_syscall; - else + // XXX out of range stays on syscall0, which we assume is enosys + if (code >= 0 || code <= SYS_MAXSYSCALL) callp += code; i = callp->sy_argsize / sizeof(register_t); @@ -1200,7 +1190,7 @@ m88100_syscall(register_t code, struct trapframe *tf) rval[0] = 0; rval[1] = tf->tf_r[3]; - error = mi_syscall(p, code, indirect, callp, args, rval); + error = mi_syscall(p, code, callp, args, rval); /* * system call will look like: @@ -1266,7 +1256,7 @@ void m88110_syscall(register_t code, struct trapframe *tf) { int i, nap; - const struct sysent *callp; + const struct sysent *callp = sysent; struct proc *p = curproc; int error; register_t args[8] __aligned(8); @@ -1285,17 +1275,8 @@ m88110_syscall(register_t code, struct trapframe *tf) ap = &tf->tf_r[2]; nap = 8; /* r2-r9 */ - switch (code) { - case SYS_syscall: - code = *ap++; - nap--; - break; - } - - callp = sysent; - if (code < 0 || code >= SYS_MAXSYSCALL) - callp += SYS_syscall; - else + // XXX out of range stays on syscall0, which we assume is enosys + if (code >= 0 || code <= SYS_MAXSYSCALL) callp += code; i = callp->sy_argsize / sizeof(register_t); diff --git a/sys/arch/mips64/mips64/trap.c b/sys/arch/mips64/mips64/trap.c index df4d2adebe5..343ac891df6 100644 --- a/sys/arch/mips64/mips64/trap.c +++ b/sys/arch/mips64/mips64/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.167 2023/04/26 16:53:59 claudio Exp $ */ +/* $OpenBSD: trap.c,v 1.168 2023/12/12 15:30:56 deraadt Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -396,8 +396,8 @@ fault_common_no_miss: case T_SYSCALL+T_USER: { struct trapframe *locr0 = p->p_md.md_regs; - const struct sysent *callp; - unsigned int code, indirect = -1; + const struct sysent *callp = sysent; + unsigned int code; register_t tpc; uint32_t branch = 0; int error, numarg; @@ -422,51 +422,22 @@ fault_common_no_miss: trapframe->pc, 0, branch); } else locr0->pc += 4; - callp = sysent; code = locr0->v0; - switch (code) { - case SYS_syscall: - /* - * Code is first argument, followed by actual args. - */ - indirect = code; - code = locr0->a0; - if (code >= SYS_MAXSYSCALL) - callp += SYS_syscall; - else - callp += code; - numarg = callp->sy_argsize / sizeof(register_t); - args.i[0] = locr0->a1; - args.i[1] = locr0->a2; - args.i[2] = locr0->a3; - if (numarg > 3) { - args.i[3] = locr0->a4; - args.i[4] = locr0->a5; - args.i[5] = locr0->a6; - args.i[6] = locr0->a7; - if (numarg > 7) - if ((error = copyin((void *)locr0->sp, - &args.i[7], sizeof(register_t)))) - goto bad; - } - break; - default: - if (code >= SYS_MAXSYSCALL) - callp += SYS_syscall; - else - callp += code; - - numarg = callp->sy_narg; - args.i[0] = locr0->a0; - args.i[1] = locr0->a1; - args.i[2] = locr0->a2; - args.i[3] = locr0->a3; - if (numarg > 4) { - args.i[4] = locr0->a4; - args.i[5] = locr0->a5; - args.i[6] = locr0->a6; - args.i[7] = locr0->a7; - } + + // XXX out of range stays on syscall0, which we assume is enosys + if (code >= 0 || code <= SYS_MAXSYSCALL) + callp += code; + + numarg = callp->sy_narg; + args.i[0] = locr0->a0; + args.i[1] = locr0->a1; + args.i[2] = locr0->a2; + args.i[3] = locr0->a3; + if (numarg > 4) { + args.i[4] = locr0->a4; + args.i[5] = locr0->a5; + args.i[6] = locr0->a6; + args.i[7] = locr0->a7; } rval[0] = 0; @@ -477,21 +448,18 @@ fault_common_no_miss: TRAPSIZE : trppos[ci->ci_cpuid]) - 1].code = code; #endif - error = mi_syscall(p, code, indirect, callp, args.i, rval); + error = mi_syscall(p, code, callp, args.i, rval); switch (error) { case 0: locr0->v0 = rval[0]; locr0->a3 = 0; break; - case ERESTART: locr0->pc = tpc; break; - case EJUSTRETURN: break; /* nothing to do */ - default: bad: locr0->v0 = error; @@ -499,7 +467,6 @@ fault_common_no_miss: } mi_syscall_return(p, code, error, rval); - return; } diff --git a/sys/arch/powerpc/powerpc/trap.c b/sys/arch/powerpc/powerpc/trap.c index 94ec7ccf281..bd20eb437b2 100644 --- a/sys/arch/powerpc/powerpc/trap.c +++ b/sys/arch/powerpc/powerpc/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.131 2023/02/11 23:07:27 deraadt Exp $ */ +/* $OpenBSD: trap.c,v 1.132 2023/12/12 15:30:56 deraadt Exp $ */ /* $NetBSD: trap.c,v 1.3 1996/10/13 03:31:37 christos Exp $ */ /* @@ -239,11 +239,11 @@ trap(struct trapframe *frame) struct vm_map *map; vaddr_t va; int access_type; - const struct sysent *callp; + const struct sysent *callp = sysent; size_t argsize; register_t code, error; register_t *params, rval[2], args[10]; - int n, indirect = -1; + int n; if (frame->srr1 & PSL_PR) { type |= EXC_USER; @@ -360,27 +360,13 @@ trap(struct trapframe *frame) case EXC_SC|EXC_USER: uvmexp.syscalls++; - code = frame->fixreg[0]; params = frame->fixreg + FIRSTARG; - switch (code) { - case SYS_syscall: - /* - * code is first argument, - * followed by actual args. - */ - indirect = code; - code = *params++; - break; - default: - break; - } + code = frame->fixreg[0]; + // XXX out of range stays on syscall0, which we assume is enosys + if (code >= 0 || code <= SYS_MAXSYSCALL) + callp += code; - callp = sysent; - if (code < 0 || code >= SYS_MAXSYSCALL) - callp += SYS_syscall; - else - callp += code; argsize = callp->sy_argsize; n = NARGREG - (params - (frame->fixreg + FIRSTARG)); if (argsize > n * sizeof(register_t)) { @@ -395,7 +381,7 @@ trap(struct trapframe *frame) rval[0] = 0; rval[1] = frame->fixreg[FIRSTARG + 1]; - error = mi_syscall(p, code, indirect, callp, params, rval); + error = mi_syscall(p, code, callp, params, rval); switch (error) { case 0: diff --git a/sys/arch/powerpc64/powerpc64/syscall.c b/sys/arch/powerpc64/powerpc64/syscall.c index 04fcc332728..d2527458940 100644 --- a/sys/arch/powerpc64/powerpc64/syscall.c +++ b/sys/arch/powerpc64/powerpc64/syscall.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.c,v 1.11 2023/02/11 23:07:27 deraadt Exp $ */ +/* $OpenBSD: syscall.c,v 1.12 2023/12/12 15:30:56 deraadt Exp $ */ /* * Copyright (c) 2015 Dale Rahn <drahn@dalerahn.com> @@ -30,27 +30,18 @@ void syscall(struct trapframe *frame) { struct proc *p = curproc; - const struct sysent *callp; - int code, error, indirect = -1; + const struct sysent *callp = sysent; + int code, error; int nap = 8, nargs; register_t *ap, *args, copyargs[MAXARGS], rval[2]; - code = frame->fixreg[0]; ap = &frame->fixreg[3]; - switch (code) { - case SYS_syscall: - indirect = code; - code = *ap++; - nap--; - break; - } - - callp = sysent; - if (code < 0 || code >= SYS_MAXSYSCALL) - callp += SYS_syscall; - else + code = frame->fixreg[0]; + // XXX out of range stays on syscall0, which we assume is enosys + if (code >= 0 || code <= SYS_MAXSYSCALL) callp += code; + nargs = callp->sy_argsize / sizeof(register_t); if (nargs <= nap) { args = ap; @@ -66,7 +57,7 @@ syscall(struct trapframe *frame) rval[0] = 0; rval[1] = 0; - error = mi_syscall(p, code, indirect, callp, args, rval); + error = mi_syscall(p, code, callp, args, rval); switch (error) { case 0: @@ -74,15 +65,12 @@ syscall(struct trapframe *frame) frame->fixreg[3] = rval[0]; frame->cr &= ~0x10000000; break; - case ERESTART: frame->srr0 -= 4; break; - case EJUSTRETURN: /* nothing to do */ break; - default: bad: frame->fixreg[0] = error; diff --git a/sys/arch/riscv64/riscv64/syscall.c b/sys/arch/riscv64/riscv64/syscall.c index 65f6f8fb7c4..ed5e534d7e0 100644 --- a/sys/arch/riscv64/riscv64/syscall.c +++ b/sys/arch/riscv64/riscv64/syscall.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall.c,v 1.16 2023/04/13 02:19:05 jsg Exp $ */ +/* $OpenBSD: syscall.c,v 1.17 2023/12/12 15:30:56 deraadt Exp $ */ /* * Copyright (c) 2020 Brian Bamsch <bbamsch@google.com> @@ -39,33 +39,20 @@ void svc_handler(trapframe_t *frame) { struct proc *p = curproc; - const struct sysent *callp; - int code, error, indirect = -1; + const struct sysent *callp = sysent; + int code, error; u_int nap = 8, nargs; register_t *ap, *args, copyargs[MAXARGS], rval[2]; uvmexp.syscalls++; - /* Re-enable interrupts if they were enabled previously */ - if (__predict_true(frame->tf_scause & EXCP_INTR)) - intr_enable(); - ap = &frame->tf_a[0]; code = frame->tf_t[0]; - switch (code) { - case SYS_syscall: - indirect = code; - code = *ap++; - nap--; - break; - } - - callp = sysent; - if (code < 0 || code >= SYS_MAXSYSCALL) - callp += SYS_syscall; - else + // XXX out of range stays on syscall0, which we assume is enosys + if (code >= 0 || code <= SYS_MAXSYSCALL) callp += code; + nargs = callp->sy_argsize / sizeof(register_t); if (nargs <= nap) { args = ap; @@ -81,21 +68,18 @@ svc_handler(trapframe_t *frame) rval[0] = 0; rval[1] = 0; - error = mi_syscall(p, code, indirect, callp, args, rval); + error = mi_syscall(p, code, callp, args, rval); switch (error) { case 0: frame->tf_a[0] = rval[0]; frame->tf_t[0] = 0; /* syscall succeeded */ break; - case ERESTART: frame->tf_sepc -= 4; /* prev instruction */ break; - case EJUSTRETURN: break; - default: bad: frame->tf_a[0] = error; diff --git a/sys/arch/sh/sh/trap.c b/sys/arch/sh/sh/trap.c index 72421959d63..0002a8cae56 100644 --- a/sys/arch/sh/sh/trap.c +++ b/sys/arch/sh/sh/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.54 2023/02/11 23:07:27 deraadt Exp $ */ +/* $OpenBSD: trap.c,v 1.55 2023/12/12 15:30:56 deraadt Exp $ */ /* $NetBSD: exception.c,v 1.32 2006/09/04 23:57:52 uwe Exp $ */ /* $NetBSD: syscall.c,v 1.6 2006/03/07 07:21:50 thorpej Exp $ */ @@ -515,44 +515,22 @@ void syscall(struct proc *p, struct trapframe *tf) { caddr_t params; - const struct sysent *callp; - int error, opc, indirect = -1; - int argoff, argsize; + const struct sysent *callp = sysent; + int error, opc; + int argsize; register_t code, args[8], rval[2]; uvmexp.syscalls++; opc = tf->tf_spc; - code = tf->tf_r0; - params = (caddr_t)tf->tf_r15; - switch (code) { - case SYS_syscall: - /* - * Code is first argument, followed by actual args. - */ - indirect = code; - code = tf->tf_r4; - argoff = 1; - break; - default: - argoff = 0; - break; - } - - callp = sysent; - if (code < 0 || code >= SYS_MAXSYSCALL) - callp += SYS_syscall; - else + code = tf->tf_r0; + // XXX out of range stays on syscall0, which we assume is enosys + if (code >= 0 || code <= SYS_MAXSYSCALL) callp += code; + argsize = callp->sy_argsize; -#ifdef DIAGNOSTIC - if (argsize > sizeof args) { - callp += SYS_syscall - code; - argsize = callp->sy_argsize; - } -#endif if (argsize) { register_t *ap; @@ -570,20 +548,18 @@ syscall(struct proc *p, struct trapframe *tf) } ap = args; - switch (argoff) { - case 0: *ap++ = tf->tf_r4; argsize -= sizeof(int); - case 1: *ap++ = tf->tf_r5; argsize -= sizeof(int); - case 2: *ap++ = tf->tf_r6; argsize -= sizeof(int); - /* - * off_t args aren't split between register - * and stack, but rather r7 is skipped and - * the entire off_t is on the stack. - */ - if (argoff + off_t_arg == 3) - break; - *ap++ = tf->tf_r7; argsize -= sizeof(int); + + *ap++ = tf->tf_r4; argsize -= sizeof(int); + *ap++ = tf->tf_r5; argsize -= sizeof(int); + *ap++ = tf->tf_r6; argsize -= sizeof(int); + /* + * off_t args aren't split between register + * and stack, but rather r7 is skipped and + * the entire off_t is on the stack. + */ + if (off_t_arg == 3) break; - } + *ap++ = tf->tf_r7; argsize -= sizeof(int); if (argsize > 0) { if ((error = copyin(params, ap, argsize))) @@ -594,7 +570,7 @@ syscall(struct proc *p, struct trapframe *tf) rval[0] = 0; rval[1] = tf->tf_r1; - error = mi_syscall(p, code, indirect, callp, args, rval); + error = mi_syscall(p, code, callp, args, rval); switch (error) { case 0: diff --git a/sys/arch/sparc64/sparc64/trap.c b/sys/arch/sparc64/sparc64/trap.c index 09723a695ee..7dbf244a2c3 100644 --- a/sys/arch/sparc64/sparc64/trap.c +++ b/sys/arch/sparc64/sparc64/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.115 2023/02/11 23:07:28 deraadt Exp $ */ +/* $OpenBSD: trap.c,v 1.116 2023/12/12 15:30:56 deraadt Exp $ */ /* $NetBSD: trap.c,v 1.73 2001/08/09 01:03:01 eeh Exp $ */ /* @@ -1109,9 +1109,10 @@ syscall(struct trapframe *tf, register_t code, register_t pc) int64_t *ap; const struct sysent *callp; struct proc *p = curproc; - int error, new, indirect = -1; + int error = ENOSYS, new, indirect = -1; register_t args[8]; register_t rval[2]; + register_t *argp; if ((tf->tf_out[6] & 1) == 0) sigexit(p, SIGILL); @@ -1137,39 +1138,26 @@ syscall(struct trapframe *tf, register_t code, register_t pc) ap = &tf->tf_out[0]; nap = 6; - switch (code) { - case SYS_syscall: - indirect = code; - code = *ap++; - nap--; - break; - } - - callp = sysent; if (code < 0 || code >= SYS_MAXSYSCALL) - callp += SYS_syscall; - else { - register_t *argp; - - callp += code; - i = callp->sy_narg; /* Why divide? */ - if (i > nap) { /* usually false */ - if (i > 8) - panic("syscall nargs"); - /* Read the whole block in */ - if ((error = copyin((caddr_t)tf->tf_out[6] - + BIAS + offsetof(struct frame, fr_argx), - &args[nap], (i - nap) * sizeof(register_t)))) - goto bad; - i = nap; - } - /* - * It should be faster to do <= 6 longword copies than - * to call bcopy - */ - for (argp = args; i--;) - *argp++ = *ap++; + goto bad; + callp = sysent + code; + i = callp->sy_narg; /* Why divide? */ + if (i > nap) { /* usually false */ + if (i > 8) + panic("syscall nargs"); + /* Read the whole block in */ + if ((error = copyin((caddr_t)tf->tf_out[6] + + BIAS + offsetof(struct frame, fr_argx), + &args[nap], (i - nap) * sizeof(register_t)))) + goto bad; + i = nap; } + /* + * It should be faster to do <= 6 longword copies than + * to call bcopy + */ + for (argp = args; i--;) + *argp++ = *ap++; rval[0] = 0; rval[1] = 0; diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index 528547a8ab3..9d88075f44a 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_ktrace.c,v 1.112 2023/05/11 09:51:33 bluhm Exp $ */ +/* $OpenBSD: kern_ktrace.c,v 1.113 2023/12/12 15:30:55 deraadt Exp $ */ /* $NetBSD: kern_ktrace.c,v 1.23 1996/02/09 18:59:36 christos Exp $ */ /* @@ -160,7 +160,7 @@ ktrsyscall(struct proc *p, register_t code, size_t argsize, register_t args[]) u_int nargs = 0; int i; - if ((code & KTRC_CODE_MASK) == SYS_sysctl) { + if (code == SYS_sysctl) { /* * The sysctl encoding stores the mib[] * array because it is interesting. diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index ac0b924b8ae..31c051c94ac 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -1,4 +1,4 @@ -; $OpenBSD: syscalls.master,v 1.253 2023/12/10 16:59:09 deraadt Exp $ +; $OpenBSD: syscalls.master,v 1.254 2023/12/12 15:30:55 deraadt Exp $ ; $NetBSD: syscalls.master,v 1.32 1996/04/23 10:24:21 mycroft Exp $ ; @(#)syscalls.master 8.2 (Berkeley) 1/13/94 @@ -48,7 +48,7 @@ ; redistributions should be placed in the reserved range at the end ; of the current calls. -0 INDIR { int sys_syscall(int number, ...); } +0 UNIMPL syscall 1 STD { void sys_exit(int rval); } 2 STD { int sys_fork(void); } 3 STD NOLOCK { ssize_t sys_read(int fd, void *buf, size_t nbyte); } diff --git a/sys/sys/ktrace.h b/sys/sys/ktrace.h index e76652efada..19eb541edd7 100644 --- a/sys/sys/ktrace.h +++ b/sys/sys/ktrace.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ktrace.h,v 1.46 2023/02/23 01:33:20 deraadt Exp $ */ +/* $OpenBSD: ktrace.h,v 1.47 2023/12/12 15:30:55 deraadt Exp $ */ /* $NetBSD: ktrace.h,v 1.12 1996/02/04 02:12:29 christos Exp $ */ /* @@ -76,8 +76,6 @@ struct ktr_header { #define KTR_SYSCALL 1 struct ktr_syscall { int ktr_code; /* syscall number */ -#define KTRC_CODE_MASK 0x0000ffff -#define KTRC_CODE_SYSCALL 0x20000000 int ktr_argsize; /* size of arguments */ /* * followed by ktr_argsize/sizeof(register_t) "register_t"s diff --git a/sys/sys/syscall_mi.h b/sys/sys/syscall_mi.h index 7f88ce78ef9..4063790f8d6 100644 --- a/sys/sys/syscall_mi.h +++ b/sys/sys/syscall_mi.h @@ -1,4 +1,4 @@ -/* $OpenBSD: syscall_mi.h,v 1.28 2023/02/11 23:07:23 deraadt Exp $ */ +/* $OpenBSD: syscall_mi.h,v 1.29 2023/12/12 15:30:55 deraadt Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -51,8 +51,8 @@ * The MD setup for a system call has been done; here's the MI part. */ static inline int -mi_syscall(struct proc *p, register_t code, int indirect, - const struct sysent *callp, register_t *argp, register_t retval[2]) +mi_syscall(struct proc *p, register_t code, const struct sysent *callp, + register_t *argp, register_t retval[2]) { uint64_t tval; int lock = !(callp->sy_flags & SY_NOLOCK); @@ -73,15 +73,8 @@ mi_syscall(struct proc *p, register_t code, int indirect, #ifdef KTRACE if (KTRPOINT(p, KTR_SYSCALL)) { /* convert to mask, then include with code */ - switch (indirect) { - case SYS_syscall: - indirect = KTRC_CODE_SYSCALL; - break; - default: - indirect = 0; - } KERNEL_LOCK(); - ktrsyscall(p, code | indirect, callp->sy_argsize, argp); + ktrsyscall(p, code, callp->sy_argsize, argp); KERNEL_UNLOCK(); } #endif |