Module Name:    src
Committed By:   njoly
Date:           Wed Jan 26 21:44:32 UTC 2011

Modified Files:
        src/sys/arch/amd64/amd64: netbsd32_machdep.c

Log Message:
Do mask the upper 16 bits, when sanity checking fs/gs register values.
Fix my own PR/43842.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/arch/amd64/amd64/netbsd32_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.68 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.69
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.68	Wed Nov 17 18:22:17 2010
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Wed Jan 26 21:44:31 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.68 2010/11/17 18:22:17 dholland Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.69 2011/01/26 21:44:31 njoly Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.68 2010/11/17 18:22:17 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.69 2011/01/26 21:44:31 njoly Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -952,6 +952,12 @@
  * and rely on catching invalid user contexts on exit from the kernel.
  * These functions perform the needed checks.
  */
+
+#define	VALID_FS32(s) \
+    (((s) & 0xffff) == GSEL(GUFS_SEL, SEL_UPL))
+#define	VALID_GS32(s) \
+    (((s) & 0xffff) == GSEL(GUGS_SEL, SEL_UPL))
+
 static int
 check_sigcontext32(struct lwp *l, const struct netbsd32_sigcontext *scp)
 {
@@ -965,10 +971,10 @@
 	    !VALID_USER_CSEL32(scp->sc_cs))
 		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))
+	    !(VALID_FS32(scp->sc_fs) && pcb->pcb_fs != 0))
 		return EINVAL;
 	if (scp->sc_gs != 0 && !VALID_USER_DSEL32(scp->sc_gs) &&
-	    !(scp->sc_gs == GSEL(GUGS_SEL, SEL_UPL) && pcb->pcb_gs != 0))
+	    !(VALID_GS32(scp->sc_gs) && pcb->pcb_gs != 0))
 		return EINVAL;
 	if (scp->sc_es != 0 && !VALID_USER_DSEL32(scp->sc_es))
 		return EINVAL;
@@ -994,10 +1000,10 @@
 	    !VALID_USER_CSEL32(gr[_REG32_CS]))
 		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))
+	    !(VALID_FS32(gr[_REG32_FS]) && pcb->pcb_fs != 0))
 		return EINVAL;
 	if (gr[_REG32_GS] != 0 && !VALID_USER_DSEL32(gr[_REG32_GS]) &&
-	    !(gr[_REG32_GS] == GSEL(GUGS_SEL, SEL_UPL) && pcb->pcb_gs != 0))
+	    !(VALID_GS32(gr[_REG32_GS]) && pcb->pcb_gs != 0))
 		return EINVAL;
 	if (gr[_REG32_ES] != 0 && !VALID_USER_DSEL32(gr[_REG32_ES]))
 		return EINVAL;

Reply via email to