Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 Jan 2002 04:00:45 +1100 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        John Baldwin <jhb@FreeBSD.org>
Cc:        Poul-Henning Kamp <phk@FreeBSD.org>, <cvs-all@FreeBSD.org>, <cvs-committers@FreeBSD.org>
Subject:   RE: cvs commit: src/sys/i386/i386 trap.c
Message-ID:  <20020102035156.M10589-100000@gamplex.bde.org>
In-Reply-To: <XFMail.011231123911.jhb@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 31 Dec 2001, John Baldwin wrote:

> On 30-Dec-01 Poul-Henning Kamp wrote:
> > phk         2001/12/30 11:43:59 PST
> >
> >   Modified files:
> >     sys/i386/i386        trap.c
> >   Log:
> >   GC an alternate trap_pfault() which has rotted away behind an "#ifdef
> > notyet"
> >   since 21-Mar-95 .
>
> I thought we wanted to switch to using it as it simplifies some of the kernel
> fault handling but just had a few unsafe places in the kernel to fix?

I added the check for disallowing pagefaults for user addresses in kernel
mode except ones for copying functions.   It is just the

    (!usermode && PCPU_GET(curpcb)->pcb_onfault == NULL)

part of the patch (the other changes are mostly to optimize some copying
functions).  I haven't merged any of the simplifications from the old
version.

%%%
Index: trap.c
===================================================================
RCS file: /home/ncvs/src/sys/i386/i386/trap.c,v
retrieving revision 1.210
diff -u -2 -r1.210 trap.c
--- trap.c	30 Dec 2001 19:43:59 -0000	1.210
+++ trap.c	1 Jan 2002 16:39:50 -0000
@@ -688,10 +719,21 @@
 		/*
 		 * This is a fault on non-kernel virtual memory.
-		 * vm is initialized above to NULL. If curproc is NULL
-		 * or curproc->p_vmspace is NULL the fault is fatal.
+		 * Do not allow it in kernel mode unless it is for a
+		 * a recognized copying function.
 		 */
-		if (p != NULL)
-			vm = p->p_vmspace;
+		if (!usermode &&
+		    frame->tf_eip != (int)fubyte_access &&
+		    frame->tf_eip != (int)fusword_access &&
+		    frame->tf_eip != (int)fuword_access &&
+		    frame->tf_eip != (int)subyte_access &&
+		    frame->tf_eip != (int)susword_access &&
+		    frame->tf_eip != (int)suword_access &&
+		    PCPU_GET(curpcb)->pcb_onfault == NULL)
+			goto nogo;

+		/*
+		 * If curproc->p_vmspace is NULL the fault is fatal.
+		 */
+		vm = p->p_vmspace;
 		if (vm == NULL)
 			goto nogo;

%%%

This is completely untested (except for removing the p != NULL check).

Bruce


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




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