Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933101AbdHVPQA (ORCPT ); Tue, 22 Aug 2017 11:16:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34746 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932941AbdHVPP7 (ORCPT ); Tue, 22 Aug 2017 11:15:59 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 93A25155C1 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.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 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> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <95fe182a-fd21-77a1-33df-0e609c2845fd@redhat.com> Date: Tue, 22 Aug 2017 17:15:53 +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: <20170822142823.69425-1-nixiaoming@huawei.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.29]); Tue, 22 Aug 2017 15:15:59 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1202 Lines: 39 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). -- Thanks, David