From nobody Wed May 1 18:17:40 2024 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 715E0C4332F for ; Fri, 30 Sep 2022 23:31:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232029AbiI3Xbr (ORCPT ); Fri, 30 Sep 2022 19:31:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231521AbiI3Xbi (ORCPT ); Fri, 30 Sep 2022 19:31:38 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35CB915349C for ; Fri, 30 Sep 2022 16:31:37 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id n1-20020a170902f60100b00179c0a5c51fso4108261plg.7 for ; Fri, 30 Sep 2022 16:31:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date; bh=R0RgZ91roMSEBPJsrvjvkDfFam5SN/lgMQRJiTuvmqc=; b=OuDkBTC/7/+wwp2oA6nxhc4qsGi9j4lxh48P9BTwteM1QHrh7U4pxZDP+3KMRH3jUl mjhclAQ6XSJ2qFHly66CmaJLnpiAI7wlkU9rYa1am2YMkGHiqK4BH9ZFSq48K+utrA2B K2KceinGHtClDe2GunKXJyoYY1dmN8fgrpVRLgnLMu8ACJkcnYgZfAhBh6T6zJu81vrN CpyGExB6M9QBwk/KAxy/F/ohhgXa67cT4YW7ArZXhMiJXyjUvxA7ebCVuwzEH4vewrEI nEEUW0ls+ygPHQUjV6V06eqDeBzB9ejojf6Hr3JagIFUtspGghQ9UbIs8eHoG4rTU+y3 XGzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date; bh=R0RgZ91roMSEBPJsrvjvkDfFam5SN/lgMQRJiTuvmqc=; b=g3912VhsNbbIYaCsJqUzs726e99fhyoCGCL1kPLyzEcvcHfwpkQgmm0PTVUKhl1bSg TnseZEbncZZ7NdeHGbEiVcUGT5mGQDbgel9F+RRwpK4HVS1Iq09VVDIc5EV2Mc/MR2Cf /yzguXWyCBig9dgrF5mY9IH3ZEcRWzxYripn2bay++rlgl+cObYCvb6O2XS6ApSDNuKT YYL3jU+o526blqB2cYiDJd7jNqv6vtdTQko0e5LYdtbFg06CeOTi7VF87sB+xQQQGYBq WLu/eaDuu3U/r+BhgfmanmLtJAOL8G8l+E1bI7PSoCn0S5uD9U/AP/bsgnoKIYAPy1hL lK1w== X-Gm-Message-State: ACrzQf0WLGUobPPv7TgLZIo7ZITAcp9HBZfxOhugj2vu4Bp/hrLrsEGQ LP0jCCJmJ5tz0MG+IJsYqzyHgKEI+ZY= X-Google-Smtp-Source: AMsMyM723OxHhFpusATWVmoaapfvZt1if9qgEY43yn60482Rm7Q/zG9hQv1CmWYT9CI7gNWznyfx2vRR7Z4= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90a:c986:b0:205:f08c:a82b with SMTP id w6-20020a17090ac98600b00205f08ca82bmr498120pjt.1.1664580696502; Fri, 30 Sep 2022 16:31:36 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 30 Sep 2022 23:31:32 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20220930233132.1723330-1-seanjc@google.com> Subject: [PATCH] KVM: VMX: Resume guest immediately when injecting #GP on ECREATE From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kai Huang Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Resume the guest immediately when injecting a #GP on ECREATE due to an invalid enclave size, i.e. don't attempt ECREATE in the host. The #GP is a terminal fault, e.g. skipping the instruction if ECREATE is successful would result in KVM injecting #GP on the instruction following ECREATE. Fixes: 70210c044b4e ("KVM: VMX: Add SGX ENCLS[ECREATE] handler to enforce C= PUID restrictions") Cc: stable@vger.kernel.org Cc: Kai Huang Signed-off-by: Sean Christopherson Reviewed-by: Kai Huang --- Effectively compile tested only, found by inspection when auditing use of kvm_skip_emulated_instruction(). arch/x86/kvm/vmx/sgx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/sgx.c b/arch/x86/kvm/vmx/sgx.c index 8f95c7c01433..b12da2a6dec9 100644 --- a/arch/x86/kvm/vmx/sgx.c +++ b/arch/x86/kvm/vmx/sgx.c @@ -182,8 +182,10 @@ static int __handle_encls_ecreate(struct kvm_vcpu *vcp= u, /* Enforce CPUID restriction on max enclave size. */ max_size_log2 =3D (attributes & SGX_ATTR_MODE64BIT) ? sgx_12_0->edx >> 8 : sgx_12_0->edx; - if (size >=3D BIT_ULL(max_size_log2)) + if (size >=3D BIT_ULL(max_size_log2)) { kvm_inject_gp(vcpu, 0); + return 1; + } =20 /* * sgx_virt_ecreate() returns: base-commit: c59fb127583869350256656b7ed848c398bef879 --=20 2.38.0.rc1.362.ged0d419d3c-goog