Received: by 10.213.65.68 with SMTP id h4csp1734526imn; Mon, 19 Mar 2018 11:48:11 -0700 (PDT) X-Google-Smtp-Source: AG47ELsVqADZgId2PWPq0W/S63n/tZvKoxKi2b4TqQtXkdEPmmlRnwcKAUH4TmBgg5HwyUs3EvW8 X-Received: by 10.99.106.202 with SMTP id f193mr10076794pgc.334.1521485291393; Mon, 19 Mar 2018 11:48:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521485291; cv=none; d=google.com; s=arc-20160816; b=Azlhv2Y7fcrC6arRPlnh5uLSKjLRx0a3wLuwpHume16xB3F4lnX2LdJEoW/AvCXRMV /ZDKyxqTfcpQ+s7roSqFrepBVTfjDR3ESnSI+PEwTQll2Ck44faSkl3wTTx6vUVJ8iEw hdnYFOKY6H7xeUgnumYpWv5+iRN0cki40swVRX5REHN/RtaNO5fSBtMIQ1qEqi59Str6 MsiOsA2zl8WXr96Ob8KnoT2TaYL3JNKjjAU6Zha3Rmnfn2VhjUOzzd3mPajKf4Jsv3Aa Tq3PKOmgJ6TusqmB2P/2gzRJslGlxh2nJDcCODB953yQyQ2KUQfDFPkaA3Uwi28iJRXo gXqw== 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=+OVjtNFtOYWfLGHogYGQXF7S5Vj+SK444heYdbEhAJE=; b=VbxcGZOmfV+yTSFrGyYqIPFT9aVJNG7vBNVXBEyRP783oQHxiNv8Mx9RTuDwTXsrcj Tx+puISIpDgh9ksDA1zxlVNkewsYfhU7VVSVOv8ryLWV4bGbwXPDjZJGOE1Ft2sJIb3v Asja7TXSHig7W/3aBMewA2fE9ITc6xvN5f3OZNQfGS30P/Hdk7R0Ax9rQII5T446MQzA f7I0NvnHj2IVu7eZmqzjcnW5VK9H8JJhncQYUXhCjesWGAH6bvEIWnfk1Aw+cejEnbKa YBf9yIlOwimYwj0jRUi8R1Fve/EN0756DmHplqrjJ6fWw3K2T7PtJQX9dTDlJKcLqluZ 0Mtg== 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 61-v6si444117plq.737.2018.03.19.11.47.57; Mon, 19 Mar 2018 11:48:11 -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 S970333AbeCSSqM (ORCPT + 99 others); Mon, 19 Mar 2018 14:46:12 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:53734 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032051AbeCSSb5 (ORCPT ); Mon, 19 Mar 2018 14:31:57 -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 915D311CE; Mon, 19 Mar 2018 18:31:56 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Oldeman , Andy Lutomirski , Borislav Petkov , Brian Gerst , Denys Vlasenko , "H. Peter Anvin" , Josh Poimboeuf , Linus Torvalds , Peter Zijlstra , Stas Sergeev , Thomas Gleixner , Ingo Molnar Subject: [PATCH 4.15 04/52] selftests/x86/entry_from_vm86: Add test cases for POPF Date: Mon, 19 Mar 2018 19:08:02 +0100 Message-Id: <20180319180735.259095372@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180734.976730813@linuxfoundation.org> References: <20180319180734.976730813@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.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andy Lutomirski commit 78393fdde2a456cafa414b171c90f26a3df98b20 upstream. POPF is currently broken -- add tests to catch the error. This results in: [RUN] POPF with VIP set and IF clear from vm86 mode [INFO] Exited vm86 mode due to STI [FAIL] Incorrect return reason (started at eip = 0xd, ended at eip = 0xf) because POPF currently fails to check IF before reporting a pending interrupt. This patch also makes the FAIL message a bit more informative. Reported-by: Bart Oldeman Signed-off-by: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Stas Sergeev Cc: Thomas Gleixner Cc: stable@vger.kernel.org Link: http://lkml.kernel.org/r/a16270b5cfe7832d6d00c479d0f871066cbdb52b.1521003603.git.luto@kernel.org Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- tools/testing/selftests/x86/entry_from_vm86.c | 30 +++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) --- a/tools/testing/selftests/x86/entry_from_vm86.c +++ b/tools/testing/selftests/x86/entry_from_vm86.c @@ -95,6 +95,10 @@ asm ( "int3\n\t" "vmcode_int80:\n\t" "int $0x80\n\t" + "vmcode_popf_hlt:\n\t" + "push %ax\n\t" + "popf\n\t" + "hlt\n\t" "vmcode_umip:\n\t" /* addressing via displacements */ "smsw (2052)\n\t" @@ -124,8 +128,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_umip_str[], vmcode_umip_sldt[]; + vmcode_sti[], vmcode_int3[], vmcode_int80[], vmcode_popf_hlt[], + 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, @@ -175,7 +179,7 @@ static bool do_test(struct vm86plus_stru (VM86_TYPE(ret) == rettype && VM86_ARG(ret) == retarg)) { printf("[OK]\tReturned correctly\n"); } else { - printf("[FAIL]\tIncorrect return reason\n"); + printf("[FAIL]\tIncorrect return reason (started at eip = 0x%lx, ended at eip = 0x%lx)\n", eip, v86->regs.eip); nerrs++; } @@ -264,6 +268,9 @@ int main(void) v86.regs.ds = load_addr / 16; v86.regs.es = load_addr / 16; + /* Use the end of the page as our stack. */ + v86.regs.esp = 4096; + assert((v86.regs.cs & 3) == 0); /* Looks like RPL = 0 */ /* #BR -- should deliver SIG??? */ @@ -295,6 +302,23 @@ int main(void) v86.regs.eflags &= ~X86_EFLAGS_IF; do_test(&v86, vmcode_sti - vmcode, VM86_STI, 0, "STI with VIP set"); + /* POPF with VIP set but IF clear: should not trap */ + v86.regs.eflags = X86_EFLAGS_VIP; + v86.regs.eax = 0; + do_test(&v86, vmcode_popf_hlt - vmcode, VM86_UNKNOWN, 0, "POPF with VIP set and IF clear"); + + /* POPF with VIP set and IF set: should trap */ + v86.regs.eflags = X86_EFLAGS_VIP; + v86.regs.eax = X86_EFLAGS_IF; + do_test(&v86, vmcode_popf_hlt - vmcode, VM86_STI, 0, "POPF with VIP and IF set"); + + /* POPF with VIP clear and IF set: should not trap */ + v86.regs.eflags = 0; + v86.regs.eax = X86_EFLAGS_IF; + do_test(&v86, vmcode_popf_hlt - vmcode, VM86_UNKNOWN, 0, "POPF with VIP clear and IF set"); + + v86.regs.eflags = 0; + /* INT3 -- should cause #BP */ do_test(&v86, vmcode_int3 - vmcode, VM86_TRAP, 3, "INT3");