Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965022AbcKKUvt (ORCPT ); Fri, 11 Nov 2016 15:51:49 -0500 Received: from smtp48.i.mail.ru ([94.100.177.108]:46062 "EHLO smtp48.i.mail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964955AbcKKUvq (ORCPT ); Fri, 11 Nov 2016 15:51:46 -0500 X-Greylist: delayed 129526 seconds by postgrey-1.27 at vger.kernel.org; Fri, 11 Nov 2016 15:51:45 EST Subject: Re: [PATCH 0/4] x86: enable User-Mode Instruction Prevention To: Ricardo Neri References: <1478585533-19406-1-git-send-email-ricardo.neri-calderon@linux.intel.com> <20161108131600.GF3117@twins.programming.kicks-ass.net> <1478665889.2533.8.camel@ranerica-desktop> <1478760361.2551.21.camel@ranerica-desktop> <1478837698.2542.9.camel@ranerica-desktop> Cc: Andy Lutomirski , Peter Zijlstra , Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , "linux-kernel@vger.kernel.org" , X86 ML , "linux-doc@vger.kernel.org" , Andy Lutomirski , Andrew Morton , Borislav Petkov , Brian Gerst , Chen Yucong , Chris Metcalf , Dave Hansen , Fenghua Yu , Huang Rui , Jiri Slaby , Jonathan Corbet , "Michael S . Tsirkin" , Paul Gortmaker , "Ravi V . Shankar" , Vlastimil Babka , Shuah Khan , linux-msdos@vger.kernel.org From: Stas Sergeev Message-ID: <0644b7c5-c122-e02b-95e8-b46382b3a866@list.ru> Date: Fri, 11 Nov 2016 23:51:25 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <1478837698.2542.9.camel@ranerica-desktop> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Authentication-Results: smtp48.i.mail.ru; auth=pass smtp.auth=stsp@list.ru smtp.mailfrom=stsp@list.ru X-E1FCDC63: F15A0F9D37996517F721AE1B88881F301E35E39F85F323EC X-E1FCDC64: 3A2A927C0AA5D9726A4316D85E4785F528E99E15DC9C6D99AC45E819BB183D41 X-Mailru-Sender: CD12F6D16A91A659C71BA12F480A5E3E448D542E1D3DA4153B61A4BC12D54B7D19D3E64FD9CE66A408D917D6130B1AFB X-Mras: OK Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2665 Lines: 53 11.11.2016 07:14, Ricardo Neri пишет: >> 10.11.2016 09:46, Ricardo Neri пишет: >>> I took a closer look at the dosemu code. It appears that it does not >>> purposely utilize SGDT to obtain the descriptor table while in vm86. It >>> does use SGDT (in protected mode) to emulate certain functionality such >>> as the Virtual xxx Driver. In such a case, UMIP needs to be disabled. >>> However, this code seems to be disabled [1]. >> Indeed. >> The code you've found, was copied from wine, because >> dosemu supports windows-3.1. But sgdt is in win32s part >> that is disabled in dosemu. It is however enabled in wine, or >> at least it was when I ported the VxD code from there. So you >> may want to ask wine devs if they still use sgdt and vm86. >> In dosemu, if we ever enable win32s support, we won't rely >> on sgdt. In fact, when some prot mode program under dosemu >> uses GDT selectors, in a fault handler we replace them with >> LDT selectors. > Actually, the SLDT instruction is also impacted by this feature. This We do not support programs that do SLDT. The "polite" programs use special DPMI API extension to get the selector that covers LDT. That allows us to manage an "ldt alias" - memory buffer where we emulate LDT by write-protecting it. If we ever support SLDT, we would very much like to trap it and provide the pointer to our alias. Some very old dos extenders for 286 may start to work with such change, that are currently unsupported. > feature, will cause a GP fault if the instructions SGDT, SLDT, SIDT, > SMSW or STR are executed with CPL > 0. Would this be a problem for > dosemu? I am only a bit unsure about SMSW; the rest should be safe. Maybe some odd prog would use SMSW to check for FPU? Or to check for v86 mode by checking the PE bit? I am sure this is very uncommon, and if we find such prog, we can add an emulation of that instruction. I am pretty sure no one would get sufficiently hurt, but there will likely be 1-2 bug reports in our tracker, because if something is possible, then some DOS prog did that. :) > The proposal now is to trap this GPU fault and give fake value > for these tables. If this fake value will be cooked up by the kernel without delivering the signal to dosemu process, then I don't see any problem at all. Of course you can provide the sane value for smsw. If that will go up to dosemu, then some coding may be needed on the user-space side. > This is good news. This means that we could go ahead and give a fake > pointer to the GDT and the other impacted tables? Definitely. What these fake tables will look like, btw? Will they somehow resemble the real ones? Visible to user-space?