Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Oct 2011 17:01:31 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r225943 - in head/sys: amd64/amd64 i386/i386
Message-ID:  <201110031701.p93H1VXn019826@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Mon Oct  3 17:01:31 2011
New Revision: 225943
URL: http://svn.freebsd.org/changeset/base/225943

Log:
  Do not allow the kernel to access usermode pages without installed
  fault handler. Panic immediately in such situation, on i386 and amd64.
  
  Reviewed by:	avg, jhb
  MFC after:	1 week

Modified:
  head/sys/amd64/amd64/trap.c
  head/sys/i386/i386/trap.c

Modified: head/sys/amd64/amd64/trap.c
==============================================================================
--- head/sys/amd64/amd64/trap.c	Mon Oct  3 16:58:58 2011	(r225942)
+++ head/sys/amd64/amd64/trap.c	Mon Oct  3 17:01:31 2011	(r225943)
@@ -674,6 +674,19 @@ trap_pfault(frame, usermode)
 			goto nogo;
 
 		map = &vm->vm_map;
+
+		/*
+		 * When accessing a usermode address, kernel must be
+		 * ready to accept the page fault, and provide a
+		 * handling routine.  Since accessing the address
+		 * without the handler is a bug, do not try to handle
+		 * it normally, and panic immediately.
+		 */
+		if (!usermode && (td->td_intr_nesting_level != 0 ||
+		    PCPU_GET(curpcb)->pcb_onfault == NULL)) {
+			trap_fatal(frame, eva);
+			return (-1);
+		}
 	}
 
 	/*

Modified: head/sys/i386/i386/trap.c
==============================================================================
--- head/sys/i386/i386/trap.c	Mon Oct  3 16:58:58 2011	(r225942)
+++ head/sys/i386/i386/trap.c	Mon Oct  3 17:01:31 2011	(r225943)
@@ -831,6 +831,11 @@ trap_pfault(frame, usermode, eva)
 			goto nogo;
 
 		map = &vm->vm_map;
+		if (!usermode && (td->td_intr_nesting_level != 0 ||
+		    PCPU_GET(curpcb)->pcb_onfault == NULL)) {
+			trap_fatal(frame, eva);
+			return (-1);
+		}
 	}
 
 	/*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201110031701.p93H1VXn019826>