From patchwork Thu Jan 2 02:20:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 11315247 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 02A1A138C for ; Thu, 2 Jan 2020 02:19:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D328121734 for ; Thu, 2 Jan 2020 02:19:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727538AbgABCTN (ORCPT ); Wed, 1 Jan 2020 21:19:13 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:8657 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727511AbgABCTN (ORCPT ); Wed, 1 Jan 2020 21:19:13 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 4477357E9891A67129BA; Thu, 2 Jan 2020 10:19:10 +0800 (CST) Received: from huawei.com (10.175.105.18) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.439.0; Thu, 2 Jan 2020 10:19:03 +0800 From: linmiaohe To: , , , , , , , , , , CC: , , , , Subject: [PATCH] KVM: SVM: Fix potential memory leak in svm_cpu_init() Date: Thu, 2 Jan 2020 10:20:40 +0800 Message-ID: <1577931640-29420-1-git-send-email-linmiaohe@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.175.105.18] X-CFilter-Loop: Reflected Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Miaohe Lin When kmalloc memory for sd->sev_vmcbs failed, we forget to free the page held by sd->save_area. Signed-off-by: Miaohe Lin Reviewed-by: Liran Alon Reviewed-by: Vitaly Kuznetsov --- arch/x86/kvm/svm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 8f1b715dfde8..89eb382e8580 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -1012,7 +1012,7 @@ static int svm_cpu_init(int cpu) r = -ENOMEM; sd->save_area = alloc_page(GFP_KERNEL); if (!sd->save_area) - goto err_1; + goto free_cpu_data; if (svm_sev_enabled()) { r = -ENOMEM; @@ -1020,14 +1020,16 @@ static int svm_cpu_init(int cpu) sizeof(void *), GFP_KERNEL); if (!sd->sev_vmcbs) - goto err_1; + goto free_save_area; } per_cpu(svm_data, cpu) = sd; return 0; -err_1: +free_save_area: + __free_page(sd->save_area); +free_cpu_data: kfree(sd); return r;