Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752594AbdFPQkY (ORCPT ); Fri, 16 Jun 2017 12:40:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47198 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750827AbdFPQkW (ORCPT ); Fri, 16 Jun 2017 12:40:22 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D1AE9C0567B2 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D1AE9C0567B2 Subject: Re: [RFC] KVM: SVM: do not drop VMCB CPL to 0 if SS is not present To: Andy Lutomirski Cc: Roman Penyaev , Mikhail Sennikovskii , Gleb Natapov , kvm list , "linux-kernel@vger.kernel.org" References: From: Paolo Bonzini Message-ID: <177c5635-ba96-c3e1-9eba-223ce5800f49@redhat.com> Date: Fri, 16 Jun 2017 18:40:18 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 16 Jun 2017 16:40:22 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1661 Lines: 40 On 15/06/2017 23:44, Andy Lutomirski wrote: > On Tue, May 30, 2017 at 9:05 AM, Paolo Bonzini wrote: >> On 30/05/2017 17:58, Roman Penyaev wrote: >>> We will have CPL in var->dpl, and it seems ok. All we need is not >>> to lose it on the way kernel->userspace->kernel. >> >> You're right. So what do you think of the other suggestion (svm.c >> doesn't clear attributes for unusable registers, QEMU only clears P for >> unusable registers)? > > AMD CPUs really allow setting RPL in MSR_*STAR to something other than > 3 and then blindly copy the result to SS.DPL when SYSRET happens? > Ugh! For AMD, "a data-segment-descriptor DPL field is ignored in 64-bit mode" (4.8.2). This is unlike Intel, where SS.DPL is the CPL. After SYSRET, CPL is always 3, even if CS.RPL != 3. > Alternatively, is there ever a case where CPL == 3, SS.DPL != 3 and > non-root code can observe the fact that SS.DPL != 3? If not, maybe > KVM could just change SS.DPL to 3 whenever it reads out SS if CPL == > 3. Then CPL really could live in the SS state even on SVM. Currently that's almost what happens, except the "migration" of the CPL field into SS.DPL only happens when going through QEMU. > In other > words, if a weird guest forces SS.RPL ! = 3 by programming garbage > into *STAR and doing SYSRET, could that guest tell the difference if > we non-deterministically changed SS.DPL back to 3 out from under it? > Or is there some nasty case in which SS.DPL == 0, CPL == 3, SS is > valid and you're in compat mode, and you expect stack access to fail > because SS.DPL < CPL? No, any case where STAR is programmed with RPL != 3 is garbage. Paolo