From patchwork Tue Nov 23 16:24:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 519317 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp8870557imj; Tue, 23 Nov 2021 08:24:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzDFNLxpvzRKGjhI7sbWz/MgqG11EaW2BJI0wi6WE6hSzG5toJAqh+gzcKQIpKjRRTS5cI8 X-Received: by 2002:a50:da0a:: with SMTP id z10mr10857182edj.95.1637684675477; Tue, 23 Nov 2021 08:24:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637684675; cv=none; d=google.com; s=arc-20160816; b=xgzebIOBPlYTl56Yfa8cytHAAhFBhH1OdBbptBdh0K7DTcKEKuVTs8Ff/WrXO2zAQE 5MjJVD2vmZBqY6NJPO/QLX/fo2o/EMINCIBOjQsFRUHqc2B5AQFvnEC4UflJL7l2y6Rv l5cQI661VGmV7aDi7Le621yjTapxsPXq7FVGwHxBqJH0jUX1sssxE8KgtoLhH4LLPJi7 7kZgTqOAzhOgAxsvJnEM6XPBWN40Chcr9g4HKN0lxqZjmraAxeXXZoju+WeZQOYNzOHk z23gzOmC88J/uni5W2YKz+JxZOc64sWldGXE3Os6/Xm4QRSfv41XULCoYiMdlyZx9IwO s9lg== 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=3jtluZyYPQW17TlPO2/HszLaQyQWtcHxbcNSKdzsTUo=; b=L3/SVeQHQYxh5KzFRTdfKGJ+u/Bdy6/2KG6IrJV1IIgmCysUut5df/xwwEnn1I/JrM Y1NnfUTzKCkmLCWE5MYnAHRs+C2jW318qCG25vx9RxVCMi/Rt2ub0ehba7yK25rWBCxe +1/ENzkhJrFaOubpR/jfqOcKNrxtNvSTInSlv7x2Z39muX92AA7IhH/+1sFZXbB5JRFn f0ckpZG3h7ES1xPxuWoumO6t5HpUAbdFkIgbR0JeQnjO6bgyuo/Hw2YGBa4lnQlZFk/8 pF6K5uS06qVFLH7reI+CAahWGZFXrf3lBIxdGN/Af+6sWiWkl9rAUi7vD9Vu8aQiF5SO nOiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="c/PvqaqZ"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id o7si42055367ejy.374.2021.11.23.08.24.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 08:24:35 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="c/PvqaqZ"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 BC0998069C; Tue, 23 Nov 2021 17:24:32 +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="c/PvqaqZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6BFBE80A4F; Tue, 23 Nov 2021 17:24:31 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) (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 615F3800AA for ; Tue, 23 Nov 2021 17:24:28 +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-ed1-x534.google.com with SMTP id y12so94506859eda.12 for ; Tue, 23 Nov 2021 08:24:28 -0800 (PST) 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=3jtluZyYPQW17TlPO2/HszLaQyQWtcHxbcNSKdzsTUo=; b=c/PvqaqZibG3bNJ23SD9rWCsljfTaEeD6X7icWabO4WDdWof49WJjxxERZQQigdtqV 6eSj0IACRtINzOOgBngkTDyPy1lsThFLB1Xrb3ZSl8Cuf4P8rA1gvrPITL6cSg0AhkfB 9hT7l307OMFyuiPOC0Hth4drr2bnlfv/Wisjm9s8Z65uxiaaQ+yqykeQ5Q9AP/D2D60i flFoc6+j7b7uaXYVtPW81eC1sZpO6CTS1vD9Pkch0YYjjdn/2O2xKgj5MHQg434tLSXS w5nG2Iz7xSt50LiEj4HjBJmrnsI/6og8+nl5lcgFVwEkr8mpl/N26Q1rYKUxvzBmiol9 g4NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3jtluZyYPQW17TlPO2/HszLaQyQWtcHxbcNSKdzsTUo=; b=nIDBV3EZcG6HRX2ljE1mgaAMXZNMcLxh02t6lUJBCWzP8ZeuioLEsv6D37+o1Q9jWD gnU/xGbEmiqCIZ2X39rPP0zr2rKuj5e1E4OPmA0YLjC9M76K3dReEVIVO4IYVInxvOov 6TDtF+g3/OF3ZTaKoRGRCPIs3Mdyjdzp+XGMlBiyZeSypi1lCwStB6xNV9O2IJfJDPWZ FcNjtKtO6854qzZ7xUK9ZgIJqEQrIb4XSpUHzjye80HzetyJjFL+iaFxkk5NB6viZgy/ nZouiXnTASoBk54UYRnRh6r4sdIIheZ9kC3rZHUnTU3B5j8j8ctVNcGl9JYERHJ8RDo5 32Og== X-Gm-Message-State: AOAM530zdG3JcUQt4m0Ma7KfcNLituijsF6qQLhRWecIFlbW4OsAKgqN YQrNZ6RItLtdpWweC7NJ7P0BHw== X-Received: by 2002:aa7:cada:: with SMTP id l26mr11131144edt.376.1637684668032; Tue, 23 Nov 2021 08:24:28 -0800 (PST) Received: from localhost.localdomain (ppp-94-66-220-227.home.otenet.gr. [94.66.220.227]) by smtp.gmail.com with ESMTPSA id a17sm5981179edx.14.2021.11.23.08.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 08:24:27 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: ruchika.gupta@linaro.org, masahisa.kojima@linaro.org, Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH] efi_loader: Check for pointers before appending to the eventlog Date: Tue, 23 Nov 2021 18:24:24 +0200 Message-Id: <20211123162425.657178-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.34.0 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.37 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.103.2 at phobos.denx.de X-Virus-Status: Clean The TCG protocol returns EFI_SUCCESS even when it fails to install. If the protocol is not installed there should be no calls to tcg2_agile_log_append(). However there are calls to this function occurring outside the TCG protocol invocation (e.g tcg2_measure_pe_image). Let's deal with this and shield the code from crashing while complaining, so buggy code can be spotted and fixed. Signed-off-by: Ilias Apalodimas --- Heinrich this is rebased on top of https://lore.kernel.org/u-boot/20211123115335.125252-1-ruchika.gupta@linaro.org/ lib/efi_loader/efi_tcg2.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 133fe8291a92..57a1f37695f6 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -311,6 +311,17 @@ static efi_status_t tcg2_agile_log_append(u32 pcr_index, u32 event_type, struct efi_tcg2_final_events_table *final_event; efi_status_t ret = EFI_SUCCESS; + /* + * This should never happen. This function should only be invoked if + * the TCG2 protocol has been installed. However since we always + * return EFI_SUCCESS from efi_tcg2_register shield callers against + * crashing and complain + */ + if (!event_log.final_buffer || !event_log.buffer) { + log_err("EFI TCG2 protocol not installed\n"); + return EFI_INVALID_PARAMETER; + } + /* if ExitBootServices hasn't been called update the normal log */ if (!event_log.ebs_called) { if (event_log.truncated ||