Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Torn down KSTACK_CHECK_DR0, i386-only feature to de...



details:   https://anonhg.NetBSD.org/src/rev/63892b0f993e
branches:  trunk
changeset: 349518:63892b0f993e
user:      kamil <kamil%NetBSD.org@localhost>
date:      Tue Dec 13 10:54:27 2016 +0000

description:
Torn down KSTACK_CHECK_DR0, i386-only feature to detect stack overflow

This feature was intended to detect stack overflow with CPU Debug Registers
(x86). It was never ported to other ports, neither amd64 and should be
adapted for SMP...

Currently there might be better ways to detect stack overflows like page
mapping protection. Since the number of Debug Registers is restricted
(4 on x86), torn it down completely.

This interface introduced helper functions for Debug Registers, they will
be replaced with the new <x86/dbregs.h> interface.

KSTACK_CHECK_DR0 was disabled by default and won't affect ordinary users.

Sponsored by <The NetBSD Foundation>

diffstat:

 sys/arch/i386/conf/files.i386  |    6 +-
 sys/arch/i386/i386/db_dbgreg.S |  129 -----------------------------------------
 sys/arch/i386/i386/trap.c      |   27 +-------
 sys/arch/x86/include/cpufunc.h |    3 +-
 sys/arch/x86/x86/pmap.c        |   16 +----
 sys/arch/xen/conf/files.compat |    5 +-
 sys/arch/xen/conf/files.xen    |    3 +-
 sys/arch/xen/x86/xen_pmap.c    |    7 +-
 8 files changed, 11 insertions(+), 185 deletions(-)

diffs (truncated from 342 to 300 lines):

diff -r 170a46e9eae5 -r 63892b0f993e sys/arch/i386/conf/files.i386
--- a/sys/arch/i386/conf/files.i386     Tue Dec 13 10:21:33 2016 +0000
+++ b/sys/arch/i386/conf/files.i386     Tue Dec 13 10:54:27 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.i386,v 1.374 2014/02/12 23:24:09 dsl Exp $
+#      $NetBSD: files.i386,v 1.375 2016/12/13 10:54:27 kamil Exp $
 #
 # new style config file for i386 architecture
 #
@@ -41,9 +41,6 @@
                        PCIBIOS_INTR_GUESS PCIINTR_DEBUG
 defparam opt_pcibios.h PCIBIOS_IRQS_HINT
 
-# kernel stack debug
-defflag        opt_kstack_dr0.h                KSTACK_CHECK_DR0
-
 # splraise()/spllower() debug
 defflag        opt_spldebug.h                  SPLDEBUG
 
@@ -63,7 +60,6 @@
 file   arch/i386/i386/busfunc.S
 file   arch/i386/i386/cpufunc.S
 file   arch/i386/i386/cpu_in_cksum.S   (inet | inet6) & cpu_in_cksum
-file   arch/i386/i386/db_dbgreg.S      ddb | kstack_check_dr0
 file   arch/i386/i386/db_disasm.c      ddb
 file   arch/i386/i386/db_interface.c   ddb
 file   arch/i386/i386/db_machdep.c     ddb
