Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp48571lqh; Mon, 6 May 2024 10:50:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU/aPgQ8/1cPUdem9F6ggnb2TFzeR5BIxjku1TIhKbtK82Q2r8qHxXcnOuBk6MYnXaxRqio7yTqlGBARB4I1icy5egm9XvZamg9O9qUzw== X-Google-Smtp-Source: AGHT+IG6n6CjrXtLhXqjBI2ccoIUMo3YjV7w8Dju62z60KpTaYi96S2zw8tG7YvBk7jHUvgVMFr4 X-Received: by 2002:a17:906:6d5:b0:a59:a3ef:21fa with SMTP id v21-20020a17090606d500b00a59a3ef21famr4839833ejb.51.1715017834222; Mon, 06 May 2024 10:50:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715017834; cv=pass; d=google.com; s=arc-20160816; b=XDNypHGUZ0UHs9kFsvWflQCsLOCvH7yXrIZLUnXpE1X8s8xtmhEpqznpElnLnXAl0A y7EZs4zdy5GFYaAe2SuyDSMHHd5M9iqAIyYga/pOqDEHuO5nKR5pLg0EBLX5ooZnnMgM wb4IY6K8snvufL3bOCSdRNX1HkPlxXxU0SsSAYS1LtwncWULgFBz/Xlm+FwjVydoPeq+ 11Ro0zjfQCuXekUDOq5or1rfULuzsY1kITnBADfwVKExsNhHSB3Ueh9kg4yweqLB1FM9 nwBdHEzy3+MxO/cm6OaT0nvGGfTUXNfKbdiILYCVGL72mwmgn1a395YRxOZr8uP56JXs TUFA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=jmUXpKCmmv8Zz5EczPWZ0N8pz/6hQl+4PrrdW35sJfY=; fh=lvMIpiBN3xB+1Rjfkd3U9YKJNpN+T+XUnO6WiUSQgYE=; b=FE3Er1VWxcoCKZtZhvBN39HEE4pIIPiHy2fVLkshY/P+3Lqs11MZOrahD3qv6g4Wuj lN0igca+QR5011BJjVUMi82+ArGrH1zUwcE3RwYY8xnOD1Z1YihU3JZ9qqljRmQWTksU SwlSOohxtqdz0fdD2nnMeGfe3y9JtfTURI48Kl5f6X5n/Xh3k6wKDrY8/LyeQis0UJIA oLvhfMzB0jrIqjAqrUeSa6ia16ftlg0a7W66+beMYeH6pwab3TPFM4TdA4f6OVdeUb15 N5dPjib2xrFs2eNRD8U5sDpZL8lG08/nybmwpPNgb9jRZdzpGk3SHSgc+braBKgK22W8 sQYw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=mGwJTwDH; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-170251-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170251-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id t17-20020a17090605d100b00a5583f81d2dsi5048378ejt.488.2024.05.06.10.50.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 10:50:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170251-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=mGwJTwDH; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-170251-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170251-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C46D81F22453 for ; Mon, 6 May 2024 17:50:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 37301158204; Mon, 6 May 2024 17:50:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="mGwJTwDH" Received: from smtp-42ad.mail.infomaniak.ch (smtp-42ad.mail.infomaniak.ch [84.16.66.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35A5E158845 for ; Mon, 6 May 2024 17:50:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=84.16.66.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715017823; cv=none; b=lAJhNDf1TRLcNO1ba8iDXz+IH8+ZHWdyuXBIjEfqGkl/wsBGOynQ8DRiLs+jC9AKg9oxT9C8loIi8kIcOI2J5Lg6L7xeWaRFrEq+DkqUXLFsEFH0aEuc6ONbDG5sO5dYub2pvn0JXdu2ISa/h285NIwtFZhJs0HLh+ly3JQJB7s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715017823; c=relaxed/simple; bh=FeafhCaExu57qsacTj62dWRUdrBXKjPBuLT9vOLipXU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=syR9yed0bkNRCfo5JOJziaTPOZ++DCScyTAzTZXoylrfVGD3MZywr54bC9liptGtS3mzQnPQPY6P8Jx6VVPvi6W1rSujr4bL9/3caxi4kxfjR+Qcu72tCioJGBzOUQM/Kr/NI0nMtLPQYy7FtgwUJxwULdmbmU2shpLWZWtIayE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net; spf=pass smtp.mailfrom=digikod.net; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b=mGwJTwDH; arc=none smtp.client-ip=84.16.66.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=digikod.net Received: from smtp-3-0001.mail.infomaniak.ch (smtp-3-0001.mail.infomaniak.ch [10.4.36.108]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4VY87s1JrnzP8k; Mon, 6 May 2024 19:50:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1715017816; bh=FeafhCaExu57qsacTj62dWRUdrBXKjPBuLT9vOLipXU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mGwJTwDHmCYyRVABfvivVlR645+s55YE3ikqtGU8J06uhEpc53bUE7Ls8lVECmSJY ZoGZR6nkUaCWIF86rf6UUOQ30vsnFTU+oyKVa5juk1cYq6aZPMMxOD7Adtf6s6Qe8Z /vj4j5MGtH+BC89lqOLDnwO6/+q161VQ+b28m63o= Received: from unknown by smtp-3-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4VY87p5F0GzB95; Mon, 6 May 2024 19:50:14 +0200 (CEST) Date: Mon, 6 May 2024 19:50:13 +0200 From: =?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?= To: Sean Christopherson Cc: Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Ingo Molnar , Kees Cook , Paolo Bonzini , Thomas Gleixner , Vitaly Kuznetsov , Wanpeng Li , Rick P Edgecombe , Alexander Graf , Angelina Vu , Anna Trikalinou , Chao Peng , Forrest Yuan Yu , James Gowans , James Morris , John Andersen , "Madhavan T . Venkataraman" , Marian Rotariu , Mihai =?utf-8?B?RG9uyJt1?= , =?utf-8?B?TmljdciZb3IgQ8OuyJt1?= , Thara Gopinath , Trilok Soni , Wei Liu , Will Deacon , Yu Zhang , =?utf-8?Q?=C8=98tefan_=C8=98icleru?= , dev@lists.cloudhypervisor.org, kvm@vger.kernel.org, linux-hardening@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, qemu-devel@nongnu.org, virtualization@lists.linux-foundation.org, x86@kernel.org, xen-devel@lists.xenproject.org Subject: Re: [RFC PATCH v3 3/5] KVM: x86: Add notifications for Heki policy configuration and violation Message-ID: <20240506.ohwe7eewu0oB@digikod.net> References: <20240503131910.307630-1-mic@digikod.net> <20240503131910.307630-4-mic@digikod.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Infomaniak-Routing: alpha On Fri, May 03, 2024 at 07:03:21AM GMT, Sean Christopherson wrote: > On Fri, May 03, 2024, Mickaël Salaün wrote: > > Add an interface for user space to be notified about guests' Heki policy > > and related violations. > > > > Extend the KVM_ENABLE_CAP IOCTL with KVM_CAP_HEKI_CONFIGURE and > > KVM_CAP_HEKI_DENIAL. Each one takes a bitmask as first argument that can > > contains KVM_HEKI_EXIT_REASON_CR0 and KVM_HEKI_EXIT_REASON_CR4. The > > returned value is the bitmask of known Heki exit reasons, for now: > > KVM_HEKI_EXIT_REASON_CR0 and KVM_HEKI_EXIT_REASON_CR4. > > > > If KVM_CAP_HEKI_CONFIGURE is set, a VM exit will be triggered for each > > KVM_HC_LOCK_CR_UPDATE hypercalls according to the requested control > > register. This enables to enlighten the VMM with the guest > > auto-restrictions. > > > > If KVM_CAP_HEKI_DENIAL is set, a VM exit will be triggered for each > > pinned CR violation. This enables the VMM to react to a policy > > violation. > > > > Cc: Borislav Petkov > > Cc: Dave Hansen > > Cc: H. Peter Anvin > > Cc: Ingo Molnar > > Cc: Kees Cook > > Cc: Madhavan T. Venkataraman > > Cc: Paolo Bonzini > > Cc: Sean Christopherson > > Cc: Thomas Gleixner > > Cc: Vitaly Kuznetsov > > Cc: Wanpeng Li > > Signed-off-by: Mickaël Salaün > > Link: https://lore.kernel.org/r/20240503131910.307630-4-mic@digikod.net > > --- > > > > Changes since v1: > > * New patch. Making user space aware of Heki properties was requested by > > Sean Christopherson. > > No, I suggested having userspace _control_ the pinning[*], not merely be notified > of pinning. > > : IMO, manipulation of protections, both for memory (this patch) and CPU state > : (control registers in the next patch) should come from userspace. I have no > : objection to KVM providing plumbing if necessary, but I think userspace needs to > : to have full control over the actual state. > : > : One of the things that caused Intel's control register pinning series to stall > : out was how to handle edge cases like kexec() and reboot. Deferring to userspace > : means the kernel doesn't need to define policy, e.g. when to unprotect memory, > : and avoids questions like "should userspace be able to overwrite pinned control > : registers". > : > : And like the confidential VM use case, keeping userspace in the loop is a big > : beneifit, e.g. the guest can't circumvent protections by coercing userspace into > : writing to protected memory. > > I stand by that suggestion, because I don't see a sane way to handle things like > kexec() and reboot without having a _much_ more sophisticated policy than would > ever be acceptable in KVM. > > I think that can be done without KVM having any awareness of CR pinning whatsoever. > E.g. userspace just needs to ability to intercept CR writes and inject #GPs. Off > the cuff, I suspect the uAPI could look very similar to MSR filtering. E.g. I bet > userspace could enforce MSR pinning without any new KVM uAPI at all. > > [*] https://lore.kernel.org/all/ZFUyhPuhtMbYdJ76@google.com OK, I had concern about the control not directly coming from the guest, especially in the case of pKVM and confidential computing, but I get you point. It should indeed be quite similar to the MSR filtering on the userspace side, except that we need another interface for the guest to request such change (i.e. self-protection). Would it be OK to keep this new KVM_HC_LOCK_CR_UPDATE hypercall but forward the request to userspace with a VM exit instead? That would also enable userspace to get the request and directly configure the CR pinning with the same VM exit.