From patchwork Wed Mar 24 14:23:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 407815 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp457274jai; Wed, 24 Mar 2021 07:24:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOd7bWdrOcDg/ANngPkw7g5UWmORNCCnu9TBZC6Mxu13TvIkmozeoJFlC4bxBjT8RtAgay X-Received: by 2002:aa7:dd05:: with SMTP id i5mr3684424edv.300.1616595847491; Wed, 24 Mar 2021 07:24:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616595847; cv=none; d=google.com; s=arc-20160816; b=Vv0ECb8wXwkucG8pHROGgzrZAsnELUR2ZkNBATBC0y3VqFxcprOjDWwF8dwOBFhYEC rcugNx3HbtFIDLPhQsu2nyz9JtyFvItSpAhbPHSEhKo1nkmIZip5yfZO2nsP3IvzGiiy l59ZMa3hz+k/u7Lk/9IkDq/Tc/jTPMbGt5/Kf2ciwVYIOQIjeAyiRwewhMFxhJz2vdev fcL7CDvA6DoTz0gTG2FHoLFEK64EHRHB8tM8vhaYGhs4FL9LLsnq7U77m9qum9cpuowX eVRcSH2fgehN5SDXZwf6CQWBrnJv/Y3KowKhbAnBLc4n3TjNsH1cq3qVG8vAnywCancZ H90A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=5XrY+WMgeK4w/RXjAXUfFteL+FccymxmoOJUaG19Oxk=; b=LsFvWKtXiRZRn6a9mCYdEQrsvoKtEa8643w/diywj7BNPPqfNunBt7YT5i5mRWFNZE +2eoD+5wVOfyI06Kt8f2gJoPFzR+OT6Dt5Wu7Ye1mlaruqEEQNi6KJC7Gg/yoiz6bF8I rpI3oeBjsNOGtXawx7xNMzSZl5/keLxzr/VwmYW6sXi7IBfFScQYZS5osQJktgq/jBZg /Zf3ZEe+8bM/oxi2D9tc2SH0v7pWWL6djIK8Xz19+tBPxtlm4NHiH8Cuvz/yKrv0Zw/u lSTA0YT5JooLsdby7gOFz84rIAzqIAxxFYNz5dEliMsyEdnC4GbXWbFHTwz96EbKKjOb dDUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D2K3yGfO; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id qn25si1889503ejb.22.2021.03.24.07.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 07:24:07 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D2K3yGfO; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5D1AC82887; Wed, 24 Mar 2021 15:24:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="D2K3yGfO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 213C9828B3; Wed, 24 Mar 2021 15:23:59 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 71C8C8283C for ; Wed, 24 Mar 2021 15:23:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wr1-x432.google.com with SMTP id 14so1421185wrz.12 for ; Wed, 24 Mar 2021 07:23:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5XrY+WMgeK4w/RXjAXUfFteL+FccymxmoOJUaG19Oxk=; b=D2K3yGfOPv4qD/AA5u4xBWRtXzkQ86X6/avTge8b5AyTbbhEX8IJ5/9xvOpIa1Nk2z /Vx9vrU8co9C5Dt9ykNAuLv4Wh4G23gJBpKW4DvLYyf/m2q97gqusV16y7p01+4ovjDV Fj65V66mUbEu761D000QoyYWwurJ09oE9+u/U0qpSioEj6SdBDRZXCZZ6/Ph3l93lre6 HYZRYonuHaZ/1KQf4D5lnDVnfwZcCfgk1W5cJ8aB4XfGdlGMOoUmL+Z6I4gmFE1vGN0e imSMVZjE3qexQ2nMcT+nDtZQbIKrZKYvXVXSyAf3Z9sMjQyRxpYuMFcgnLaw3l2H1boT qJ3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5XrY+WMgeK4w/RXjAXUfFteL+FccymxmoOJUaG19Oxk=; b=WWDhR/JLz2PIUzJHaNa7piYzTylyH+jwhrRbOUxWupHfwHZ+M3R8vXOGFwlGPB9+yd e8Ra4P5Dtweu6Ds4bE5q/xZlCCrF0LsPLjBc1x5CwpWNiAk+PEDcXIVcldksJkFNLCgt 29LedmFfY6lYotXdx/GrAdUazHGYyodc4yqZOWkDPe7P2/3YUqDdYKvLp/we1XHPFSHb z+URmLrnOeN4BL4ceYOTG58F8tc2GULoskc8cR8AoNG8ZISFzGCb1N0a0a26kqhAdVIs 8fQByQZkoNNPdUaztsNQS49G+pfTVT/iYyXEJS58S8+YQLX88kyxLhN9KlC7NDyYugMx vS9w== X-Gm-Message-State: AOAM531ogLaR1HMaUqTIC7D+ceUJBVEhP0B4Z5nrLgYPA/HE37TBoSru 6/7ar6hkmR7+dmrDXkesv4/HIw== X-Received: by 2002:a5d:6a11:: with SMTP id m17mr3912315wru.361.1616595836055; Wed, 24 Mar 2021 07:23:56 -0700 (PDT) Received: from localhost.localdomain (ppp-94-64-113-158.home.otenet.gr. [94.64.113.158]) by smtp.gmail.com with ESMTPSA id h20sm2455010wmp.38.2021.03.24.07.23.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 07:23:55 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH] efi_loader: EFI TCG2 free efi memory on protocol failure Date: Wed, 24 Mar 2021 16:23:52 +0200 Message-Id: <20210324142353.1216042-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean Current code doesn't free the efi allocated memory in case the protocol failed to install Fixes: c8d0fd582576 ("efi_loader: Introduce eventlog support for TCG2_PROTOCOL") Signed-off-by: Ilias Apalodimas --- lib/efi_loader/efi_tcg2.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) -- 2.31.0 diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 797d6eb134f6..02de63808f9a 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -988,6 +988,7 @@ static efi_status_t create_final_event(void) return EFI_SUCCESS; out: + efi_free_pool(event_log.final_buffer); return ret; } @@ -1041,8 +1042,12 @@ static efi_status_t efi_init_event_log(void) event_log.last_event_size = event_log.pos; ret = create_final_event(); + if (ret != EFI_SUCCESS) + goto out; + return EFI_SUCCESS; out: + efi_free_pool(event_log.buffer); return ret; } @@ -1055,23 +1060,31 @@ out: */ efi_status_t efi_tcg2_register(void) { - efi_status_t ret; + efi_status_t ret = EFI_SUCCESS; struct udevice *dev; ret = platform_get_tpm2_device(&dev); if (ret != EFI_SUCCESS) { log_warning("Unable to find TPMv2 device\n"); - return EFI_SUCCESS; + ret = EFI_SUCCESS; + goto out; } ret = efi_init_event_log(); if (ret != EFI_SUCCESS) - return ret; + goto fail; ret = efi_add_protocol(efi_root, &efi_guid_tcg2_protocol, (void *)&efi_tcg2_protocol); - if (ret != EFI_SUCCESS) + if (ret != EFI_SUCCESS) { log_err("Cannot install EFI_TCG2_PROTOCOL\n"); + goto fail; + } +out: + return ret; +fail: + efi_free_pool(event_log.final_buffer); + efi_free_pool(event_log.buffer); return ret; }