From patchwork Thu Mar 25 11:31:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 408790 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp445815jai; Thu, 25 Mar 2021 04:33:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJww5W3UxVVwJ9RgStTVmDvxDALjFZHR/qpp6gYmBIF0XkyBPoz3JC/wxhNyajeX5y7C+eEA X-Received: by 2002:a05:6402:1855:: with SMTP id v21mr8581794edy.310.1616671919463; Thu, 25 Mar 2021 04:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616671919; cv=none; d=google.com; s=arc-20160816; b=UIYQR9BgLe9vxQkc08eBGOl3XlzuGvLnkNq5Jf2o4btsy3fxvFeWRWvRYKnrklwFnL gZ31++LWxH55BrQXl8Q5330kqoo+blQrLqoBCUQ6efHXQtG2r0naeJkNO1D6+WCTqiGv J55alA/eqZh+Qfh2DJtsQ8zElVJk2/6eyE2Z/9z5SVlbnqbNL3gAfb6ClP6id5BE3N1l 8VTOg1dwqZrMbM1I5ReLEYv5NGIUIA8Fy+56UmXbKYS0nGlHbTAdbWcXkXhhty/aorLk qJtW+etL9RRFIKhOqijU9rcrIvXzNOAHNPYSm8Mg5q/4U07up6j9ZSPTzi09cp6mudXM EVmg== 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=/2P/epoyX0/ikgu9FH3VnQf6sRNF9C31HqN3zK/TETY=; b=Sbj2VswK9ze1XdH1x4b6A40/aknlvCjmupfzicoZXVDZMccAPFj++QUIJKDMskuanp K3zJVJ6dmp+N7PeyJCGIthcI4ZqH195e6l8j4+tehyINgqydmqZPUsHMurXb+bf4eYI2 /w0crB2La/g5a1peVTCYTuPRIsf9j/WXlNuuchpS3fF9HuSompYeybW3KyBkF5NyQrDp gyL8uX24OL3XfmUrXBFwVcPnunhFmpLrzn9NUrcHDKxgru8xuf5I0RsAUWDzFpS1m9H2 KvpZ6Nbv3b1bPXp1s7PeFJPJcfKkDaIsZvRpkUYmrHz9C+RaN6MERZ4VeALV0xvNRPVS L9Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=youR0Ifk; 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 e16si4022772edq.338.2021.03.25.04.31.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Mar 2021 04:31:59 -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=youR0Ifk; 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 406EC805BF; Thu, 25 Mar 2021 12:31:53 +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="youR0Ifk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B8649827AE; Thu, 25 Mar 2021 12:31:51 +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-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (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 D70128006D for ; Thu, 25 Mar 2021 12:31:48 +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-wm1-x32d.google.com with SMTP id b2-20020a7bc2420000b029010be1081172so978322wmj.1 for ; Thu, 25 Mar 2021 04:31:48 -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=/2P/epoyX0/ikgu9FH3VnQf6sRNF9C31HqN3zK/TETY=; b=youR0IfkqJQqsSB/homEI6TNzlamVJoVZIROOGXxk77ue8mj9c0GoXRcXMbHN2zERO lMRPFk0jzpgVLubXhLUXets2j/WA12Ko3Kx88MmTHcBK0o2A848MTUb119b26k3T2IuK PGKe42dRi3RH9bbf7rlbMOlPiD8ytD8Q5zEe8O01cXq3/Z6gIFQ1FNhyxyHGF/EVh3ue s5h+eIioHEvioHkjDqpPR+tpA2RtIQdbP0HOrLGm1im2q1Jrk+6DM5yhVKLhqEBXCpsE 8BsnF/EfdsWSAmwUqh2pu/t/uw0MaFCNxVbYkCKkYoxUiX71KzjwzO1nUNoSlYF09Jvp bfMQ== 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=/2P/epoyX0/ikgu9FH3VnQf6sRNF9C31HqN3zK/TETY=; b=NnMLzLsSb/zwD+OYpHBzUUbZiKk7VXmHTBvvUe1+nL/WAlIOR/vPUCEEwGQD3bscDn TTgNk5ER9+v9gmBKOVT0DM7UuUBrqNbcpK9VQaL+agnWySRUSNpLf5Z0QxLVfh3A3TGi LdrSo0j6iucv+L7DBI/dpkgzS4WgqEe9ADQZFOjOeTCDaX0J7st2VOLaXxwnSJ27Ax6+ BW1WG7P2UGtRAQGHsHZd9kQAx4Wc7cM/NZvVuiU98X0NPe9FrKRXVygRmiPkp5xdq7IR cvf0gl7n6ukDBt2nmal3hGx1BUwzedYmfY28BkD3AqFyymHGINEY4aZ7huoQRf3N9xQl vb/A== X-Gm-Message-State: AOAM533EwbojTDYK1nREeuY5ra74PHz8PRGp1nEPd5KjHG+H6N0yvaLk 5yUvtmvbBveyunpA3YsKS7MSog== X-Received: by 2002:a05:600c:214d:: with SMTP id v13mr7541726wml.162.1616671908456; Thu, 25 Mar 2021 04:31:48 -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 g11sm7227009wrw.89.2021.03.25.04.31.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Mar 2021 04:31:48 -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: Thu, 25 Mar 2021 13:31:45 +0200 Message-Id: <20210325113145.1255029-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 --- changes since v2: - remove the table using efi_install_configuration_table with NULL changes since v1: - remove the installed config table as well - gather all cleanups in a single function and call that instead lib/efi_loader/efi_tcg2.c | 40 +++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) -- 2.31.0 diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 797d6eb134f6..35ae8ed5962e 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -957,6 +957,23 @@ out: return ret; } +/** + * tcg2_uninit - remove the final event table and free efi memory on failures + */ +void tcg2_uninit(void) +{ + efi_status_t ret; + + ret = efi_install_configuration_table(&efi_guid_final_events, NULL); + if (ret != EFI_SUCCESS) + log_err("Failed to delete final events config table\n"); + + efi_free_pool(event_log.buffer); + event_log.buffer = NULL; + efi_free_pool(event_log.final_buffer); + event_log.final_buffer = NULL; +} + /** * create_final_event() - Create the final event and install the config * defined by the TCG EFI spec @@ -983,10 +1000,6 @@ static efi_status_t create_final_event(void) event_log.final_pos = sizeof(*final_event); ret = efi_install_configuration_table(&efi_guid_final_events, final_event); - if (ret != EFI_SUCCESS) - goto out; - - return EFI_SUCCESS; out: return ret; } @@ -1041,8 +1054,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: + tcg2_uninit(); return ret; } @@ -1055,23 +1072,30 @@ 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: + tcg2_uninit(); return ret; }