Module Name: src
Committed By: maxv
Date: Sun Jul 19 14:31:31 UTC 2020
Modified Files:
src/sys/arch/amd64/conf: ALL GENERIC
src/sys/arch/x86/x86: x86_machdep.c
src/tests/lib/libi386: t_user_ldt.c
Log Message:
Compile USER_LDT by default, but, put it behind a privileged sysctl that
defaults to disabled. To enable:
# sysctl -w machdep.user_ldt=1
To generate a diff of this commit:
cvs rdiff -u -r1.156 -r1.157 src/sys/arch/amd64/conf/ALL
cvs rdiff -u -r1.572 -r1.573 src/sys/arch/amd64/conf/GENERIC
cvs rdiff -u -r1.144 -r1.145 src/sys/arch/x86/x86/x86_machdep.c
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libi386/t_user_ldt.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.156 src/sys/arch/amd64/conf/ALL:1.157
--- src/sys/arch/amd64/conf/ALL:1.156 Tue Jul 14 00:45:52 2020
+++ src/sys/arch/amd64/conf/ALL Sun Jul 19 14:31:31 2020
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.156 2020/07/14 00:45:52 yamaguchi Exp $
+# $NetBSD: ALL,v 1.157 2020/07/19 14:31:31 maxv Exp $
# From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
#
# ALL machine description file
@@ -17,14 +17,14 @@ include "arch/amd64/conf/std.amd64"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "ALL-$Revision: 1.156 $"
+#ident "ALL-$Revision: 1.157 $"
maxusers 64 # estimated number of users
makeoptions USE_SSP=yes
# CPU-related options.
-#options USER_LDT # user-settable LDT; used by WINE
+options USER_LDT # User-settable LDT, used by Wine
options X86EMU # 386 Real Mode emulator
#options PAE # PAE mode (36 bits physical addressing)
makeoptions SPECTRE_V2_GCC_MITIGATION=1 # GCC Spectre variant 2
Index: src/sys/arch/amd64/conf/GENERIC
diff -u src/sys/arch/amd64/conf/GENERIC:1.572 src/sys/arch/amd64/conf/GENERIC:1.573
--- src/sys/arch/amd64/conf/GENERIC:1.572 Tue Jul 14 01:05:06 2020
+++ src/sys/arch/amd64/conf/GENERIC Sun Jul 19 14:31:31 2020
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.572 2020/07/14 01:05:06 yamaguchi Exp $
+# $NetBSD: GENERIC,v 1.573 2020/07/19 14:31:31 maxv Exp $
#
# GENERIC machine description file
#
@@ -22,7 +22,7 @@ include "arch/amd64/conf/std.amd64"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "GENERIC-$Revision: 1.572 $"
+#ident "GENERIC-$Revision: 1.573 $"
maxusers 64 # estimated number of users
@@ -74,7 +74,7 @@ options USERCONF # userconf(4) support
options SYSCTL_INCLUDE_DESCR # Include sysctl descriptions in kernel
# CPU-related options
-#options USER_LDT # User-settable LDT, used by Wine
+options USER_LDT # User-settable LDT, used by Wine
options SVS # Separate Virtual Space
options PCPU_IDT # Per CPU IDTs
Index: src/sys/arch/x86/x86/x86_machdep.c
diff -u src/sys/arch/x86/x86/x86_machdep.c:1.144 src/sys/arch/x86/x86/x86_machdep.c:1.145
--- src/sys/arch/x86/x86/x86_machdep.c:1.144 Sat Jul 4 21:02:16 2020
+++ src/sys/arch/x86/x86/x86_machdep.c Sun Jul 19 14:31:31 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: x86_machdep.c,v 1.144 2020/07/04 21:02:16 chs Exp $ */
+/* $NetBSD: x86_machdep.c,v 1.145 2020/07/19 14:31:31 maxv Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi,
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.144 2020/07/04 21:02:16 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.145 2020/07/19 14:31:31 maxv Exp $");
#include "opt_modular.h"
#include "opt_physmem.h"
@@ -95,6 +95,8 @@ void (*x86_cpu_idle)(void);
static bool x86_cpu_idle_ipi;
static char x86_cpu_idle_text[16];
+static bool x86_user_ldt_enabled __read_mostly = false;
+
#ifdef XEN
#include <xen/xen.h>
@@ -1178,9 +1180,14 @@ x86_listener_cb(kauth_cred_t cred, kauth
switch (action) {
case KAUTH_MACHDEP_IOPERM_GET:
+ result = KAUTH_RESULT_ALLOW;
+ break;
+
case KAUTH_MACHDEP_LDT_GET:
case KAUTH_MACHDEP_LDT_SET:
- result = KAUTH_RESULT_ALLOW;
+ if (x86_user_ldt_enabled) {
+ result = KAUTH_RESULT_ALLOW;
+ }
break;
default:
@@ -1432,6 +1439,13 @@ SYSCTL_SETUP(sysctl_machdep_setup, "sysc
CTL_CREATE, CTL_EOL);
#endif
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_READWRITE,
+ CTLTYPE_BOOL, "user_ldt",
+ SYSCTL_DESCR("Whether USER_LDT is enabled"),
+ NULL, 0, &x86_user_ldt_enabled, 0,
+ CTL_MACHDEP, CTL_CREATE, CTL_EOL);
+
#ifndef XENPV
void sysctl_speculation_init(struct sysctllog **);
sysctl_speculation_init(clog);
Index: src/tests/lib/libi386/t_user_ldt.c
diff -u src/tests/lib/libi386/t_user_ldt.c:1.4 src/tests/lib/libi386/t_user_ldt.c:1.5
--- src/tests/lib/libi386/t_user_ldt.c:1.4 Fri Jul 3 16:07:52 2020
+++ src/tests/lib/libi386/t_user_ldt.c Sun Jul 19 14:31:31 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: t_user_ldt.c,v 1.4 2020/07/03 16:07:52 maxv Exp $ */
+/* $NetBSD: t_user_ldt.c,v 1.5 2020/07/19 14:31:31 maxv Exp $ */
/*
* Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@ user_ldt_detect(void)
int ret;
ret = i386_get_ldt(0, &desc, 1);
- user_ldt_supported = (ret != -1) || (errno != ENOSYS);
+ user_ldt_supported = (ret != -1) || (errno != ENOSYS && errno != EPERM);
}
static void