Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754051AbdCHQ0m (ORCPT ); Wed, 8 Mar 2017 11:26:42 -0500 Received: from mail-ua0-f177.google.com ([209.85.217.177]:34785 "EHLO mail-ua0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751972AbdCHQ0j (ORCPT ); Wed, 8 Mar 2017 11:26:39 -0500 MIME-Version: 1.0 In-Reply-To: <20170308003254.27833-22-ricardo.neri-calderon@linux.intel.com> References: <20170308003254.27833-1-ricardo.neri-calderon@linux.intel.com> <20170308003254.27833-22-ricardo.neri-calderon@linux.intel.com> From: Andy Lutomirski Date: Wed, 8 Mar 2017 07:56:20 -0800 Message-ID: Subject: Re: [v6 PATCH 21/21] selftests/x86: Add tests for User-Mode Instruction Prevention To: Ricardo Neri Cc: Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , Andy Lutomirski , Borislav Petkov , Peter Zijlstra , Andrew Morton , Brian Gerst , Chris Metcalf , Dave Hansen , Paolo Bonzini , Liang Z Li , Masami Hiramatsu , Huang Rui , Jiri Slaby , Jonathan Corbet , "Michael S. Tsirkin" , Paul Gortmaker , Vlastimil Babka , Chen Yucong , Alexandre Julliard , Stas Sergeev , Fenghua Yu , "Ravi V. Shankar" , Shuah Khan , "linux-kernel@vger.kernel.org" , X86 ML , linux-msdos@vger.kernel.org, wine-devel@winehq.org Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1521 Lines: 28 On Tue, Mar 7, 2017 at 4:32 PM, Ricardo Neri wrote: > Certain user space programs that run on virtual-8086 mode may utilize > instructions protected by the User-Mode Instruction Prevention (UMIP) > security feature present in new Intel processors: SGDT, SIDT and SMSW. In > such a case, a general protection fault is issued if UMIP is enabled. When > such a fault happens, the kernel catches it and emulates the results of > these instructions with dummy values. The purpose of this new > test is to verify whether the impacted instructions can be executed without > causing such #GP. If no #GP exceptions occur, we expect to exit virtual- > 8086 mode from INT 0x80. > > The instructions protected by UMIP are executed in representative use > cases: > a) the memory address of the result is given in the form of a displacement > from the base of the data segment > b) the memory address of the result is given in a general purpose register > c) the result is stored directly in a general purpose register. > > Unfortunately, it is not possible to check the results against a set of > expected values because no emulation will occur in systems that do not have > the UMIP feature. Instead, results are printed for verification. You could pre-initialize the result buffer to a bunch of non-matching values (1, 2, 3, ...) and then check that all the invocations of the same instruction gave the same value. If you do this, maybe make it a follow-up patch -- see other email.