Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp539919pxb; Fri, 13 Aug 2021 00:14:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyr5HrCpGRVRQxP8mkziOWf9C+scVkeLtkgbddtzIrhiisS87H/jSiNAm4KQiW5z6TDA+cP X-Received: by 2002:a05:6e02:13f0:: with SMTP id w16mr807010ilj.268.1628838892248; Fri, 13 Aug 2021 00:14:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628838892; cv=none; d=google.com; s=arc-20160816; b=bhGG5ZgYO/JiGeBaZw+6totrdwe5WqjUU2pjGD+KGzdCNzyseQsXb9a1Fz2W0PKmei 6+yiTOYlTWix0V+xe8cpq5YjSEwhMdMp6oc199KLFFQkQxTTPEFrnUxDMuZ5FUxodJPf Qe5Fcf3KZBfeWQcpjNjca+GmLWp2IX97OKGuyZfjRTkaBMYUiuz10H6Af7J3hxUqI495 UVrInZbG/fTerUGBq3ReJt59BK+eFzlFwTbS3qn+IlpOtAjk0unOqgXzGvsFo9JTYXIj WxDqw7xWChxKmddsGRdODXtXm8MMjd1XqsBHaBcbt6zwpja6Sxf0deavw1Shnayyl5di +tFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Na61p0whGR1uV8+GWb5lTvOwW2DcHuUQ9yjAwPQAWmc=; b=EcZSu5hVM3OcFxZoZ9sOyskPbvZd2rI0EDcFE82Ydk8DaE0cf5LQnO0gVpIRLr/pJ5 DrAriWkbmuIXKRt6QXCGwpyyPSSqIbtCKyJgChmvOS8rR7NQNpmoxfppjEdtm0j8l3pm n5uyFwKQxZ+YSkwlLOW6sMhImcB7qwJnO2SvatoNmIJCtbAtjv2oRBsOUOhfdcdFulIp pf/otvpCEcUcHxBZerTtWRJ3AK7kH+8qVL/acuQq2piBNNRhkOldTJRvVnzLiKt5tkrf WuAlgna3Q1IMU26XuY+on/X2SPWdoLLMClYelxP37tMKj92ZOvQu0UjfIc5WX6hPsIvr C4OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b="W3Y/bJyJ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k34si720444jav.61.2021.08.13.00.14.42; Fri, 13 Aug 2021 00:14:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b="W3Y/bJyJ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239305AbhHMHNC (ORCPT + 99 others); Fri, 13 Aug 2021 03:13:02 -0400 Received: from forward2-smtp.messagingengine.com ([66.111.4.226]:57007 "EHLO forward2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239273AbhHMHMv (ORCPT ); Fri, 13 Aug 2021 03:12:51 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailforward.nyi.internal (Postfix) with ESMTP id 6F3C5194082F; Fri, 13 Aug 2021 03:12:21 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 13 Aug 2021 03:12:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=Na61p0whGR1uV8+GWb5lTvOwW2DcHuUQ9yjAwPQAWmc=; b=W3Y/bJyJ s/TaP4kL5tof0EPODzquOwz633HBOZLRNMSEm/Hq2HImr6tFhslaY/U3zwWmyILZ FawhNfKFIp4eDAqFglzeShF7uuEoVqRmuTRrD7vyHkJpLK+bqvZIM1fBNmANKZfo FZ3sbWG6P0txP3Vd71oQIDCLFkY72Ixd32qAVXSDgnQhFOEhnJXRdo00XvlX347p jEh6R5MngjM82+xjpMYeefIMpiORG4nRH/Irn8O9mqmthLEUQ+XYALChaPD5Qwk9 PRE8ZB7eHKHOGfUGmoaxdMp8Sd6ZQ1O9PxLuSuNpGMZJEqeyRt+JZEWN1T8FMMdw QaCtEmcXB6v9yw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrkeeggdduudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghvihgu ucfgughmohhnughsohhnuceouggrvhhiugdrvggumhhonhgushhonhesohhrrggtlhgvrd gtohhmqeenucggtffrrghtthgvrhhnpedufeetjefgfefhtdejhfehtdfftefhteekhefg leehfffhiefhgeelgfejtdehkeenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmh epmhgrihhlfhhrohhmpegurghvihgurdgvughmohhnughsohhnsehorhgrtghlvgdrtgho mh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 13 Aug 2021 03:12:19 -0400 (EDT) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 8c26ee67; Fri, 13 Aug 2021 07:12:12 +0000 (UTC) From: David Edmondson To: linux-kernel@vger.kernel.org Cc: Jim Mattson , Borislav Petkov , Paolo Bonzini , Vitaly Kuznetsov , "H. Peter Anvin" , Thomas Gleixner , Wanpeng Li , Ingo Molnar , Sean Christopherson , Joerg Roedel , David Matlack , x86@kernel.org, kvm@vger.kernel.org, David Edmondson Subject: [PATCH v4 4/4] KVM: x86: SGX must obey the KVM_INTERNAL_ERROR_EMULATION protocol Date: Fri, 13 Aug 2021 08:12:11 +0100 Message-Id: <20210813071211.1635310-5-david.edmondson@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210813071211.1635310-1-david.edmondson@oracle.com> References: <20210813071211.1635310-1-david.edmondson@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When passing the failing address and size out to user space, SGX must ensure not to trample on the earlier fields of the emulation_failure sub-union of struct kvm_run. Signed-off-by: David Edmondson --- arch/x86/kvm/vmx/sgx.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/vmx/sgx.c b/arch/x86/kvm/vmx/sgx.c index 6693ebdc0770..35e7ec91ae86 100644 --- a/arch/x86/kvm/vmx/sgx.c +++ b/arch/x86/kvm/vmx/sgx.c @@ -53,11 +53,9 @@ static int sgx_get_encls_gva(struct kvm_vcpu *vcpu, unsigned long offset, static void sgx_handle_emulation_failure(struct kvm_vcpu *vcpu, u64 addr, unsigned int size) { - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; - vcpu->run->internal.ndata = 2; - vcpu->run->internal.data[0] = addr; - vcpu->run->internal.data[1] = size; + uint64_t data[2] = { addr, size }; + + __kvm_prepare_emulation_failure_exit(vcpu, data, ARRAY_SIZE(data)); } static int sgx_read_hva(struct kvm_vcpu *vcpu, unsigned long hva, void *data, @@ -112,9 +110,7 @@ static int sgx_inject_fault(struct kvm_vcpu *vcpu, gva_t gva, int trapnr) * but the error code isn't (yet) plumbed through the ENCLS helpers. */ if (trapnr == PF_VECTOR && !boot_cpu_has(X86_FEATURE_SGX2)) { - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; - vcpu->run->internal.ndata = 0; + kvm_prepare_emulation_failure_exit(vcpu); return 0; } @@ -155,9 +151,7 @@ static int __handle_encls_ecreate(struct kvm_vcpu *vcpu, sgx_12_0 = kvm_find_cpuid_entry(vcpu, 0x12, 0); sgx_12_1 = kvm_find_cpuid_entry(vcpu, 0x12, 1); if (!sgx_12_0 || !sgx_12_1) { - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; - vcpu->run->internal.ndata = 0; + kvm_prepare_emulation_failure_exit(vcpu); return 0; } -- 2.30.2