Received: by 10.213.65.68 with SMTP id h4csp36088imn; Mon, 19 Mar 2018 18:43:04 -0700 (PDT) X-Google-Smtp-Source: AG47ELsCEq4cqwAEucr0VwGum8eETeyZJjvl0rwTosmKKdMp+26EsT7A1n/+4JiLFpv+ZJlWXNe7 X-Received: by 10.99.106.202 with SMTP id f193mr10902000pgc.334.1521510184714; Mon, 19 Mar 2018 18:43:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521510184; cv=none; d=google.com; s=arc-20160816; b=wgONDN8X3VcY+w2eYIBFJztDekcH1UVs51PUR2jFkQPyTAziuHjOfGHC2FafC65twU ASgBIT3POXRhPt7l2f10Hem5wXmJWywOX9X3LWPhTKuOYE6WV/GXM/7qsBg9vdSfIpeF Pe29Ol2TaMZH55D1Iz4MnDooKp8JrTpjvnxiqLLq+TehRidDwzbKU0fArlakHXgIOQ/d 3W3zrVGtdyTz31gB2Jj2syMvRZQSaiiCmge6Jt/1DOYi7Td4AV4yGtm8Q58Dpohs3mMO XVPyHG7x4sDS2nqINeHBTq2vcYA9h4Q8uUIU21zTs3jDY1wAsGkT2DVBlH7nlODZnSRs AWjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=9nHWASNjxal146xv8zJydhEhcLE1YRgoGjmjlfZZC9I=; b=XZqBYeTCSJ7hphtVRMV8NidENheEI55PvBqiKcahHO2pxdSwEepHwL8Z3bi0o2WDih GQXu/LuIXSW/smM4aMIqhVF78mnmStwCdO4tMDhzRaWLBVUDcbDD6CNWEbp8gh8DHFR/ +vBmV56rUZunVSd4vqm90C4Syj/fx6OnmIo5cpUWfR2PbYi4z2ZMCBLWVcRG0v3xS4O/ mAqzVIka2Vy9gsPoBtOrpTUjW3cO2IVA8H05rouIx+ETKGccn9y865vhbQr8Yo2VB+zE JLNkxUw7XYVXQukOFJ/u2sCYusWqcRoG9MomPVqdnyA6XhqQLw/sCgX2GW0+o1a6n3bA EOxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u21si432919pfl.176.2018.03.19.18.42.50; Mon, 19 Mar 2018 18:43:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S969222AbeCSSR4 (ORCPT + 99 others); Mon, 19 Mar 2018 14:17:56 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45740 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965763AbeCSSRw (ORCPT ); Mon, 19 Mar 2018 14:17:52 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5FD70125D; Mon, 19 Mar 2018 18:17:51 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ricardo Neri , Thomas Gleixner , Andrew Morton , Andy Lutomirski , Borislav Petkov , Borislav Petkov , Brian Gerst , Chen Yucong , Chris Metcalf , Dave Hansen , Denys Vlasenko , Fenghua Yu , "H. Peter Anvin" , Huang Rui , Jiri Slaby , Jonathan Corbet , Josh Poimboeuf , Linus Torvalds , Masami Hiramatsu , "Michael S. Tsirkin" , Paolo Bonzini , Paul Gortmaker , Peter Zijlstra , "Ravi V. Shankar" , Shuah Khan , Tony Luck , Vlastimil Babka , ricardo.neri@intel.com, Ingo Molnar Subject: [PATCH 4.4 112/134] selftests/x86: Add tests for the STR and SLDT instructions Date: Mon, 19 Mar 2018 19:06:35 +0100 Message-Id: <20180319171905.477378247@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319171849.024066323@linuxfoundation.org> References: <20180319171849.024066323@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ricardo Neri commit a9e017d5619eb371460c8e516f4684def62bef3a upstream. The STR and SLDT instructions are not valid when running on virtual-8086 mode and generate an invalid operand exception. These two instructions are protected by the Intel User-Mode Instruction Prevention (UMIP) security feature. In protected mode, if UMIP is enabled, these instructions generate a general protection fault if called from CPL > 0. Linux traps the general protection fault and emulates the instructions sgdt, sidt and smsw; but not str and sldt. These tests are added to verify that the emulation code does not emulate these two instructions but the expected invalid operand exception is seen. Tests fallback to exit with INT3 in case emulation does happen. Signed-off-by: Ricardo Neri Reviewed-by: Thomas Gleixner Cc: Andrew Morton Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Borislav Petkov Cc: Brian Gerst Cc: Chen Yucong Cc: Chris Metcalf Cc: Dave Hansen Cc: Denys Vlasenko Cc: Fenghua Yu Cc: H. Peter Anvin Cc: Huang Rui Cc: Jiri Slaby Cc: Jonathan Corbet Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Masami Hiramatsu Cc: Michael S. Tsirkin Cc: Paolo Bonzini Cc: Paul Gortmaker Cc: Peter Zijlstra Cc: Ravi V. Shankar Cc: Shuah Khan Cc: Tony Luck Cc: Vlastimil Babka Cc: ricardo.neri@intel.com Link: http://lkml.kernel.org/r/1509935277-22138-13-git-send-email-ricardo.neri-calderon@linux.intel.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- tools/testing/selftests/x86/entry_from_vm86.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) --- a/tools/testing/selftests/x86/entry_from_vm86.c +++ b/tools/testing/selftests/x86/entry_from_vm86.c @@ -111,6 +111,11 @@ asm ( "smsw %ax\n\t" "mov %ax, (2080)\n\t" "int3\n\t" + "vmcode_umip_str:\n\t" + "str %eax\n\t" + "vmcode_umip_sldt:\n\t" + "sldt %eax\n\t" + "int3\n\t" ".size vmcode, . - vmcode\n\t" "end_vmcode:\n\t" ".code32\n\t" @@ -119,7 +124,8 @@ asm ( extern unsigned char vmcode[], end_vmcode[]; extern unsigned char vmcode_bound[], vmcode_sysenter[], vmcode_syscall[], - vmcode_sti[], vmcode_int3[], vmcode_int80[], vmcode_umip[]; + vmcode_sti[], vmcode_int3[], vmcode_int80[], vmcode_umip[], + vmcode_umip_str[], vmcode_umip_sldt[]; /* Returns false if the test was skipped. */ static bool do_test(struct vm86plus_struct *v86, unsigned long eip, @@ -226,6 +232,16 @@ void do_umip_tests(struct vm86plus_struc printf("[FAIL]\tAll the results of SIDT should be the same.\n"); else printf("[PASS]\tAll the results from SIDT are identical.\n"); + + sethandler(SIGILL, sighandler, 0); + do_test(vm86, vmcode_umip_str - vmcode, VM86_SIGNAL, 0, + "STR instruction"); + clearhandler(SIGILL); + + sethandler(SIGILL, sighandler, 0); + do_test(vm86, vmcode_umip_sldt - vmcode, VM86_SIGNAL, 0, + "SLDT instruction"); + clearhandler(SIGILL); } int main(void)