Module Name:    src
Committed By:   snj
Date:           Sat Sep  9 17:29:41 UTC 2017

Modified Files:
        src/sys/arch/amd64/conf [netbsd-8]: ALL
        src/sys/arch/i386/conf [netbsd-8]: ALL
        src/sys/arch/i386/i386 [netbsd-8]: i386_trap.S locore.S
        src/sys/arch/x86/x86 [netbsd-8]: sys_machdep.c

Log Message:
Pull up following revision(s) (requested by maxv in ticket #258):
        sys/arch/amd64/conf/ALL: 1.68
        sys/arch/i386/conf/ALL: 1.428
        sys/arch/i386/i386/i386_trap.S: 1.12
        sys/arch/i386/i386/locore.S: 1.149-1.150
        sys/arch/x86/x86/sys_machdep.c: 1.38
Remove undocumented hack.
--
Switch to the temporary stack right away when booted via multiboot. GRUB
happens to give a correct stack, but it is not guaranteed by the spec. This
temporary stack will be reset later, which is fine.
Fixes PR/50245.
--
Pfff, use %ss and not %ds. The latter is controlled by userland, the former
contains the kernel value (flat); FreeBSD fixed this too a few weeks ago.
As I said earlier, this dtrace code is complete bullshit.
--
Don't allow userland to create 286/386 call gates anymore - they are not
used by Wine. While here, don't allow it to overwrite the static entries
either, don't allow unknown entry types, remove LDT_DEBUG, and style.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.59.2.1 src/sys/arch/amd64/conf/ALL
cvs rdiff -u -r1.419.2.1 -r1.419.2.2 src/sys/arch/i386/conf/ALL
cvs rdiff -u -r1.6.6.1 -r1.6.6.2 src/sys/arch/i386/i386/i386_trap.S
cvs rdiff -u -r1.145.6.1 -r1.145.6.2 src/sys/arch/i386/i386/locore.S
cvs rdiff -u -r1.35.6.1 -r1.35.6.2 src/sys/arch/x86/x86/sys_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/conf/ALL
diff -u src/sys/arch/amd64/conf/ALL:1.59 src/sys/arch/amd64/conf/ALL:1.59.2.1
--- src/sys/arch/amd64/conf/ALL:1.59	Sat May 27 22:53:29 2017
+++ src/sys/arch/amd64/conf/ALL	Sat Sep  9 17:29:40 2017
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.59 2017/05/27 22:53:29 bouyer Exp $
+# $NetBSD: ALL,v 1.59.2.1 2017/09/09 17:29:40 snj Exp $
 # From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
 #
 # ALL machine description file
@@ -17,7 +17,7 @@ include 	"arch/amd64/conf/std.amd64"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident		"ALL-$Revision: 1.59 $"
+#ident		"ALL-$Revision: 1.59.2.1 $"
 
 maxusers	64		# estimated number of users
 
@@ -2076,7 +2076,6 @@ options KSYMS_DEBUG
 options KUE_DEBUG
 options LANA_DEBUG
 options LCD_DEBUG
-options LDT_DEBUG
 options LEDEBUG
 options LE_DEBUG
 options LIFDEBUG

Index: src/sys/arch/i386/conf/ALL
diff -u src/sys/arch/i386/conf/ALL:1.419.2.1 src/sys/arch/i386/conf/ALL:1.419.2.2
--- src/sys/arch/i386/conf/ALL:1.419.2.1	Thu Aug 31 08:41:33 2017
+++ src/sys/arch/i386/conf/ALL	Sat Sep  9 17:29:40 2017
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.419.2.1 2017/08/31 08:41:33 bouyer Exp $
+# $NetBSD: ALL,v 1.419.2.2 2017/09/09 17:29:40 snj Exp $
 # From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
 #
 # ALL machine description file
@@ -17,7 +17,7 @@ include 	"arch/i386/conf/std.i386"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident		"ALL-$Revision: 1.419.2.1 $"
+#ident		"ALL-$Revision: 1.419.2.2 $"
 
 maxusers	64		# estimated number of users
 
@@ -2230,7 +2230,6 @@ options KSYMS_DEBUG
 options KUE_DEBUG
 options LANA_DEBUG
 options LCD_DEBUG
-options LDT_DEBUG
 options LEDEBUG
 options LE_DEBUG
 options LIFDEBUG

Index: src/sys/arch/i386/i386/i386_trap.S
diff -u src/sys/arch/i386/i386/i386_trap.S:1.6.6.1 src/sys/arch/i386/i386/i386_trap.S:1.6.6.2
--- src/sys/arch/i386/i386/i386_trap.S:1.6.6.1	Tue Aug  1 23:18:30 2017
+++ src/sys/arch/i386/i386/i386_trap.S	Sat Sep  9 17:29:40 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: i386_trap.S,v 1.6.6.1 2017/08/01 23:18:30 snj Exp $	*/
+/*	$NetBSD: i386_trap.S,v 1.6.6.2 2017/09/09 17:29:40 snj Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -66,7 +66,7 @@
 
 #if 0
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.6.6.1 2017/08/01 23:18:30 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.6.6.2 2017/09/09 17:29:40 snj Exp $");
 #endif
 
 /*
@@ -139,7 +139,7 @@ IDTVEC_END(trap05)
 	SUPERALIGN_TEXT
 IDTVEC(trap06)
 	/* Check if there is no DTrace hook registered. */
-	cmpl	$0,dtrace_invop_jump_addr
+	cmpl	$0,%ss:dtrace_invop_jump_addr
 	je	norm_ill
 
 	/* Check if this is a user fault. */

Index: src/sys/arch/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.145.6.1 src/sys/arch/i386/i386/locore.S:1.145.6.2
--- src/sys/arch/i386/i386/locore.S:1.145.6.1	Wed Jul  5 19:59:29 2017
+++ src/sys/arch/i386/i386/locore.S	Sat Sep  9 17:29:40 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.145.6.1 2017/07/05 19:59:29 snj Exp $	*/
+/*	$NetBSD: locore.S,v 1.145.6.2 2017/09/09 17:29:40 snj Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.145.6.1 2017/07/05 19:59:29 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.145.6.2 2017/09/09 17:29:40 snj Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -343,11 +343,13 @@ _C_LABEL(Multiboot_Header):
 	jne	1f
 
 	/*
-	 * Indeed, a multiboot-compliant boot loader executed us.  We copy
-	 * the received Multiboot information structure into kernel's data
-	 * space to process it later -- after we are relocated.  It will
-	 * be safer to run complex C code than doing it at this point.
+	 * Indeed, a multiboot-compliant boot loader executed us. We switch
+	 * to the temporary stack, and copy the received Multiboot information
+	 * structure into kernel's data space to process it later -- after we
+	 * are relocated. It will be safer to run complex C code than doing it
+	 * at this point.
 	 */
+	movl	$_RELOC(tmpstk),%esp
 	pushl	%ebx		/* Address of Multiboot information */
 	call	_C_LABEL(multiboot_pre_reloc)
 	addl	$4,%esp
@@ -842,24 +844,6 @@ begin:
 	addl	$PDE_SIZE,%esp		/* pop paddr_t */
 	addl	$NGDT*8,%esp		/* pop temporary gdt */
 
-#ifdef SAFARI_FIFO_HACK
-	movb	$5,%al
-	movw	$0x37b,%dx
-	outb	%al,%dx
-	movw	$0x37f,%dx
-	inb	%dx,%al
-	movb	%al,%cl
-
-	orb	$1,%cl
-
-	movb	$5,%al
-	movw	$0x37b,%dx
-	outb	%al,%dx
-	movw	$0x37f,%dx
-	movb	%cl,%al
-	outb	%al,%dx
-#endif /* SAFARI_FIFO_HACK */
-
 	call 	_C_LABEL(main)
 #else /* XEN */
 	/* First, reset the PSL. */

Index: src/sys/arch/x86/x86/sys_machdep.c
diff -u src/sys/arch/x86/x86/sys_machdep.c:1.35.6.1 src/sys/arch/x86/x86/sys_machdep.c:1.35.6.2
--- src/sys/arch/x86/x86/sys_machdep.c:1.35.6.1	Tue Aug  1 23:18:30 2017
+++ src/sys/arch/x86/x86/sys_machdep.c	Sat Sep  9 17:29:41 2017
@@ -1,11 +1,11 @@
-/*	$NetBSD: sys_machdep.c,v 1.35.6.1 2017/08/01 23:18:30 snj Exp $	*/
+/*	$NetBSD: sys_machdep.c,v 1.35.6.2 2017/09/09 17:29:41 snj Exp $	*/
 
-/*-
- * Copyright (c) 1998, 2007, 2009 The NetBSD Foundation, Inc.
+/*
+ * Copyright (c) 1998, 2007, 2009, 2017 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
- * by Charles M. Hannum, and by Andrew Doran.
+ * by Charles M. Hannum, by Andrew Doran, and by Maxime Villard.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.35.6.1 2017/08/01 23:18:30 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.35.6.2 2017/09/09 17:29:41 snj Exp $");
 
 #include "opt_mtrr.h"
 #include "opt_pmc.h"
@@ -117,19 +117,6 @@ int x86_set_sdbase(void *, char, lwp_t *
 int x86_get_sdbase32(void *, char);
 int x86_get_sdbase(void *, char);
 
-#if defined(USER_LDT) && defined(LDT_DEBUG)
-static void x86_print_ldt(int, const struct segment_descriptor *);
-
-static void
-x86_print_ldt(int i, const struct segment_descriptor *d)
-{
-	printf("[%d] lolimit=0x%x, lobase=0x%x, type=%u, dpl=%u, p=%u, "
-	    "hilimit=0x%x, xx=%x, def32=%u, gran=%u, hibase=0x%x\n",
-	    i, d->sd_lolimit, d->sd_lobase, d->sd_type, d->sd_dpl, d->sd_p,
-	    d->sd_hilimit, d->sd_xx, d->sd_def32, d->sd_gran, d->sd_hibase);
-}
-#endif
-
 int
 x86_get_ldt(struct lwp *l, void *args, register_t *retval)
 {
@@ -172,24 +159,23 @@ x86_get_ldt1(struct lwp *l, struct x86_g
 	int nldt, num;
 	union descriptor *lp;
 
+#ifdef __x86_64__
+	const size_t min_ldt_size = LDT_SIZE;
+#else
+	const size_t min_ldt_size = NLDT * sizeof(union descriptor);
+#endif
+
 	error = kauth_authorize_machdep(l->l_cred, KAUTH_MACHDEP_LDT_GET,
 	    NULL, NULL, NULL, NULL);
 	if (error)
-		return (error);
-
-#ifdef	LDT_DEBUG
-	printf("x86_get_ldt: start=%d num=%d descs=%p\n", ua->start,
-	    ua->num, ua->desc);
-#endif
+		return error;
 
 	if (ua->start < 0 || ua->num < 0 || ua->start > 8192 || ua->num > 8192 ||
 	    ua->start + ua->num > 8192)
-		return (EINVAL);
+		return EINVAL;
 
-#ifdef __x86_64__
-	if (ua->start * sizeof(union descriptor) < LDT_SIZE)
+	if (ua->start * sizeof(union descriptor) < min_ldt_size)
 		return EINVAL;
-#endif
 
 	mutex_enter(&cpu_lock);
 
@@ -207,19 +193,12 @@ x86_get_ldt1(struct lwp *l, struct x86_g
 
 	if (ua->start > nldt) {
 		mutex_exit(&cpu_lock);
-		return (EINVAL);
+		return EINVAL;
 	}
 
 	lp += ua->start;
 	num = min(ua->num, nldt - ua->start);
 	ua->num = num;
-#ifdef LDT_DEBUG
-	{
-		int i;
-		for (i = 0; i < num; i++)
-			x86_print_ldt(i, &lp[i].sd);
-	}
-#endif
 
 	memcpy(cp, lp, num * sizeof(union descriptor));
 	mutex_exit(&cpu_lock);
@@ -239,7 +218,7 @@ x86_set_ldt(struct lwp *l, void *args, r
 	int error;
 
 	if ((error = copyin(args, &ua, sizeof(ua))) != 0)
-		return (error);
+		return error;
 
 	if (ua.num < 0 || ua.num > 8192)
 		return EINVAL;
@@ -280,16 +259,14 @@ x86_set_ldt1(struct lwp *l, struct x86_s
 	error = kauth_authorize_machdep(l->l_cred, KAUTH_MACHDEP_LDT_SET,
 	    NULL, NULL, NULL, NULL);
 	if (error)
-		return (error);
+		return error;
 
 	if (ua->start < 0 || ua->num < 0 || ua->start > 8192 || ua->num > 8192 ||
 	    ua->start + ua->num > 8192)
-		return (EINVAL);
+		return EINVAL;
 
-#ifdef __x86_64__
-	if (ua->start * sizeof(union descriptor) < LDT_SIZE)
+	if (ua->start * sizeof(union descriptor) < min_ldt_size)
 		return EINVAL;
-#endif
 
 	/* Check descriptors for access violations. */
 	for (i = 0; i < ua->num; i++) {
@@ -299,29 +276,6 @@ x86_set_ldt1(struct lwp *l, struct x86_s
 		case SDT_SYSNULL:
 			desc->sd.sd_p = 0;
 			break;
-#ifdef __x86_64__
-		case SDT_SYS286CGT:
-		case SDT_SYS386CGT:
-			/* We don't allow these on amd64. */
-			return EACCES;
-#else
-		case SDT_SYS286CGT:
-		case SDT_SYS386CGT:
-			/*
-			 * Only allow call gates targeting a segment
-			 * in the LDT or a user segment in the fixed
-			 * part of the gdt.  Segments in the LDT are
-			 * constrained (below) to be user segments.
-			 */
-			if (desc->gd.gd_p != 0 &&
-			    !ISLDT(desc->gd.gd_selector) &&
-			    ((IDXSEL(desc->gd.gd_selector) >= NGDT) ||
-			     (gdtstore[IDXSEL(desc->gd.gd_selector)].sd.sd_dpl !=
-				 SEL_UPL))) {
-				return EACCES;
-			}
-			break;
-#endif
 		case SDT_MEMEC:
 		case SDT_MEMEAC:
 		case SDT_MEMERC:
@@ -344,13 +298,7 @@ x86_set_ldt1(struct lwp *l, struct x86_s
 		case SDT_MEMERA:
 			break;
 		default:
-			/*
-			 * Make sure that unknown descriptor types are
-			 * not marked present.
-			 */
-			if (desc->sd.sd_p != 0)
-				return EACCES;
-			break;
+			return EACCES;
 		}
 
 		if (desc->sd.sd_p != 0) {
@@ -448,7 +396,7 @@ x86_iopl(struct lwp *l, void *args, regi
 	error = kauth_authorize_machdep(l->l_cred, KAUTH_MACHDEP_IOPL,
 	    NULL, NULL, NULL, NULL);
 	if (error)
-		return (error);
+		return error;
 
 	if ((error = copyin(args, &ua, sizeof(ua))) != 0)
 		return error;
@@ -499,10 +447,10 @@ x86_get_ioperm(struct lwp *l, void *args
 	error = kauth_authorize_machdep(l->l_cred, KAUTH_MACHDEP_IOPERM_GET,
 	    NULL, NULL, NULL, NULL);
 	if (error)
-		return (error);
+		return error;
 
 	if ((error = copyin(args, &ua, sizeof(ua))) != 0)
-		return (error);
+		return error;
 
 	iomap = pcb->pcb_iomap;
 	if (iomap == NULL) {
@@ -533,10 +481,10 @@ x86_set_ioperm(struct lwp *l, void *args
   	error = kauth_authorize_machdep(l->l_cred, KAUTH_MACHDEP_IOPERM_SET,
 	    NULL, NULL, NULL, NULL);
 	if (error)
-		return (error);
+		return error;
 
 	if ((error = copyin(args, &ua, sizeof(ua))) != 0)
-		return (error);
+		return error;
 
 	new = kmem_alloc(IOMAPSIZE, KM_SLEEP);
 	error = copyin(ua.iomap, new, IOMAPSIZE);
@@ -576,7 +524,7 @@ x86_get_mtrr(struct lwp *l, void *args, 
  	error = kauth_authorize_machdep(l->l_cred, KAUTH_MACHDEP_MTRR_GET,
 	    NULL, NULL, NULL, NULL);
 	if (error)
-		return (error);
+		return error;
 
 	error = copyin(args, &ua, sizeof ua);
 	if (error != 0)
@@ -611,7 +559,7 @@ x86_set_mtrr(struct lwp *l, void *args, 
  	error = kauth_authorize_machdep(l->l_cred, KAUTH_MACHDEP_MTRR_SET,
 	    NULL, NULL, NULL, NULL);
 	if (error)
-		return (error);
+		return error;
 
 	error = copyin(args, &ua, sizeof ua);
 	if (error != 0)
@@ -884,7 +832,7 @@ sys_sysarch(struct lwp *l, const struct 
 		error = EINVAL;
 		break;
 	}
-	return (error);
+	return error;
 }
 
 int

Reply via email to