Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Fix several panics that can be caused by applicatio...



details:   https://anonhg.NetBSD.org/src/rev/c85cee1c4e70
branches:  trunk
changeset: 756958:c85cee1c4e70
user:      chs <chs%NetBSD.org@localhost>
date:      Sun Aug 08 18:13:54 2010 +0000

description:
Fix several panics that can be caused by applications using
bad segment register values with setcontext() or sigreturn().

diffstat:

 sys/arch/amd64/amd64/netbsd32_machdep.c |  10 ++++++----
 sys/arch/i386/i386/trap.c               |   7 ++++---
 2 files changed, 10 insertions(+), 7 deletions(-)

diffs (73 lines):

diff -r 945cbe18cb74 -r c85cee1c4e70 sys/arch/amd64/amd64/netbsd32_machdep.c
--- a/sys/arch/amd64/amd64/netbsd32_machdep.c   Sun Aug 08 18:10:34 2010 +0000
+++ b/sys/arch/amd64/amd64/netbsd32_machdep.c   Sun Aug 08 18:13:54 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_machdep.c,v 1.64 2010/07/07 01:14:52 chs Exp $        */
+/*     $NetBSD: netbsd32_machdep.c,v 1.65 2010/08/08 18:13:54 chs Exp $        */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.64 2010/07/07 01:14:52 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.65 2010/08/08 18:13:54 chs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -961,7 +961,8 @@
        tf = l->l_md.md_regs;
        pcb = lwp_getpcb(curlwp);
 
-       if (((scp->sc_eflags ^ tf->tf_rflags) & PSL_USERSTATIC) != 0)
+       if (((scp->sc_eflags ^ tf->tf_rflags) & PSL_USERSTATIC) != 0 ||
+           scp->sc_cs != GSEL(GUCODE32_SEL, SEL_UPL))
                return EINVAL;
        if (scp->sc_fs != 0 && !VALID_USER_DSEL32(scp->sc_fs) &&
            !(scp->sc_fs == GSEL(GUFS_SEL, SEL_UPL) && pcb->pcb_fs != 0))
@@ -989,7 +990,8 @@
        tf = l->l_md.md_regs;
        pcb = lwp_getpcb(l);
 
-       if (((gr[_REG32_EFL] ^ tf->tf_rflags) & PSL_USERSTATIC) != 0)
+       if (((gr[_REG32_EFL] ^ tf->tf_rflags) & PSL_USERSTATIC) != 0 ||
+           gr[_REG32_CS] != GSEL(GUCODE32_SEL, SEL_UPL))
                return EINVAL;
        if (gr[_REG32_FS] != 0 && !VALID_USER_DSEL32(gr[_REG32_FS]) &&
            !(gr[_REG32_FS] == GSEL(GUFS_SEL, SEL_UPL) && pcb->pcb_fs != 0))
diff -r 945cbe18cb74 -r c85cee1c4e70 sys/arch/i386/i386/trap.c
--- a/sys/arch/i386/i386/trap.c Sun Aug 08 18:10:34 2010 +0000
+++ b/sys/arch/i386/i386/trap.c Sun Aug 08 18:13:54 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.258 2010/07/25 19:19:06 christos Exp $      */
+/*     $NetBSD: trap.c,v 1.259 2010/08/08 18:13:54 chs 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.258 2010/07/25 19:19:06 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.259 2010/08/08 18:13:54 chs Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -442,6 +442,7 @@
                 * returning from a trap, syscall, or interrupt.
                 */
 
+kernelfault:
                KSI_INIT_TRAP(&ksi);
                ksi.ksi_signo = SIGSEGV;
                ksi.ksi_code = SEGV_ACCERR;
@@ -759,7 +760,7 @@
                                goto copyfault;
                        printf("uvm_fault(%p, %#lx, %d) -> %#x\n",
                            map, va, ftype, error);
-                       goto we_re_toast;
+                       goto kernelfault;
                }
                if (error == ENOMEM) {
                        ksi.ksi_signo = SIGKILL;



Home | Main Index | Thread Index | Old Index