From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web10.5879.1624959097431247827 for ; Tue, 29 Jun 2021 02:31:37 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Nv7Au6WB; spf=pass (domain: redhat.com, ip: 216.205.24.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624959096; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a7KttuMooYoyaluD3a6FdLr1c7/+40TEBVNRIEVxZl8=; b=Nv7Au6WBXqqnDUR+oxX3Qt8vQH2fKIDURmwLxmRd3SBDWjpuuFTdrrjJnj4lSJaQyqqkXk qUIy4lnSVeAtnQLXTWTyc4TICNT3V1fz80Hgm8tgZf/wKcfBZjadYd0gUdhfAPmD5RspH5 dlDQSjInLzbvYMLCU9Fpw1rNsDbC318= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-355-10_jmKPaPVGecN8qLYrrtQ-1; Tue, 29 Jun 2021 05:31:34 -0400 X-MC-Unique: 10_jmKPaPVGecN8qLYrrtQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 891FB804140; Tue, 29 Jun 2021 09:31:33 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-158.ams2.redhat.com [10.36.114.158]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4163A5C1D1; Tue, 29 Jun 2021 09:31:32 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v3 2/5] OvmfPkg/X86QemuLoadImageLib: plug cmdline blob leak on success To: devel@edk2.groups.io, dovmurik@linux.ibm.com Cc: Ard Biesheuvel , Jordan Justen , James Bottomley , Tobin Feldman-Fitzthum References: <20210628105110.379951-1-dovmurik@linux.ibm.com> <20210628105110.379951-3-dovmurik@linux.ibm.com> From: "Laszlo Ersek" Message-ID: <2b77233f-5d4b-7f72-5c6b-a6153b31170d@redhat.com> Date: Tue, 29 Jun 2021 11:31:30 +0200 MIME-Version: 1.0 In-Reply-To: <20210628105110.379951-3-dovmurik@linux.ibm.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 06/28/21 12:51, Dov Murik wrote: > When QemuLoadKernelImage() ends successfully, the command-line blob is > not freed, even though it is not used elsewhere (its content is already > copied to KernelLoadedImage->LoadOptions). The memory leak bug was > introduced in commit 7c47d89003a6 ("OvmfPkg: implement QEMU loader > library for X86 with legacy fallback", 2020-03-05). > > Cc: Ard Biesheuvel > Cc: Jordan Justen > Cc: James Bottomley > Cc: Tobin Feldman-Fitzthum > Reported-by: Laszlo Ersek > Fixes: 7c47d89003a6f8f7f6f0ce8ca7d3e87c630d14cc > Signed-off-by: Dov Murik > --- > OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c b/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c > index 1177582ab051..6b1e7e649014 100644 > --- a/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c > +++ b/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c > @@ -446,14 +446,16 @@ QemuLoadKernelImage ( > } > > *ImageHandle = KernelImageHandle; > - return EFI_SUCCESS; > + Status = EFI_SUCCESS; > > FreeCommandLine: > if (CommandLineSize > 0) { > FreePool (CommandLine); > } > UnloadImage: > - gBS->UnloadImage (KernelImageHandle); > + if (EFI_ERROR (Status)) { > + gBS->UnloadImage (KernelImageHandle); > + } > > return Status; > } > Reviewed-by: Laszlo Ersek