Module Name: src Committed By: snj Date: Thu Jul 20 01:42:40 UTC 2017
Modified Files: src/sys/arch/amd64/amd64 [netbsd-7-0]: locore.S src/sys/arch/i386/i386 [netbsd-7-0]: locore.S machdep.c trap.c Log Message: Pull up following revision(s) (requested by maxv in ticket #1441): sys/arch/i386/i386/trap.c: revision 1.288 via patch sys/arch/i386/i386/machdep.c: revision 1.783 via patch sys/arch/i386/i386/locore.S: revision 1.146 via patch sys/arch/amd64/amd64/locore.S: revision 1.124 via patch Remove the osyscall call gate on i386, and emulate it. There is a one- instruction race in it that could panic the kernel. To generate a diff of this commit: cvs rdiff -u -r1.76.4.1 -r1.76.4.2 src/sys/arch/amd64/amd64/locore.S cvs rdiff -u -r1.112 -r1.112.6.1 src/sys/arch/i386/i386/locore.S cvs rdiff -u -r1.752 -r1.752.8.1 src/sys/arch/i386/i386/machdep.c cvs rdiff -u -r1.272.6.1 -r1.272.6.2 src/sys/arch/i386/i386/trap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/amd64/amd64/locore.S diff -u src/sys/arch/amd64/amd64/locore.S:1.76.4.1 src/sys/arch/amd64/amd64/locore.S:1.76.4.2 --- src/sys/arch/amd64/amd64/locore.S:1.76.4.1 Wed Apr 26 14:50:51 2017 +++ src/sys/arch/amd64/amd64/locore.S Thu Jul 20 01:42:39 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.76.4.1 2017/04/26 14:50:51 martin Exp $ */ +/* $NetBSD: locore.S,v 1.76.4.2 2017/07/20 01:42:39 snj Exp $ */ /* * Copyright-o-rama! @@ -1298,7 +1298,6 @@ IDTVEC(osyscall) addq $0x10,%rsp #endif pushq $2 # size of instruction for restart -osyscall1: pushq $T_ASTFLT # trap # for doing ASTs INTRENTRY STI(si) Index: src/sys/arch/i386/i386/locore.S diff -u src/sys/arch/i386/i386/locore.S:1.112 src/sys/arch/i386/i386/locore.S:1.112.6.1 --- src/sys/arch/i386/i386/locore.S:1.112 Thu Feb 20 18:19:10 2014 +++ src/sys/arch/i386/i386/locore.S Thu Jul 20 01:42:39 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.112 2014/02/20 18:19:10 dsl Exp $ */ +/* $NetBSD: locore.S,v 1.112.6.1 2017/07/20 01:42:39 snj Exp $ */ /* * Copyright-o-rama! @@ -129,7 +129,7 @@ */ #include <machine/asm.h> -__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.112 2014/02/20 18:19:10 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.112.6.1 2017/07/20 01:42:39 snj Exp $"); #include "opt_compat_oldboot.h" #include "opt_ddb.h" @@ -1144,30 +1144,12 @@ ENTRY(savectx) END(savectx) /* - * osyscall() - * - * Old call gate entry for syscall - */ -IDTVEC(osyscall) -#ifndef XEN - /* XXX we are in trouble! interrupts be off here. */ - cli # must be first instruction -#endif - pushfl # set eflags in trap frame - popl 8(%esp) - orl $PSL_I,8(%esp) # re-enable ints on return to user - pushl $7 # size of instruction for restart - jmp syscall1 -IDTVEC_END(osyscall) - -/* * syscall() * * Trap gate entry for syscall */ IDTVEC(syscall) pushl $2 # size of instruction for restart -syscall1: pushl $T_ASTFLT # trap # for doing ASTs INTRENTRY STI(%eax) Index: src/sys/arch/i386/i386/machdep.c diff -u src/sys/arch/i386/i386/machdep.c:1.752 src/sys/arch/i386/i386/machdep.c:1.752.8.1 --- src/sys/arch/i386/i386/machdep.c:1.752 Sun Feb 23 22:36:43 2014 +++ src/sys/arch/i386/i386/machdep.c Thu Jul 20 01:42:39 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.752 2014/02/23 22:36:43 dsl Exp $ */ +/* $NetBSD: machdep.c,v 1.752.8.1 2017/07/20 01:42:39 snj Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009 @@ -67,7 +67,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.752 2014/02/23 22:36:43 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.752.8.1 2017/07/20 01:42:39 snj Exp $"); #include "opt_beep.h" #include "opt_compat_ibcs2.h" @@ -924,7 +924,6 @@ setsegment(struct segment_descriptor *sd #define IDTVEC(name) __CONCAT(X, name) typedef void (vector)(void); extern vector IDTVEC(syscall); -extern vector IDTVEC(osyscall); extern vector *IDTVEC(exceptions)[]; extern vector IDTVEC(svr4_fasttrap); void (*svr4_fasttrap_vec)(void) = (void (*)(void))nullop; @@ -1345,13 +1344,9 @@ init386(paddr_t first_avail) #endif /* XEN */ /* make ldt gates and memory segments */ - setgate(&ldt[LSYS5CALLS_SEL].gd, &IDTVEC(osyscall), 1, - SDT_SYS386CGT, SEL_UPL, GSEL(GCODE_SEL, SEL_KPL)); - ldt[LUCODE_SEL] = gdt[GUCODE_SEL]; ldt[LUCODEBIG_SEL] = gdt[GUCODEBIG_SEL]; ldt[LUDATA_SEL] = gdt[GUDATA_SEL]; - ldt[LSOL26CALLS_SEL] = ldt[LBSDICALLS_SEL] = ldt[LSYS5CALLS_SEL]; #ifndef XEN /* exceptions */ Index: src/sys/arch/i386/i386/trap.c diff -u src/sys/arch/i386/i386/trap.c:1.272.6.1 src/sys/arch/i386/i386/trap.c:1.272.6.2 --- src/sys/arch/i386/i386/trap.c:1.272.6.1 Sat Mar 25 16:59:01 2017 +++ src/sys/arch/i386/i386/trap.c Thu Jul 20 01:42:39 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.272.6.1 2017/03/25 16:59:01 snj Exp $ */ +/* $NetBSD: trap.c,v 1.272.6.2 2017/07/20 01:42:39 snj Exp $ */ /*- * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.272.6.1 2017/03/25 16:59:01 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.272.6.2 2017/07/20 01:42:39 snj Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -78,6 +78,7 @@ __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.2 #include "opt_kstack_dr0.h" #include "opt_xen.h" #include "opt_dtrace.h" +#include "opt_compat_netbsd.h" #include <sys/param.h> #include <sys/systm.h> @@ -265,8 +266,7 @@ trap(struct trapframe *frame) struct lwp *l = curlwp; struct proc *p; struct pcb *pcb; - extern char fusubail[], kcopy_fault[], return_address_fault[], - IDTVEC(osyscall)[]; + extern char fusubail[], kcopy_fault[], return_address_fault[]; struct trapframe *vframe; ksiginfo_t ksi; void *onfault; @@ -439,6 +439,26 @@ kernelfault: /* NOTREACHED */ case T_PROTFLT|T_USER: /* protection fault */ +#if defined(COMPAT_10) + { + static const char lcall[7] = { 0x9a, 0, 0, 0, 0, 7, 0 }; + const size_t sz = sizeof(lcall); + char tmp[sz]; + + /* Check for the osyscall lcall instruction. */ + if (frame->tf_eip < VM_MAXUSER_ADDRESS - sz && + copyin((void *)frame->tf_eip, tmp, sz) == 0 && + memcmp(tmp, lcall, sz) == 0) { + + /* Advance past the lcall. */ + frame->tf_eip += sz; + + /* Do the syscall. */ + p->p_md.md_syscall(frame); + goto out; + } + } +#endif case T_TSSFLT|T_USER: case T_SEGNPFLT|T_USER: case T_STKFLT|T_USER: @@ -686,13 +706,6 @@ faultcommon: } case T_TRCTRAP: - /* Check whether they single-stepped into a lcall. */ - if (frame->tf_eip == (int)IDTVEC(osyscall)) - return; - if (frame->tf_eip == (int)IDTVEC(osyscall) + 1) { - frame->tf_eflags &= ~PSL_T; - return; - } goto we_re_toast; case T_BPTFLT|T_USER: /* bpt instruction fault */