From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.158.5]) by mx.groups.io with SMTP id smtpd.web10.9546.1624877476579167684 for ; Mon, 28 Jun 2021 03:51:16 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ibm.com header.s=pp1 header.b=lhmFkDWm; spf=pass (domain: linux.ibm.com, ip: 148.163.158.5, mailfrom: dovmurik@linux.ibm.com) Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15SAYiM8106234; Mon, 28 Jun 2021 06:51:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=ho952QhzP6gne8ECz/AbR9gMqDk4Hl9f1KsX7R4aVrE=; b=lhmFkDWmy8xbAZqE2+CvFGXQ140/CywLrPCoDIOvPW+fTs6PY0eKILV6QROkYr2LR57q MKVF+4lCmuFNu/5io8tD0uKnri3I8bW/UGvRNKWWUKZ6L5FRP+XbubZEE1St148tFMTe KpA7GrM1KucufJrzkOj0/jO5YGDfrMC6s+RvYqGogkgQpSRnvGlNUtIpq1ZMO0/s7Czt T4HaB1A30OACjCoU9GrDf3riVU7IlUB/xQsFZDTmCv77Ub3CNF6SokGUN5JqyYYqMAxo b/fMtGdB8D8hLQX7U3FZWjkkGFZk/wX1e92jEmg+Lm2OM/vCn+GHAOpm0/agAcfttgxL bw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 39fc1q9sqm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Jun 2021 06:51:15 -0400 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 15SAYjOr106353; Mon, 28 Jun 2021 06:51:15 -0400 Received: from ppma04wdc.us.ibm.com (1a.90.2fa9.ip4.static.sl-reverse.com [169.47.144.26]) by mx0b-001b2d01.pphosted.com with ESMTP id 39fc1q9sqe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Jun 2021 06:51:15 -0400 Received: from pps.filterd (ppma04wdc.us.ibm.com [127.0.0.1]) by ppma04wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 15SAhMX6002856; Mon, 28 Jun 2021 10:51:14 GMT Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by ppma04wdc.us.ibm.com with ESMTP id 39duva973c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Jun 2021 10:51:14 +0000 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 15SApEbD10421114 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Jun 2021 10:51:14 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4B6C1AC05E; Mon, 28 Jun 2021 10:51:14 +0000 (GMT) Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 204DEAC064; Mon, 28 Jun 2021 10:51:14 +0000 (GMT) Received: from localhost.localdomain (unknown [9.2.130.16]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP; Mon, 28 Jun 2021 10:51:14 +0000 (GMT) From: "Dov Murik" To: devel@edk2.groups.io Cc: Dov Murik , Ard Biesheuvel , Jordan Justen , James Bottomley , Tobin Feldman-Fitzthum , Laszlo Ersek Subject: [PATCH v3 1/5] OvmfPkg/GenericQemuLoadImageLib: plug cmdline blob leak on success Date: Mon, 28 Jun 2021 10:51:06 +0000 Message-Id: <20210628105110.379951-2-dovmurik@linux.ibm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210628105110.379951-1-dovmurik@linux.ibm.com> References: <20210628105110.379951-1-dovmurik@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: TsOg8vYTT43ZRHOto3_x8StJt8obwYIx X-Proofpoint-ORIG-GUID: M7HFr94AhukdjSOpIUIo00S0Pcojh_bk X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-06-28_09:2021-06-25,2021-06-28 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 clxscore=1015 spamscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2106280074 Content-Transfer-Encoding: quoted-printable 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/GenericQemuLoadImageLi= b.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 ( }=0D =0D *ImageHandle =3D KernelImageHandle;=0D - return EFI_SUCCESS;=0D + Status =3D EFI_SUCCESS;=0D =0D FreeCommandLine:=0D if (CommandLineSize > 0) {=0D FreePool (CommandLine);=0D }=0D UnloadImage:=0D - gBS->UnloadImage (KernelImageHandle);=0D + if (EFI_ERROR (Status)) {=0D + gBS->UnloadImage (KernelImageHandle);=0D + }=0D =0D return Status;=0D }=0D --=20 2.25.1