From f40aa5670b9d62771bc9db9c987d6fa85b9174eb Mon Sep 17 00:00:00 2001 From: reinoud Date: Sat, 27 Aug 2011 18:01:37 +0000 Subject: [PATCH] Implement trap recursion detection and fix small one-off error in range checks for kernel space --- sys/arch/usermode/usermode/trap.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sys/arch/usermode/usermode/trap.c b/sys/arch/usermode/usermode/trap.c index 6ed7d2706590..d11200fa4af2 100644 --- a/sys/arch/usermode/usermode/trap.c +++ b/sys/arch/usermode/usermode/trap.c @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.6 2011/08/25 19:06:03 reinoud Exp $ */ +/* $NetBSD: trap.c,v 1.7 2011/08/27 18:01:37 reinoud Exp $ */ /*- * Copyright (c) 2011 Reinoud Zandijk @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.6 2011/08/25 19:06:03 reinoud Exp $"); +__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.7 2011/08/27 18:01:37 reinoud Exp $"); #include #include @@ -83,8 +83,12 @@ mem_access_handler(int sig, siginfo_t *info, void *ctx) vaddr_t va; vaddr_t onfault; int kmem, rv; + static volatile int recurse = 0; + recurse++; aprint_debug("trap\n"); + if (recurse > 1) + printf("enter trap recursion level %d\n", recurse); if ((info->si_signo == SIGSEGV) || (info->si_signo == SIGBUS)) { l = curlwp; p = l->l_proc; @@ -121,7 +125,7 @@ mem_access_handler(int sig, siginfo_t *info, void *ctx) kmem = 1; vm_map = kernel_map; - if ((va >= VM_MIN_ADDRESS) && (va <= VM_MAXUSER_ADDRESS)) { + if ((va >= VM_MIN_ADDRESS) && (va < VM_MAXUSER_ADDRESS)) { kmem = 0; vm_map = &vm->vm_map; } @@ -146,11 +150,14 @@ atype = PROT_READ | PROT_WRITE; memset(tf, 0, sizeof(struct trapframe)); tf->tf_pc = onfault; tf->tf_out[0] = (rv == EACCES) ? EFAULT : rv; + recurse--; return; } panic("should deliver a trap to the process"); } - + if (recurse > 1) + printf("leaving trap recursion level %d\n", recurse); + recurse--; } }