Source-Changes-HG archive

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

[src/netbsd-7-1]: src/sys/arch Pull up following revision(s) (requested by ma...



details:   https://anonhg.NetBSD.org/src/rev/ed4d0be19d64
branches:  netbsd-7-1
changeset: 800751:ed4d0be19d64
user:      snj <snj%NetBSD.org@localhost>
date:      Thu Jul 20 01:43:10 2017 +0000

description:
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.

diffstat:

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

diffs (183 lines):

diff -r 0c5d02ff03a5 -r ed4d0be19d64 sys/arch/amd64/amd64/locore.S
--- a/sys/arch/amd64/amd64/locore.S     Wed Jul 12 18:52:40 2017 +0000
+++ b/sys/arch/amd64/amd64/locore.S     Thu Jul 20 01:43:10 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.76.8.1 2017/04/26 14:51:58 martin Exp $   */
+/*     $NetBSD: locore.S,v 1.76.8.2 2017/07/20 01:43:10 snj Exp $      */
 
 /*
  * Copyright-o-rama!
@@ -1298,7 +1298,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 0c5d02ff03a5 -r ed4d0be19d64 sys/arch/i386/i386/locore.S
--- a/sys/arch/i386/i386/locore.S       Wed Jul 12 18:52:40 2017 +0000
+++ b/sys/arch/i386/i386/locore.S       Thu Jul 20 01:43:10 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.112 2014/02/20 18:19:10 dsl Exp $ */
+/*     $NetBSD: locore.S,v 1.112.10.1 2017/07/20 01:43:10 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.10.1 2017/07/20 01:43:10 snj Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_ddb.h"
@@ -1144,30 +1144,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 0c5d02ff03a5 -r ed4d0be19d64 sys/arch/i386/i386/machdep.c
--- a/sys/arch/i386/i386/machdep.c      Wed Jul 12 18:52:40 2017 +0000
+++ b/sys/arch/i386/i386/machdep.c      Thu Jul 20 01:43:10 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.752 2014/02/23 22:36:43 dsl Exp $        */
+/*     $NetBSD: machdep.c,v 1.752.12.1 2017/07/20 01:43:10 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.12.1 2017/07/20 01:43:10 snj Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -924,7 +924,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;
@@ -1345,13 +1344,9 @@
 #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 */
diff -r 0c5d02ff03a5 -r ed4d0be19d64 sys/arch/i386/i386/trap.c
--- a/sys/arch/i386/i386/trap.c Wed Jul 12 18:52:40 2017 +0000
+++ b/sys/arch/i386/i386/trap.c Thu Jul 20 01:43:10 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.272.10.1 2017/03/25 16:58:25 snj Exp $      */
+/*     $NetBSD: trap.c,v 1.272.10.2 2017/07/20 01:43:10 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.10.1 2017/03/25 16:58:25 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.272.10.2 2017/07/20 01:43:10 snj Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -78,6 +78,7 @@
 #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 @@
        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 @@
                /* 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 @@
        }
 
        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 */



Home | Main Index | Thread Index | Old Index