Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A2A0C433EF for ; Mon, 22 Nov 2021 17:03:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235420AbhKVRGu (ORCPT ); Mon, 22 Nov 2021 12:06:50 -0500 Received: from smtp-out1.suse.de ([195.135.220.28]:39444 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234435AbhKVRGt (ORCPT ); Mon, 22 Nov 2021 12:06:49 -0500 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5444221709; Mon, 22 Nov 2021 17:03:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1637600621; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4rRkvJNhAxWx1zyxF3tUb1zr1nvSxZ9nWkvMm51WNrQ=; b=cKEZqdfqMr3kLw1vFZhwmecn+FJayjamhLA9XKKumc4O5xj1x5AWqQ7f9UJlwxi0ST9Ja3 dMifHwzdNrvmUA+5IUc45aw0vgZ6z8l/SV11lEuU/MjptXYlAU6jSQgZpsQgFLREMaj7sx k2mcCM5Doj/4X41chTeiRZ0ENf7wXR4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1637600621; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4rRkvJNhAxWx1zyxF3tUb1zr1nvSxZ9nWkvMm51WNrQ=; b=H3f6ATUtgp03kEO0DJKZkjPwUUL6XgXB+JBO7QX9kELJzZDpaa1Cb11GOOX+s/Z/vkD2M2 HKhNCExz+g0iSWAw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C349113B44; Mon, 22 Nov 2021 17:03:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gnD3LmzNm2F6QQAAMHmgww (envelope-from ); Mon, 22 Nov 2021 17:03:40 +0000 Message-ID: <6e67f74a-fb4e-fda4-9583-dad28f14ed3a@suse.cz> Date: Mon, 22 Nov 2021 18:03:40 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.1 Subject: Re: [PATCH Part2 v5 00/45] Add AMD Secure Nested Paging (SEV-SNP) Hypervisor Support Content-Language: en-US To: Brijesh Singh , Peter Gonda Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , "Kirill A . Shutemov" , Andi Kleen , tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com References: <20210820155918.7518-1-brijesh.singh@amd.com> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/22/21 16:23, Brijesh Singh wrote: > Hi Peter, > > On 11/12/21 9:43 AM, Peter Gonda wrote: >> Hi Brijesh,, >> >> One high level discussion I'd like to have on these SNP KVM patches. >> >> In these patches (V5) if a host userspace process writes a guest >> private page a SIGBUS is issued to that process. If the kernel writes >> a guest private page then the kernel panics due to the unhandled RMP >> fault page fault. This is an issue because not all writes into guest >> memory may come from a bug in the host. For instance a malicious or >> even buggy guest could easily point the host to writing a private page >> during the emulation of many virtual devices (virtio, NVMe, etc). For >> example if a well behaved guests behavior is to: start up a driver, >> select some pages to share with the guest, ask the host to convert >> them to shared, then use those pages for virtual device DMA, if a >> buggy guest forget the step to request the pages be converted to >> shared its easy to see how the host could rightfully write to private >> memory. I think we can better guarantee host reliability when running >> SNP guests without changing SNP’s security properties. >> >> Here is an alternative to the current approach: On RMP violation (host >> or userspace) the page fault handler converts the page from private to >> shared to allow the write to continue. This pulls from s390’s error >> handling which does exactly this. See ‘arch_make_page_accessible()’. >> Additionally it adds less complexity to the SNP kernel patches, and >> requires no new ABI. >> >> In the current (V5) KVM implementation if a userspace process >> generates an RMP violation (writes to guest private memory) the >> process receives a SIGBUS. At first glance, it would appear that >> user-space shouldn’t write to private memory. However, guaranteeing >> this in a generic fashion requires locking the RMP entries (via locks >> external to the RMP). Otherwise, a user-space process emulating a >> guest device IO may be vulnerable to having the guest memory >> (maliciously or by guest bug) converted to private while user-space >> emulation is happening. This results in a well behaved userspace >> process receiving a SIGBUS. >> >> This proposal allows buggy and malicious guests to run under SNP >> without jeopardizing the reliability / safety of host processes. This >> is very important to a cloud service provider (CSP) since it’s common >> to have host wide daemons that write/read all guests, i.e. a single >> process could manage the networking for all VMs on the host. Crashing >> that singleton process kills networking for all VMs on the system. >> > Thank you for starting the thread; based on the discussion, I am keeping the > current implementation as-is and *not* going with the auto conversion from > private to shared. To summarize what we are doing in the current SNP series: > > - If userspace accesses guest private memory, it gets SIGBUS. So, is there anything protecting host userspace processes from malicious guests? > - If kernel accesses[*] guest private memory, it does panic. > > [*] Kernel consults the RMP table for the page ownership before the access. > If the page is shared, then it uses the locking mechanism to ensure that a > guest will not be able to change the page ownership while kernel has it mapped. > > thanks >