Return-Path: Received: from mail.linutronix.de (146.0.238.70:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 02 Jul 2018 22:28:21 -0000 Received: from mx2.suse.de ([195.135.220.15] helo=mx1.suse.de) by Galois.linutronix.de with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fa7Iw-0005SS-PY for speck@linutronix.de; Tue, 03 Jul 2018 00:28:20 +0200 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C2A48AD55 for ; Mon, 2 Jul 2018 22:28:12 +0000 (UTC) Subject: [MODERATED] Re: ***UNCHECKED*** Re: KVM L1TF options References: <47ec967f-ae94-cb68-65ce-64d4aaf14609@suse.de> From: Alexander Graf Message-ID: Date: Tue, 3 Jul 2018 00:28:09 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="qBN97d01YbTtdS8VVI6GHdFgK9oyZiWf2"; protected-headers="v1" To: speck@linutronix.de List-ID: This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156) --qBN97d01YbTtdS8VVI6GHdFgK9oyZiWf2 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 03.07.18 00:02, speck for Anthony Liguori wrote: > speck for Alexander Graf writes: >> >> Howdy, >> >> I've been wondering for a while what options we (realistically) have t= o >> mitigate L1TF with SMT in the KVM case. So far I gathered: >> >> 1) Disable SMT >> 1.1) on boot >> 1.2) dynamically, magically >> >> I guess we all agree that while it's an easy option out, it's not >> necessarily the best user experience for mixed environments, where bot= h >> host Linux applications and guests are running. This typically happens= >> in any "secure" container environment, hyper-converged cloud, etc etc.= >> >> >> 2) Gang scheduling for vcpus, disallow non-kvm processes to run with k= vm >> >> This seems to be quite tricky to get right from what I gather. I >> remember IBM had similar approaches for HV KVM on PowerPC initially, b= ut >> eventually went with SMT1 on the host and SMTx in the guest, with KVM >> doing the ganging. >=20 > There are at least a couple implementations of this already but my > understanding is that mingo/tglx have pushed back on doing this. > Regardless, we plan on posting an implementation once the embargo lifts= =2E >=20 >> 3) Shadow page tables >> >> We lose quite some performance, but would be 100% safe. The biggest >> problem is that we degrade on single-core performance rather than >> overall system performance. >> >> Also with KPTI, shadow page tables started to perform much worse. >> >> >> -- >> >> >> So I've been wondering whether there is any other option: We really >> don't need the big shadow page table hammer. Instead, we can happily >> allow the guest to use nested pages during runtime as long as the page= >> tables it is using are sanitized. >> >> 4) EPT with PT sanitization >> >> We could map additional guest read only RAM in an unused window of the= >> guest physical address space as a page table cache. Then trap CR3 >> writes. On CR3 writes, check if we have a counter-page to the original= >> CR3 entry, point to our sanitized clone instead. Otherwise create one.= >> >> Then we can slowly propagate that clone similar to shadow page tables,= >> but we would never have to do the GPA->HVA->GPA dance. Instead, all we= >> need to do is check whether a PTE has the P bit set or not. If it does= , >> copy it. If it doesn't, just set the whole clone PTE to 0. >> >> The most annoying part about this approach is that we would need to >> implement A and D bits by hand, because a) the HW walker can not write= >> to the clone PTE because it's mapped read-only and b) we should >> propagate the bits immediately into the real PTE anyway. >> >> Another idea J=3DC3=3DB6rg came up with was that we could try to optim= ize the=3D >> >> sanitization even more using PML (Page Modification Log). Using that w= e >> know which pages the guest modified, so if we find a page in there tha= t >> we have in our sanitized cache, we can just redo that whole page in on= e g=3D >> o. >> >> What I'm not quite sure of yet are page invalidations. Is there >> something we can trap on for those? Otherwise we'd have to set all pag= e >> table pages to read-only in the EPT and that would end up very expensi= ve.=3D >> >> >> So what do people think about the idea? Does it sound doable? >=20 > You need to write protect all levels of the page table so you really do= > need to do full blown shadow paging, no? Well my hope was that we could get away without write protecting the levels and instead do things lazily with PML. Basically we could just scan the PML log on invlpg and mov cr3 for any page table changes and propagate them into the shadow copy automatically. > I'm not able to get my head around what gets simplified with this > approach. I simply think we can use techniques which people didn't consider useful to combine before, because EPT enabled CPUs didn't need to bother with shadowing pages. I also seem to remember that the memslot code showed up in my profiles back in the day quite a bit. We would only need that to the same level as with EPT, because we don't need to find the HVA in the shadowing case anymore. > I think there is also another thing needed: >=20 > 5) Secret hiding >=20 > Data cannot end up in the L1 cache unless it's in the virtual address > space. We can attempt to ensure that any guest secret is only present > in it's virtual address space and never in another guest's address > space. >=20 > This requires not carrying a kernel virtual address mapping for any > physical memory used by the guest but also some care in placing guest > register state and potentially device model state into a userspace va > instead of kernel memory as it is today. >=20 > It also requires stack scrubbing and a few other things. The advantage= > is that it avoids the L1 cache clearing. Doesn't that break when you have an in-kernel crypto driver like a LUKS encrypted hard drive? Also, I don't know if I understand all details of the vulnerability, but from what I gathered guest !P speculations actually end up going on the physical tags of the cache using the address bits of the GPTE as tag hints. So if a previous process 2 seconds ago happened to access a secret on that same core, you would potentially be able to see it inside your guest. I would love to have someone tell me that this is not true :). Alex --qBN97d01YbTtdS8VVI6GHdFgK9oyZiWf2--