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.web08.6541.1624965532416834036 for ; Tue, 29 Jun 2021 04:18:52 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DXQ3ReC4; 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=1624965531; 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=BIZUwelpXUxEihcK2KgPdFf9YelckOvj3JYlEMsnkq0=; b=DXQ3ReC4zelgvlXWY1mH4RImNPz2wHPTZUm2w7CNxKTp+fxwuMGJoBt13CHJdMJe/bOvvk 0cZY8X1YnT0e5kGWnmXFRRXZCHflmIQS4e9Dba/Vp9evY32bvkaofwii9xHJpDtyA3QhlZ LCyD9DQ6zLBR5wJg9d4zF7iV6BQIm60= 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-339-f2A6_tHNOdi9AufAdaVH5A-1; Tue, 29 Jun 2021 07:18:50 -0400 X-MC-Unique: f2A6_tHNOdi9AufAdaVH5A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 77898800D55; Tue, 29 Jun 2021 11:18:48 +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 F3D5D5DD68; Tue, 29 Jun 2021 11:18:46 +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: <364b6a96-3d06-f478-7e8c-4e46936e6aad@redhat.com> Date: Tue, 29 Jun 2021 13:18:45 +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.14 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; > } > Tested-by: Laszlo Ersek