Received: by 10.213.65.68 with SMTP id h4csp1725173imn; Mon, 19 Mar 2018 11:30:57 -0700 (PDT) X-Google-Smtp-Source: AG47ELvj5+xkM/Fw5xCF9v8ccbJJrfsm1EahpdNR7Bs4skoU1aAVCQcSE8OBryv/T5onvIgWS8OC X-Received: by 10.99.110.133 with SMTP id j127mr9924250pgc.79.1521484257348; Mon, 19 Mar 2018 11:30:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521484257; cv=none; d=google.com; s=arc-20160816; b=WzEwWWFqoC/iZ1/ux0lcPLmMMURG4Vf19mvg5HUYFan+ipvwebeUic05Vziuahsi1M 0Kt7fJ/Nnn8O95ox9jG9QZfMbAzcraxbSoWswRJe4YzSPnhDsPc9VuTtKdPgJ+LC6Yu4 FtiHJlnNtHz8BKN/D+QcIvV6fa4P2tHZm12juldaPoBmP31aista5TUWY7aqqyzGXzGy mrB85w44OORawWup35kqAWIgawOGlWSIhj6/YNg/JVeJO3/wxXsF4pjqNJtmEj2fy54u AJGxhzT1pt0sM4tQhb3mTZHcpSKaVe5cr3Rm5FvOLTujL1oi9qQ/LupK+UXBeDpefY4K LobA== 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=SthghpMiWly7xM2X8eHIExbvuwV244ZLRaMzJWXs+T8=; b=x54CxONpT4miyONUBUFwJ5BFq6/FPeuGG+CeI8Jrnlx9DbeidaAyJkiC9ahJTEtJYX k8kPeUhfcj5LUdoHEm3d1q9+90Ve29tsG6+HTzNSyRnGnmJSnDpFdYQmEu6OzNqq9X5K 3cpklnmpQK++Fjs/0puE6vcGz1FZ8Bvs2nY+zY80jsMxdEm3EDx9uUytZCpRXTIRbEPo n1JCDQLaSxGo55sX95gpFEFsScPkzcomnPCdWQtN6F2B9VFyPumGtHpBKBxs9+bQhl1Y /dViRcFhs9Yke7KqJuHAMCS2f1bPdAb0CckTF63OiR9ZubA6Xqt15YgN9FZL2ykq9u81 GQaw== 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 y2-v6si381347plh.649.2018.03.19.11.30.42; Mon, 19 Mar 2018 11:30:57 -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 S969762AbeCSS2E (ORCPT + 99 others); Mon, 19 Mar 2018 14:28:04 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:51414 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S970064AbeCSS1y (ORCPT ); Mon, 19 Mar 2018 14:27:54 -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 CF1C7127F; Mon, 19 Mar 2018 18:27:53 +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.9 215/241] selftests/x86: Add tests for the STR and SLDT instructions Date: Mon, 19 Mar 2018 19:08:00 +0100 Message-Id: <20180319180800.075419133@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180751.172155436@linuxfoundation.org> References: <20180319180751.172155436@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.9-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)