diff -r 170a46e9eae5 -r 63892b0f993e sys/arch/i386/i386/db_dbgreg.S
--- a/sys/arch/i386/i386/db_dbgreg.S    Tue Dec 13 10:21:33 2016 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,129 +0,0 @@
-/*     $NetBSD: db_dbgreg.S,v 1.7 2007/12/11 23:31:07 lukem Exp $      */
-
-/* 
- * Mach Operating System
- * Copyright (c) 1995 Carnegie Mellon University
- * All Rights Reserved.
- * 
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- * 
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
- * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- * 
- * Carnegie Mellon requests users of this software to return to
- * 
- *  Software Distribution Coordinator  or  Software.Distribution%CS.CMU.EDU@localhost
- *  School of Computer Science
- *  Carnegie Mellon University
- *  Pittsburgh PA 15213-3890
- * 
- * any improvements or extensions that they make and grant Carnegie Mellon
- * the rights to redistribute these changes.
- */
-
-/* LINTSTUB: Empty */
-
-#include <i386/include/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: db_dbgreg.S,v 1.7 2007/12/11 23:31:07 lukem Exp $");
-
-#define S_ARG0  4(%esp)
-#define S_ARG1  8(%esp)
-#define S_ARG2 12(%esp)
-#define S_ARG3 16(%esp)
-
-#define B_ARG0  8(%ebp)
-#define B_ARG1 12(%ebp)
-#define B_ARG2 16(%ebp)
-#define B_ARG3 20(%ebp)
-
-ENTRY(dr6)
-       movl    %db6, %eax
-       ret
-
-/*     dr<i>(address, type, len, persistence)
- *     type:
- *        00   execution (use len 00)
- *        01   data write
- *        11   data read/write
- *     len:
- *        00   one byte
- *        01   two bytes
- *        11   four bytes
- */
-ENTRY(dr0)
-       movl    S_ARG0, %eax
-       movl    %eax,_C_LABEL(dr_addr)
-       movl    %eax, %db0
-       movl    $0, %ecx
-       jmp     0f
-ENTRY(dr1)
-       movl    S_ARG0, %eax
-       movl    %eax,_C_LABEL(dr_addr)+1*4
-       movl    %eax, %db1
-       movl    $2, %ecx
-       jmp     0f
-ENTRY(dr2)
-       movl    S_ARG0, %eax
-       movl    %eax,_C_LABEL(dr_addr)+2*4
-       movl    %eax, %db2
-       movl    $4, %ecx
-       jmp     0f
-
-ENTRY(dr3)
-       movl    S_ARG0, %eax
-       movl    %eax,_C_LABEL(dr_addr)+3*4
-       movl    %eax, %db3
-       movl    $6, %ecx
-
-0:
-       pushl   %ebp
-       movl    %esp, %ebp
-
-       movl    %db7, %edx
-       movl    %edx,_C_LABEL(dr_addr)+4*4
-       andl    dr_msk(,%ecx,2),%edx    /* clear out new entry */
-       movl    %edx,_C_LABEL(dr_addr)+5*4
-       movzbl  B_ARG3, %eax
-       andb    $3, %al
-       shll    %cl, %eax
-       orl     %eax, %edx
-
-       shll    $1, %ecx
-
-       movzbl  B_ARG1, %eax
-       andb    $3, %al
-       addb    $0x10, %cl
-       shll    %cl, %eax
-       orl     %eax, %edx
-
-       movzbl  B_ARG2, %eax
-       andb    $3, %al
-       addb    $0x2, %cl
-       shll    %cl, %eax
-       orl     %eax, %edx
-
-       movl    %edx, %db7
-       movl    %edx,_C_LABEL(dr_addr)+7*4
-       movl    %edx, %eax
-       leave
-       ret
-
-       .data
-dr_msk:
-       .long   ~0x000f0003
-       .long   ~0x00f0000c
-       .long   ~0x0f000030
-       /* XXX
-        * The following should be ~0xf00000c0 but that confuses gas
-        * when cross-compiling i386 from amd64.
-        */
-       .long   0x0fffff3f
-_C_LABEL(dr_addr):
-       .long   0,0,0,0
-       .long   0,0,0,0
-       .text
diff -r 170a46e9eae5 -r 63892b0f993e sys/arch/i386/i386/trap.c
--- a/sys/arch/i386/i386/trap.c Tue Dec 13 10:21:33 2016 +0000
+++ b/sys/arch/i386/i386/trap.c Tue Dec 13 10:54:27 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.280 2016/09/25 12:53:24 maxv Exp $  */
+/*     $NetBSD: trap.c,v 1.281 2016/12/13 10:54:27 kamil Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -68,14 +68,13 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.280 2016/09/25 12:53:24 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.281 2016/12/13 10:54:27 kamil Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
 #include "opt_lockdebug.h"
 #include "opt_multiprocessor.h"
 #include "opt_vm86.h"
-#include "opt_kstack_dr0.h"
 #include "opt_xen.h"
 #include "opt_dtrace.h"
 
@@ -233,24 +232,6 @@
            l, l->l_proc->p_pid, l->l_lid, KSTACK_LOWEST_ADDR(l));
 }
 
-static void
-check_dr0(void)
-{
-#ifdef KSTACK_CHECK_DR0
-       u_int mask, dr6 = rdr6();
-
-       mask = 1 << 0; /* dr0 */
-       if (dr6 & mask) {
-               panic("trap on DR0: maybe kernel stack overflow\n");
-#if 0
-               dr6 &= ~mask;
-               ldr6(dr6);
-               return;
-#endif
-       }
-#endif
-}
-
 /*
  * trap(frame): exception, fault, and trap interface to BSD kernel.
  *
@@ -323,9 +304,7 @@
 
        default:
        we_re_toast:
-               if (type == T_TRCTRAP)
-                       check_dr0();
-               else
+               if (type != T_TRCTRAP)
                        trap_print(frame, l);
 
                if (kdb_trap(type, 0, frame))
diff -r 170a46e9eae5 -r 63892b0f993e sys/arch/x86/include/cpufunc.h
--- a/sys/arch/x86/include/cpufunc.h    Tue Dec 13 10:21:33 2016 +0000
+++ b/sys/arch/x86/include/cpufunc.h    Tue Dec 13 10:54:27 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpufunc.h,v 1.21 2016/12/13 10:21:33 kamil Exp $       */
+/*     $NetBSD: cpufunc.h,v 1.22 2016/12/13 10:54:27 kamil Exp $       */
 
 /*-
  * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc.
@@ -68,7 +68,6 @@
 vaddr_t        rcr8(void);
 void   tlbflush(void);
 void   tlbflushg(void);
-void   dr0(void *, uint32_t, uint32_t, uint32_t);
 register_t     rdr0(void);
 void           ldr0(register_t);
 register_t     rdr1(void);
diff -r 170a46e9eae5 -r 63892b0f993e sys/arch/x86/x86/pmap.c
--- a/sys/arch/x86/x86/pmap.c   Tue Dec 13 10:21:33 2016 +0000
+++ b/sys/arch/x86/x86/pmap.c   Tue Dec 13 10:54:27 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.c,v 1.230 2016/12/11 08:31:53 maxv Exp $  */
+/*     $NetBSD: pmap.c,v 1.231 2016/12/13 10:54:27 kamil Exp $ */
 
 /*-
  * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc.
@@ -171,15 +171,12 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.230 2016/12/11 08:31:53 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.231 2016/12/13 10:54:27 kamil Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
-#if !defined(__x86_64__)
-#include "opt_kstack_dr0.h"
-#endif /* !defined(__x86_64__) */
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -2627,15 +2624,6 @@
        if (l == ci->ci_curlwp) {
                KASSERT(ci->ci_want_pmapload == 0);
                KASSERT(ci->ci_tlbstate != TLBSTATE_VALID);
-#ifdef KSTACK_CHECK_DR0
-               /*
-                * setup breakpoint on the top of stack
-                */
-               if (l == &lwp0)
-                       dr0(0, 0, 0, 0);
-               else
-                       dr0(KSTACK_LOWEST_ADDR(l), 1, 3, 1);
-#endif
 
                /*
                 * no need to switch to kernel vmspace because
diff -r 170a46e9eae5 -r 63892b0f993e sys/arch/xen/conf/files.compat
--- a/sys/arch/xen/conf/files.compat    Tue Dec 13 10:21:33 2016 +0000
+++ b/sys/arch/xen/conf/files.compat    Tue Dec 13 10:54:27 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.compat,v 1.24 2012/10/03 18:58:32 dsl Exp $
+#      $NetBSD: files.compat,v 1.25 2016/12/13 10:54:27 kamil Exp $
 #      NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 
 # options for MP configuration through the MP spec
@@ -43,9 +43,6 @@
 # Large page size
 defflag        opt_largepages.h                XXXLARGEPAGES
 
-# kernel stack debug
-defflag        opt_kstack_dr0.h                XXXKSTACK_CHECK_DR0
-
 #Pentium 4+ Thermal Monitor ODCM (aka On Demand Clock Modulation)
 defflag opt_intel_odcm.h       XXXINTEL_ONDEMAND_CLOCKMOD
 
diff -r 170a46e9eae5 -r 63892b0f993e sys/arch/xen/conf/files.xen



Home | Main Index | Thread Index | Old Index