From owner-svn-soc-all@FreeBSD.ORG Thu Jun 12 22:30:16 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 855DD17D for ; Thu, 12 Jun 2014 22:30:16 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 583A62092 for ; Thu, 12 Jun 2014 22:30:16 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s5CMUGOM021487 for ; Thu, 12 Jun 2014 22:30:16 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s5CMUFUW021259 for svn-soc-all@FreeBSD.org; Thu, 12 Jun 2014 22:30:15 GMT (envelope-from op@FreeBSD.org) Date: Thu, 12 Jun 2014 22:30:15 GMT Message-Id: <201406122230.s5CMUFUW021259@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r269487 - soc2014/op/freebsd-base/sys/i386/i386 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Jun 2014 22:30:16 -0000 Author: op Date: Thu Jun 12 22:30:15 2014 New Revision: 269487 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=269487 Log: SMAP i386: added related trap handler git: https://github.com/opntr/opBSD/tree/op/gsoc2014/smap Signed-off-by: Oliver Pinter Modified: soc2014/op/freebsd-base/sys/i386/i386/trap.c Modified: soc2014/op/freebsd-base/sys/i386/i386/trap.c ============================================================================== --- soc2014/op/freebsd-base/sys/i386/i386/trap.c Thu Jun 12 22:29:50 2014 (r269486) +++ soc2014/op/freebsd-base/sys/i386/i386/trap.c Thu Jun 12 22:30:15 2014 (r269487) @@ -860,6 +860,16 @@ map = &vm->vm_map; /* + * If CPL < 3, SMAP protections are disabled if EFLAGS.AC = 1. + * If CPL = 3, SMAP applies to all supervisor-mode data accesses + * (these are implicit supervisor accesses) regardless of the + * value of EFLAGS.AC." - Intel Ref. # 319433-014 9.3.2 + */ + if (__predict_false(smap_access_violation(frame, usermode))) { + panic("SMAP!"); + } + + /* * When accessing a user-space address, kernel must be * ready to accept the page fault, and provide a * handling routine. Since accessing the address @@ -1020,6 +1030,32 @@ panic("unknown/reserved trap"); } + +/* + * Supervisor Mode Access Prevention violation + * + * If CPL < 3, SMAP protections are disabled if EFLAGS.AC = 1. + * If CPL = 3, SMAP applies to all supervisor-mode data accesses + * (these are implicit supervisor accesses) regardless of the + * value of EFLAGS.AC." - Intel Ref. # 319433-014 9.3.2 + */ +static bool +smap_access_violation(struct trapframe *frame, int usermode) +{ + /* SMAP disabled */ + if ((cpu_stdext_feature & CPUID_STDEXT_SMAP) == 0) + return (false); + + /* CPL == 3 or EFLAGS.AC == 1 */ + if (usermode || (frame->tf_rflags & PSL_AC) != 0) + return (false); + + /* + * CPL < 3 and EFLAGS.AC == 0 + */ + return (true); +} + /* * Double fault handler. Called when a fault occurs while writing * a frame for a trap/exception onto the stack. This usually occurs