Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2016962pxa; Mon, 3 Aug 2020 05:29:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqBVs5hUDgYOwyEX9KMQM0k5CwU6L04qoMiByXIjdaFDfiLMO6tsqWLO86KdtkIrm9RwV9 X-Received: by 2002:aa7:d84d:: with SMTP id f13mr14948573eds.155.1596457759481; Mon, 03 Aug 2020 05:29:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596457759; cv=none; d=google.com; s=arc-20160816; b=pHtdBLr+UFueR2G/bWKG7xj7ZZa0h4Sof0dSNWEn0RdZlr3XLKYBixRkQOoU2pWZvd e8jv14CxVIyr8OU080vuWzb+SwntrApODCeSGLxJ4yBEVSVuFLWtYwcoxuaQ+xns1S78 kxzsAe3uL1dSghllQ+4vxus+7uic/ElXuFF1pWUZzEetfzrWVsVPmDTS5im41X707iXo huMknh6nXHq04BUdEyWiaU9cg2yQH0+mPEN8nJ9u1kxt44nsahq+1S/wfyEgz6zEk8L/ 0kL9ZeagaTv193p80LzTPrVWnD+5w5xs3ZdZ01vuVbgqSvhjYh6LIMrcN40zljjZjJqr thIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=nYRg6ZrnL08Msvga5S2mZ6ubjULjtfiGNMUPQBA4ZSo=; b=bc5hlehrE3U4GgTt+VkNV+QyF42Ur4dhO8hTBfMLixVwsN4kCoriYAi5rDdSC1dc9W YcQ4r7+QrbJzmsPSteXg5jU1hOs0giRE7rQZ0VlysLY5oF3K0WGPasLvd66nnI8OVCc5 IEdKtWU2+IN0b5FzefPRY9pUrN4r/IWHTDihbQ1WajPOCHNmxN7T0HdF00LOP9E4+qi8 a2V5DeQEIBTdWvfP/F7F1xb9Odhq06xT7XSOS5cTTtH9IGKRf5dYBwC4+5seck/DRlWN tZOtFtCNDQDMGH2FnM24jpAAMs808Ew44dRkDA/hDAra6sRgdtzUjpUmO8w6NPkI5iqd QzuA== ARC-Authentication-Results: i=1; mx.google.com; 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=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c3si9848821edm.469.2020.08.03.05.28.57; Mon, 03 Aug 2020 05:29:19 -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; 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=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728586AbgHCM1m (ORCPT + 99 others); Mon, 3 Aug 2020 08:27:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728546AbgHCM11 (ORCPT ); Mon, 3 Aug 2020 08:27:27 -0400 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B8A3C061756; Mon, 3 Aug 2020 05:27:27 -0700 (PDT) Received: by theia.8bytes.org (Postfix, from userid 1000) id 1F2E74CB; Mon, 3 Aug 2020 14:27:24 +0200 (CEST) From: Joerg Roedel To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Tom Lendacky , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Joerg Roedel Subject: [PATCH v3 1/4] KVM: SVM: nested: Don't allocate VMCB structures on stack Date: Mon, 3 Aug 2020 14:27:05 +0200 Message-Id: <20200803122708.5942-2-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200803122708.5942-1-joro@8bytes.org> References: <20200803122708.5942-1-joro@8bytes.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel Do not allocate a vmcb_control_area and a vmcb_save_area on the stack, as these structures will become larger with future extenstions of SVM and thus the svm_set_nested_state() function will become a too large stack frame. Signed-off-by: Joerg Roedel --- arch/x86/kvm/svm/nested.c | 47 +++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 61378a3c2ce4..051623b652da 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -1061,10 +1061,14 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, struct vmcb *hsave = svm->nested.hsave; struct vmcb __user *user_vmcb = (struct vmcb __user *) &user_kvm_nested_state->data.svm[0]; - struct vmcb_control_area ctl; - struct vmcb_save_area save; + struct vmcb_control_area *ctl; + struct vmcb_save_area *save; + int ret; u32 cr0; + BUILD_BUG_ON(sizeof(struct vmcb_control_area) + sizeof(struct vmcb_save_area) > + KVM_STATE_NESTED_SVM_VMCB_SIZE); + if (kvm_state->format != KVM_STATE_NESTED_FORMAT_SVM) return -EINVAL; @@ -1096,13 +1100,22 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, return -EINVAL; if (kvm_state->size < sizeof(*kvm_state) + KVM_STATE_NESTED_SVM_VMCB_SIZE) return -EINVAL; - if (copy_from_user(&ctl, &user_vmcb->control, sizeof(ctl))) - return -EFAULT; - if (copy_from_user(&save, &user_vmcb->save, sizeof(save))) - return -EFAULT; - if (!nested_vmcb_check_controls(&ctl)) - return -EINVAL; + ret = -ENOMEM; + ctl = kzalloc(sizeof(*ctl), GFP_KERNEL); + save = kzalloc(sizeof(*save), GFP_KERNEL); + if (!ctl || !save) + goto out_free; + + ret = -EFAULT; + if (copy_from_user(ctl, &user_vmcb->control, sizeof(*ctl))) + goto out_free; + if (copy_from_user(save, &user_vmcb->save, sizeof(*save))) + goto out_free; + + ret = -EINVAL; + if (!nested_vmcb_check_controls(ctl)) + goto out_free; /* * Processor state contains L2 state. Check that it is @@ -1110,15 +1123,15 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, */ cr0 = kvm_read_cr0(vcpu); if (((cr0 & X86_CR0_CD) == 0) && (cr0 & X86_CR0_NW)) - return -EINVAL; + goto out_free; /* * Validate host state saved from before VMRUN (see * nested_svm_check_permissions). * TODO: validate reserved bits for all saved state. */ - if (!(save.cr0 & X86_CR0_PG)) - return -EINVAL; + if (!(save->cr0 & X86_CR0_PG)) + goto out_free; /* * All checks done, we can enter guest mode. L1 control fields @@ -1127,15 +1140,21 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, * contains saved L1 state. */ copy_vmcb_control_area(&hsave->control, &svm->vmcb->control); - hsave->save = save; + hsave->save = *save; svm->nested.vmcb = kvm_state->hdr.svm.vmcb_pa; - load_nested_vmcb_control(svm, &ctl); + load_nested_vmcb_control(svm, ctl); nested_prepare_vmcb_control(svm); out_set_gif: svm_set_gif(svm, !!(kvm_state->flags & KVM_STATE_NESTED_GIF_SET)); - return 0; + + ret = 0; +out_free: + kfree(save); + kfree(ctl); + + return ret; } struct kvm_x86_nested_ops svm_nested_ops = { -- 2.17.1