Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Remove the osyscall call gate on i386, and emulate ...



details:   https://anonhg.NetBSD.org/src/rev/40e323728803
branches:  trunk
changeset: 825141:40e323728803
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Jul 01 10:44:42 2017 +0000

description:
Remove the osyscall call gate on i386, and emulate it. There is a one-
instruction race in it that could panic the kernel.

diffstat:

 sys/arch/amd64/amd64/locore.S |   3 +--
 sys/arch/i386/i386/locore.S   |  22 ++--------------------
 sys/arch/i386/i386/machdep.c  |  10 ++--------
 sys/arch/i386/i386/trap.c     |  35 ++++++++++++++++++++++++-----------
 4 files changed, 29 insertions(+), 41 deletions(-)

diffs (185 lines):

diff -r affc49eeb92b -r 40e323728803 sys/arch/amd64/amd64/locore.S
--- a/sys/arch/amd64/amd64/locore.S     Sat Jul 01 09:26:51 2017 +0000
+++ b/sys/arch/amd64/amd64/locore.S     Sat Jul 01 10:44:42 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.123 2017/03/25 15:07:21 maxv Exp $        */
+/*     $NetBSD: locore.S,v 1.124 2017/07/01 10:44:42 maxv Exp $        */
 
 /*
  * Copyright-o-rama!
@@ -1409,7 +1409,6 @@
        addq $0x10,%rsp
 #endif
        pushq   $2              /* size of instruction for restart */
-osyscall1:
        pushq   $T_ASTFLT       /* trap # for doing ASTs */
        INTRENTRY
        STI(si)
diff -r affc49eeb92b -r 40e323728803 sys/arch/i386/i386/locore.S
--- a/sys/arch/i386/i386/locore.S       Sat Jul 01 09:26:51 2017 +0000
+++ b/sys/arch/i386/i386/locore.S       Sat Jul 01 10:44:42 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.145 2017/02/02 19:12:09 maxv Exp $        */
+/*     $NetBSD: locore.S,v 1.146 2017/07/01 10:44:42 maxv Exp $        */
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.145 2017/02/02 19:12:09 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.146 2017/07/01 10:44:42 maxv Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -1239,30 +1239,12 @@
 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)
diff -r affc49eeb92b -r 40e323728803 sys/arch/i386/i386/machdep.c
--- a/sys/arch/i386/i386/machdep.c      Sat Jul 01 09:26:51 2017 +0000
+++ b/sys/arch/i386/i386/machdep.c      Sat Jul 01 10:44:42 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.782 2017/03/24 17:09:36 maxv Exp $       */
+/*     $NetBSD: machdep.c,v 1.783 2017/07/01 10:44:42 maxv 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.782 2017/03/24 17:09:36 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.783 2017/07/01 10:44:42 maxv Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -933,7 +933,6 @@
 #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;
@@ -1290,14 +1289,9 @@
 #endif /* XEN */
 
        /* make ldt gates and memory segments */
-       setgate(&ldtstore[LSYS5CALLS_SEL].gd, &IDTVEC(osyscall), 1,
-           SDT_SYS386CGT, SEL_UPL, GSEL(GCODE_SEL, SEL_KPL));
-
        ldtstore[LUCODE_SEL] = gdtstore[GUCODE_SEL];
        ldtstore[LUCODEBIG_SEL] = gdtstore[GUCODEBIG_SEL];
        ldtstore[LUDATA_SEL] = gdtstore[GUDATA_SEL];
-       ldtstore[LSOL26CALLS_SEL] = ldtstore[LBSDICALLS_SEL] =
-           ldtstore[LSYS5CALLS_SEL];
 
 #ifndef XEN
        /* exceptions */
diff -r affc49eeb92b -r 40e323728803 sys/arch/i386/i386/trap.c
--- a/sys/arch/i386/i386/trap.c Sat Jul 01 09:26:51 2017 +0000
+++ b/sys/arch/i386/i386/trap.c Sat Jul 01 10:44:42 2017 +0000
@@ -1,5 +1,5 @@
 
-/*     $NetBSD: trap.c,v 1.287 2017/03/18 13:39:23 maxv Exp $  */
+/*     $NetBSD: trap.c,v 1.288 2017/07/01 10:44:42 maxv Exp $  */
 
 /*-
  * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.287 2017/03/18 13:39:23 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.288 2017/07/01 10:44:42 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -78,6 +78,7 @@
 #include "opt_vm86.h"
 #include "opt_xen.h"
 #include "opt_dtrace.h"
+#include "opt_compat_netbsd.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -250,8 +251,7 @@
        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;
@@ -418,6 +418,26 @@
                /* 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:
@@ -710,13 +730,6 @@
                if (x86_dbregs_user_trap())
                        break;
 
-               /* 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 */



Home | Main Index | Thread Index | Old Index