From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web12.6165.1624962199503912658 for ; Tue, 29 Jun 2021 03:23:19 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dZm+8jbN; spf=pass (domain: redhat.com, ip: 170.10.133.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624962198; 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=IVuI1WfcSqWQfA3OjCUXuBEWFm13aokh7s+QQHd3RqM=; b=dZm+8jbNdYyKqhpGQE9Yar00lWdaiCuiPCMikt84wies+PgO5x8s2xP5o1LXHrmLqMdN27 v2ubdHQOT86AhduqMKKEUuDxGbbuwSNukdfGH49UdEyc1SpMFDuVd8oYqtnDsI/1CaT8EU td/K/Q9AeKTROeATVipdU2LpBsZEY7k= 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-258-toWdia5SNlamg7Gkfw4PWQ-1; Tue, 29 Jun 2021 06:23:17 -0400 X-MC-Unique: toWdia5SNlamg7Gkfw4PWQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DCB11804140; Tue, 29 Jun 2021 10:23:15 +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 639A560C0F; Tue, 29 Jun 2021 10:23:13 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v3 1/5] OvmfPkg/GenericQemuLoadImageLib: 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-2-dovmurik@linux.ibm.com> From: "Laszlo Ersek" Message-ID: <319138ff-a5ab-18c9-65df-6a43c03ef21f@redhat.com> Date: Tue, 29 Jun 2021 12:23:11 +0200 MIME-Version: 1.0 In-Reply-To: <20210628105110.379951-2-dovmurik@linux.ibm.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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 ddd2be6b0026 ("OvmfPkg: provide a generic > implementation of QemuLoadImageLib", 2020-03-05). > > Cc: Ard Biesheuvel > Cc: Jordan Justen > Cc: James Bottomley > Cc: Tobin Feldman-Fitzthum > Reported-by: Laszlo Ersek > Fixes: ddd2be6b0026abcd0f819b3915fc80c3de81dd62 > Signed-off-by: Dov Murik > --- > OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c b/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c > index 114db7e8441f..8a29976ae172 100644 > --- a/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c > +++ b/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c > @@ -193,14 +193,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; > } > using an aarch64 guest, Tested-by: Laszlo Ersek