From patchwork Fri Dec 3 03:58:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 520182 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp340370imb; Thu, 2 Dec 2021 19:55:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJzOMOE5brjUGnhv4b8teF5XqTujaIkpnHfwTmYi5scFWgXvJM/Rb2z+2sitA2RkmZTlco4R X-Received: by 2002:a05:6402:3589:: with SMTP id y9mr23940687edc.44.1638503721473; Thu, 02 Dec 2021 19:55:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638503721; cv=none; d=google.com; s=arc-20160816; b=dlfDC+Kf0/EYm11N3swNjg+nL8FuOFw6lsriY8xOh+E5zbc6SMgBoLkq7TiclDOVqV hnLnIe3GkyS5locDYEvEes3k4vik/7Frgt/rUfZjVS76zocuLYnIbv3DLIJTJoFNx7Vf sSB0dwUg+iLdTvt3mLy4MZFxwN05nTQnG3gy+KG1D/DuAqhIFR0A1J+X10Vt79+9S+B8 lC+aJKRFsgaGLUj4DwrWv97gnFbyOy5skBmma3EJp27n/g2ZWNBIR7SwCpACeRRnccKv XQD1FJBHWMQ1kQLeiNE0AMNMAHy5H2rI7kzU7WgLAccLpD7TlhNhZL0tTB7m7AsXh7D5 uqTg== 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:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=Byyc7PLVqZOetHr/0WxA1Coz2siUwcCCpWqW9+KuY2I=; b=EN9AycpJPq0718b3MglODT0YkzWL6MRuV3glxitH1belp1MAxEXaEkpB8z/VR/ZOSS BbhloFU3Gp/81JBoZ9jckGBZmeJztZLoA/jU5nJWC1XpnFFUa90n4m73sntPqSOMub6p P6Z/t39Jxzw9cvmC9YTq6SslseolcD0G1/C7UrXVYAG2WSRkGy7MsWGVXCyQRbFdp8JX gwTf5YD/FYvdoGRKHKPCsndHQUNZjWMgOWkqBsEbn92X3ZdCAjhdKy6X4tmKVY7qmQgz ILvk0kzjCq9lNRgCq9HjeDdP5Hoqy4zyO+ldeE7QAtZ0T0WqCQg05zLUwP/qauc3hOPm +u4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YuoRD2Zn; 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 qf15si2920158ejc.553.2021.12.02.19.55.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 19:55:21 -0800 (PST) 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=YuoRD2Zn; 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 B87BB811B9; Fri, 3 Dec 2021 04:55:06 +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="YuoRD2Zn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2E353810EB; Fri, 3 Dec 2021 04:54:53 +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-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) (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 A366A80379 for ; Fri, 3 Dec 2021 04:54:47 +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=masahisa.kojima@linaro.org Received: by mail-pl1-x635.google.com with SMTP id q17so1175054plr.11 for ; Thu, 02 Dec 2021 19:54:47 -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:in-reply-to:references; bh=Byyc7PLVqZOetHr/0WxA1Coz2siUwcCCpWqW9+KuY2I=; b=YuoRD2ZnG0qf1J6Ch1aFcTPvF3w/dVCqCIitCi1fqXjXyeRMqejnjAbrrYpN4TnBpb 6NYq9AcVPdtiqZLDS/DaSqmK4sQCfAaEpn5mwlcqvkvO5PiCi5Bv8ObKIqT/7dDQ2UPZ qaVRqN0XVUHfGLnKs+59QtImoI8jqZbgRiFa2hn4WbfgxjKGerdiYEJCiF+Xv2QKAook 6hIHbhNxvwaY/Rkn1kPjnROSs5izD4koueqTabSgCcmj1WIakn3v1XALKKMk/b8izeC8 oYZBDIoD9CqCBx7WhEISCT9l1wzXRhFQ5RPMoyd5IH0h4VUDymiG7G6DbDqopVMQgHm8 TazQ== 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:in-reply-to :references; bh=Byyc7PLVqZOetHr/0WxA1Coz2siUwcCCpWqW9+KuY2I=; b=eWfayLhCWFzO+VRN92u6s8yMQlD5AFg4UNxnUKg9h6iCaYI2Jzx1qmd/X5C2WgwhRv +PZzJgFrIGsnD/eHuVA2hgmyEqknzjLRq085t3XXZbJ+qmi+MPsIwkeS+Nb0o8oEQOMC 8XzLxvVGBm+FrAws1/rPBGWLupNdl3FiicuzYYkoLI4avvTqVnKI743I2wi4wmzqyMRR 8ManVYTwJMOKs47g7bvE3MwYBxffQldyUECO5BYX45XaUd2m5hkkMF49HBjAI6AgtyNZ ofs+YvtWFo3hZss0duOD0Tm7lL4u9/KPnU/DWZ+c9bJxtDHclT1yp6qJ9lPxmHp36Jov SoEw== X-Gm-Message-State: AOAM531+rhDa5GeBnMyaI1O7YAm2p0Y7qMUnbImn+OVialL2RqWRKRZV h1uypKXAkGFuLZSqfXnuooCdRbEpiEmPOw== X-Received: by 2002:a17:903:1c7:b0:141:e630:130c with SMTP id e7-20020a17090301c700b00141e630130cmr19974523plh.80.1638503686082; Thu, 02 Dec 2021 19:54:46 -0800 (PST) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id y32sm1301334pfa.145.2021.12.02.19.54.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 19:54:45 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Masahisa Kojima , Alexander Graf Subject: [PATCH 3/3] efi_loader: correctly handle tcg2_measure_pe_image() error Date: Fri, 3 Dec 2021 12:58:15 +0900 Message-Id: <20211203035815.27433-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211203035815.27433-1-masahisa.kojima@linaro.org> References: <20211203035815.27433-1-masahisa.kojima@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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 When the TCG2 protocol is installed in efi_tcg2_register(), TPM2 device must be present. tcg2_measure_pe_image() expects that TCP2 protocol is installed and TPM device is available. If TCG2 Protocol is installed but TPM device is not found, tcg2_measure_pe_image() returns EFI_SECURITY_VIOLATION efi_load_image() ends with failure. Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- lib/efi_loader/efi_image_loader.c | 11 +++++++++-- lib/efi_loader/efi_tcg2.c | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index eb95580538..426f096574 100644 --- a/lib/efi_loader/efi_image_loader.c +++ b/lib/efi_loader/efi_image_loader.c @@ -934,9 +934,16 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, #if CONFIG_IS_ENABLED(EFI_TCG2_PROTOCOL) /* Measure an PE/COFF image */ - if (tcg2_measure_pe_image(efi, efi_size, handle, - loaded_image_info)) + ret = tcg2_measure_pe_image(efi, efi_size, handle, loaded_image_info); + if (ret == EFI_SECURITY_VIOLATION) { + /* + * TCG2 Protocol is installed but no TPM device found, + * this is not expected. + */ log_err("PE image measurement failed\n"); + goto err; + } + #endif /* Copy PE headers */ diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 2b7b7cbbae..c19f73dc10 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -977,7 +977,7 @@ efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size, ret = platform_get_tpm2_device(&dev); if (ret != EFI_SUCCESS) - return ret; + return EFI_SECURITY_VIOLATION; switch (handle->image_type) { case IMAGE_SUBSYSTEM_EFI_APPLICATION: