Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch Fix a huge privilege separation vulnerability in Xe...
details: https://anonhg.NetBSD.org/src/rev/05e696a5389c
branches: trunk
changeset: 358467:05e696a5389c
user: maxv <maxv%NetBSD.org@localhost>
date: Sun Dec 31 08:29:38 2017 +0000
description:
Fix a huge privilege separation vulnerability in Xen-amd64.
On amd64 the kernel runs in ring3, like userland, and therefore SEL_KPL
equals SEL_UPL. While Xen can make a distinction between usermode and
kernelmode in %cs, it can't when it comes to iopl. Since we set SEL_KPL
in iopl, Xen sees SEL_UPL, and allows (unprivileged) userland processes
to read and write to the CPU ports.
It is easy, then, to completely escalate privileges; by reprogramming the
PIC, by reading the ATA disks, by intercepting the keyboard interrupts
(keylogger), etc.
Declare IOPL_KPL, set to 1 on Xen-amd64, which allows the kernel to use
the ports but not userland. I didn't test this change on i386, but it
seems fine enough.
diffstat:
sys/arch/amd64/amd64/machdep.c | 6 +++---
sys/arch/amd64/include/segments.h | 8 +++++++-
sys/arch/i386/i386/machdep.c | 6 +++---
sys/arch/i386/include/segments.h | 4 +++-
sys/arch/x86/x86/vm_machdep.c | 6 +++---
5 files changed, 19 insertions(+), 11 deletions(-)
diffs (121 lines):
diff -r 3254d4acf24b -r 05e696a5389c sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c Sun Dec 31 07:23:09 2017 +0000
+++ b/sys/arch/amd64/amd64/machdep.c Sun Dec 31 08:29:38 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.279 2017/12/01 21:22:45 maxv Exp $ */
+/* $NetBSD: machdep.c,v 1.280 2017/12/31 08:29:38 maxv Exp $ */
/*
* Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.279 2017/12/01 21:22:45 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.280 2017/12/31 08:29:38 maxv Exp $");
/* #define XENDEBUG_LOW */
@@ -479,7 +479,7 @@
pcb->pcb_fs = 0;
pcb->pcb_gs = 0;
pcb->pcb_rsp0 = (uvm_lwp_getuarea(l) + USPACE - 16) & ~0xf;
- pcb->pcb_iopl = SEL_KPL;
+ pcb->pcb_iopl = IOPL_KPL;
pcb->pcb_dbregs = NULL;
pcb->pcb_cr0 = rcr0() & ~CR0_TS;
l->l_md.md_regs = (struct trapframe *)pcb->pcb_rsp0 - 1;
diff -r 3254d4acf24b -r 05e696a5389c sys/arch/amd64/include/segments.h
--- a/sys/arch/amd64/include/segments.h Sun Dec 31 07:23:09 2017 +0000
+++ b/sys/arch/amd64/include/segments.h Sun Dec 31 08:29:38 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: segments.h,v 1.33 2017/11/04 08:50:47 cherry Exp $ */
+/* $NetBSD: segments.h,v 1.34 2017/12/31 08:29:38 maxv Exp $ */
/*
* Copyright (c) 1990 The Regents of the University of California.
@@ -107,6 +107,12 @@
#define ISLDT(s) ((s) & SEL_LDT) /* is it local or global */
#define SEL_LDT 4 /* local descriptor table */
+#ifdef XEN
+#define IOPL_KPL 1
+#else
+#define IOPL_KPL SEL_KPL
+#endif
+
/* Dynamically allocated TSSs and LDTs start (byte offset) */
#define SYSSEL_START (NGDT_MEM << 3)
#define DYNSEL_START (SYSSEL_START + (NGDT_SYS << 4))
diff -r 3254d4acf24b -r 05e696a5389c sys/arch/i386/i386/machdep.c
--- a/sys/arch/i386/i386/machdep.c Sun Dec 31 07:23:09 2017 +0000
+++ b/sys/arch/i386/i386/machdep.c Sun Dec 31 08:29:38 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.799 2017/11/11 12:51:06 maxv Exp $ */
+/* $NetBSD: machdep.c,v 1.800 2017/12/31 08:29:38 maxv Exp $ */
/*
* Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009, 2017
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.799 2017/11/11 12:51:06 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.800 2017/12/31 08:29:38 maxv Exp $");
#include "opt_beep.h"
#include "opt_compat_freebsd.h"
@@ -472,7 +472,7 @@
pcb->pcb_cr0 = rcr0() & ~CR0_TS;
pcb->pcb_esp0 = uvm_lwp_getuarea(l) + USPACE - 16;
- pcb->pcb_iopl = SEL_KPL;
+ pcb->pcb_iopl = IOPL_KPL;
l->l_md.md_regs = (struct trapframe *)pcb->pcb_esp0 - 1;
memcpy(&pcb->pcb_fsd, &gdtstore[GUDATA_SEL], sizeof(pcb->pcb_fsd));
memcpy(&pcb->pcb_gsd, &gdtstore[GUDATA_SEL], sizeof(pcb->pcb_gsd));
diff -r 3254d4acf24b -r 05e696a5389c sys/arch/i386/include/segments.h
--- a/sys/arch/i386/include/segments.h Sun Dec 31 07:23:09 2017 +0000
+++ b/sys/arch/i386/include/segments.h Sun Dec 31 08:29:38 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: segments.h,v 1.63 2017/11/04 08:50:47 cherry Exp $ */
+/* $NetBSD: segments.h,v 1.64 2017/12/31 08:29:38 maxv Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -105,6 +105,8 @@
#define ISLDT(s) ((s) & SEL_LDT) /* is it local or global */
#define SEL_LDT 4 /* local descriptor table */
+#define IOPL_KPL SEL_KPL
+
/* Dynamically allocated TSSs and LDTs start (byte offset) */
#define DYNSEL_START (NGDT << 3)
diff -r 3254d4acf24b -r 05e696a5389c sys/arch/x86/x86/vm_machdep.c
--- a/sys/arch/x86/x86/vm_machdep.c Sun Dec 31 07:23:09 2017 +0000
+++ b/sys/arch/x86/x86/vm_machdep.c Sun Dec 31 08:29:38 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_machdep.c,v 1.29 2017/06/17 07:45:13 maxv Exp $ */
+/* $NetBSD: vm_machdep.c,v 1.30 2017/12/31 08:29:38 maxv Exp $ */
/*-
* Copyright (c) 1982, 1986 The Regents of the University of California.
@@ -80,7 +80,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.29 2017/06/17 07:45:13 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.30 2017/12/31 08:29:38 maxv Exp $");
#include "opt_mtrr.h"
@@ -164,7 +164,7 @@
pcb2->pcb_dbregs = NULL;
#if defined(XEN)
- pcb2->pcb_iopl = SEL_KPL;
+ pcb2->pcb_iopl = IOPL_KPL;
#endif
/*
Home |
Main Index |
Thread Index |
Old Index