From patchwork Fri Oct 14 07:55:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Wenlong X-Patchwork-Id: 13006738 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 B19A9C433FE for ; Fri, 14 Oct 2022 07:55:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230009AbiJNHzu (ORCPT ); Fri, 14 Oct 2022 03:55:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229733AbiJNHzs (ORCPT ); Fri, 14 Oct 2022 03:55:48 -0400 Received: from out0-140.mail.aliyun.com (out0-140.mail.aliyun.com [140.205.0.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37B2617FD51; Fri, 14 Oct 2022 00:55:46 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047209;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---.Pc1XjxL_1665734112; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.Pc1XjxL_1665734112) by smtp.aliyun-inc.com; Fri, 14 Oct 2022 15:55:12 +0800 From: "Hou Wenlong" To: kvm@vger.kernel.org Cc: Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Xu , linux-kernel@vger.kernel.org Subject: [PATCH] KVM: x86: Reduce refcount if single_open() fails in kvm_mmu_rmaps_stat_open() Date: Fri, 14 Oct 2022 15:55:11 +0800 Message-Id: X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Refcount is increased before calling single_open() in kvm_mmu_rmaps_stat_open(), If single_open() fails, refcount should be restored, otherwise the vm couldn't be destroyed. Fixes: 3bcd0662d66fd ("KVM: X86: Introduce mmu_rmaps_stat per-vm debugfs file") Signed-off-by: Hou Wenlong --- arch/x86/kvm/debugfs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c index cfed36aba2f7..412ed1b341fa 100644 --- a/arch/x86/kvm/debugfs.c +++ b/arch/x86/kvm/debugfs.c @@ -162,7 +162,12 @@ static int kvm_mmu_rmaps_stat_open(struct inode *inode, struct file *file) if (!kvm_get_kvm_safe(kvm)) return -ENOENT; - return single_open(file, kvm_mmu_rmaps_stat_show, kvm); + if (single_open(file, kvm_mmu_rmaps_stat_show, kvm)) { + kvm_put_kvm(kvm); + return -ENOMEM; + } + + return 0; } static int kvm_mmu_rmaps_stat_release(struct inode *inode, struct file *file)