Module Name: src Committed By: maxv Date: Mon Feb 6 16:34:37 UTC 2017
Modified Files: src/sys/arch/amd64/amd64: netbsd32_machdep.c Log Message: In cpu_mcontext32_validate, allow the registers to have different locations if the LDT is user-set. I am intentionally not allowing this in check_sigcontext32, because I don't think Wine uses it. To generate a diff of this commit: cvs rdiff -u -r1.100 -r1.101 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.100 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.101 --- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.100 Mon Feb 6 16:02:17 2017 +++ src/sys/arch/amd64/amd64/netbsd32_machdep.c Mon Feb 6 16:34:37 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_machdep.c,v 1.100 2017/02/06 16:02:17 maxv Exp $ */ +/* $NetBSD: netbsd32_machdep.c,v 1.101 2017/02/06 16:34:37 maxv Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.100 2017/02/06 16:02:17 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.101 2017/02/06 16:34:37 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -1016,6 +1016,7 @@ check_sigcontext32(struct lwp *l, const int cpu_mcontext32_validate(struct lwp *l, const mcontext32_t *mcp) { + struct pmap *pmap = l->l_proc->p_vmspace->vm_map.pmap; const __greg32_t *gr; struct trapframe *tf; struct pcb *pcb; @@ -1024,22 +1025,31 @@ cpu_mcontext32_validate(struct lwp *l, c tf = l->l_md.md_regs; pcb = lwp_getpcb(l); - if (((gr[_REG32_EFL] ^ tf->tf_rflags) & PSL_USERSTATIC) != 0 || - !VALID_USER_CSEL32(gr[_REG32_CS])) - return EINVAL; - if (gr[_REG32_FS] != 0 && !VALID_USER_DSEL32(gr[_REG32_FS]) && - !(VALID_USER_FSEL32(gr[_REG32_FS]) && pcb->pcb_fs != 0)) - return EINVAL; - if (gr[_REG32_GS] != 0 && !VALID_USER_DSEL32(gr[_REG32_GS]) && - !(VALID_USER_GSEL32(gr[_REG32_GS]) && pcb->pcb_gs != 0)) - return EINVAL; - if (gr[_REG32_ES] != 0 && !VALID_USER_DSEL32(gr[_REG32_ES])) - return EINVAL; - if (!VALID_USER_DSEL32(gr[_REG32_DS]) || - !VALID_USER_DSEL32(gr[_REG32_SS])) - return EINVAL; - if (gr[_REG32_EIP] >= VM_MAXUSER_ADDRESS32) + if (((gr[_REG32_EFL] ^ tf->tf_rflags) & PSL_USERSTATIC) != 0) return EINVAL; + + if (__predict_false(pmap->pm_ldt != NULL)) { + /* Only when the LDT is user-set (with USER_LDT) */ + if (!USERMODE(gr[_REG32_CS], gr[_REG32_EFL])) + return EINVAL; + } else { + if (!VALID_USER_CSEL32(gr[_REG32_CS])) + return EINVAL; + if (gr[_REG32_FS] != 0 && !VALID_USER_DSEL32(gr[_REG32_FS]) && + !(VALID_USER_FSEL32(gr[_REG32_FS]) && pcb->pcb_fs != 0)) + return EINVAL; + if (gr[_REG32_GS] != 0 && !VALID_USER_DSEL32(gr[_REG32_GS]) && + !(VALID_USER_GSEL32(gr[_REG32_GS]) && pcb->pcb_gs != 0)) + return EINVAL; + if (gr[_REG32_ES] != 0 && !VALID_USER_DSEL32(gr[_REG32_ES])) + return EINVAL; + if (!VALID_USER_DSEL32(gr[_REG32_DS]) || + !VALID_USER_DSEL32(gr[_REG32_SS])) + return EINVAL; + if (gr[_REG32_EIP] >= VM_MAXUSER_ADDRESS32) + return EINVAL; + } + return 0; }