Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933057AbdHVPXm (ORCPT ); Tue, 22 Aug 2017 11:23:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50136 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932946AbdHVPXk (ORCPT ); Tue, 22 Aug 2017 11:23:40 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 624BA806AD Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=david@redhat.com Subject: Re: [PATCH] fix memory leak on kvm_vm_ioctl_create_spapr_tce From: David Hildenbrand To: nixiaoming , agraf@suse.com, pbonzini@redhat.com, rkrcmar@redhat.com, benh@kernel.crashing.org, paulus@samba.org, mpe@ellerman.id.au Cc: kvm-ppc@vger.kernel.org, kvm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org References: <20170822142823.69425-1-nixiaoming@huawei.com> <95fe182a-fd21-77a1-33df-0e609c2845fd@redhat.com> Organization: Red Hat GmbH Message-ID: <8fd9a878-a8ce-5576-9a5c-1c221ff6ded7@redhat.com> Date: Tue, 22 Aug 2017 17:23:36 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <95fe182a-fd21-77a1-33df-0e609c2845fd@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 22 Aug 2017 15:23:40 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1363 Lines: 44 On 22.08.2017 17:15, David Hildenbrand wrote: > On 22.08.2017 16:28, nixiaoming wrote: >> miss kfree(stt) when anon_inode_getfd return fail >> so add check anon_inode_getfd return val, and kfree stt >> >> Signed-off-by: nixiaoming >> --- >> arch/powerpc/kvm/book3s_64_vio.c | 5 ++++- >> 1 file changed, 4 insertions(+), 1 deletion(-) >> >> diff --git a/arch/powerpc/kvm/book3s_64_vio.c b/arch/powerpc/kvm/book3s_64_vio.c >> index a160c14..a0b4459 100644 >> --- a/arch/powerpc/kvm/book3s_64_vio.c >> +++ b/arch/powerpc/kvm/book3s_64_vio.c >> @@ -341,8 +341,11 @@ long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm, >> >> mutex_unlock(&kvm->lock); >> >> - return anon_inode_getfd("kvm-spapr-tce", &kvm_spapr_tce_fops, >> + ret = anon_inode_getfd("kvm-spapr-tce", &kvm_spapr_tce_fops, >> stt, O_RDWR | O_CLOEXEC); >> + if (ret < 0) >> + goto fail; >> + return ret; >> >> fail: >> if (stt) { >> > > > stt has already been added to kvm->arch.spapr_tce_tables, so freeing it > is evil IMHO. I don't know that code, so I don't know if there is some > other place that will make sure that everything in > kvm->arch.spapr_tce_tables will properly get freed, even when no release > function has been called (kvm_spapr_tce_release). > If it is really not freed, than also kvm_put_kvm(stt->kvm) is missing. -- Thanks, David