From patchwork Tue Dec 7 05:15:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 521618 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp5711536imb; Mon, 6 Dec 2021 21:11:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJzeHOjyKo5cI1NAwjjBpq3nqIy4hWr6uFsEBWEkmpppld6dPU+uS5+iABckEFPtWnQGAtuH X-Received: by 2002:a05:6402:41a:: with SMTP id q26mr5590966edv.387.1638853903063; Mon, 06 Dec 2021 21:11:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638853903; cv=none; d=google.com; s=arc-20160816; b=oMJkXwgF6Q96Ouki4XWz5WYHqZEpDUGbXXuzYoUUxvKZoG0ez4++i/tjtoXFgyJwmC qZgNbp9PuIFV9EXJ+tkZW8157FZKKz+fP5xgpLlZ3iDGiZ2J+c3lfeC2BMmuMBuFa8Hu /73xZUIurzA6emNcSsv517UZ9CEsQpCb8ixHwa1jAto4txunbm3bkwvvr5UTVJ5ypyc1 3JlhfuQBdS5dPQHeg4RJARgFUJ7rFFFVKie+lEYr9Ziy7WT6W1q3Dp1KD1pJfDc0V1Ir 2CR0PptVwWMiZeslSESyCq64BDhdR2oyIBiVzonPXHRmqlwKJL0NhhwN0y+cUTfa/32Q v+jg== 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=PFe/RY+3gDpCxd5TGzDnW8LN9rsPOeDccX0VocHFwTA=; b=gFg85gaTmlwhkpPMR0Ebo/gg2tIwIf3nCXZxmorNi+USWW7RZs6Z9YAxDCtJgoXkOP BIM6rxtnJVc74nAllrBTQGUveds+/LNAi3Ic36heT6a570Wlt/HwmREq+JgmeMyirQTR MqeDtXYuOL4XGp9bMYRCcTThkLIeHND8tNC7plq1tPAUw3DplG6zLMTGvjUNPeHArQfO 6nHzhsZ/kcGS2joQuOGi4FJaSHYsq4Zdubpbk1saIYOet2J38zI5htEFnqnWET9BMr6O MMBT49fVtDdSMPAyYWe50XJSTP952kVJy9Rzo3L+y3v4W6Q4bYsGZdvwZj1hL6i3KgXc e3AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W1OXQmqj; 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 q2si20290160ejx.746.2021.12.06.21.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 21:11:43 -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=W1OXQmqj; 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 13D138348F; Tue, 7 Dec 2021 06:11:30 +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="W1OXQmqj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8057D8345C; Tue, 7 Dec 2021 06:11:23 +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-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) (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 6FC86830F5 for ; Tue, 7 Dec 2021 06:11:18 +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-pj1-x1029.google.com with SMTP id cq22-20020a17090af99600b001a9550a17a5so1040304pjb.2 for ; Mon, 06 Dec 2021 21:11:18 -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=PFe/RY+3gDpCxd5TGzDnW8LN9rsPOeDccX0VocHFwTA=; b=W1OXQmqjnMY54k0nlWkTmHRSl5zpc/+D5faSYoj76GQS1v5DHvuovpsJ3JI8DyxQN3 6hXGeWVhgMXlSFoZtD622LL4aj5/KJ3vENw0AbKM4LR0QNuO0D+J5nBdhs3s/1gsRDsx BCsTBpa2GkDappFChgOJ/7DvDB6dw05Z3rj7b37J7+FRi+98v7+WOan7xTKyJoqAT9De yD/nEhPZJV4xMGXM/kF5ca9VDgRki4FIKHU2ArN6reWRnvRjQctIbMc4bvgYo4DvOgqP 9vFHf+xCa21EvphSW7osTJO7GF1FI3iNmJxEFvZeZDJ+ZHixx6LbIFl6ISmAY648z1vX dSTw== 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=PFe/RY+3gDpCxd5TGzDnW8LN9rsPOeDccX0VocHFwTA=; b=gzrF14g4DXOy8BFZZolXlRez5PDaVIDCu/Lco1pC+5uljtTwiZHIWTDDoSn8HCNEBD V09EYCuihFwCk937T8IvyWxyVdJZgjWmjexJCeC0KSGWJramys1cBPPHDuv2+hILLRT6 kyFSIPQn+qY7UdHrKFut+vG+7Mi3LIwc04UJvl80FuKvsnzCVR5Ap/xdgtcdKE5Q4/bi ADFBmyUb4GFIqjE3Uimi+42iAKXcPzxZgPMNqutfw41kr+2AHKLhThbBW1homj6AvBgH haOzyr8RzgtBpUi5h8a1JOKoIrB5sKuzqTp/3E/MPcXEjP9DhgjOnF6cf+cK9FmdWzdn DhHw== X-Gm-Message-State: AOAM533jqaHsIgzGgH8wbnN+Ri5RA61by1Mm77dZEwpm9TulYCYDPC8k paKJf0uBkkLtb3kB13hs+QMMncivoFpSig== X-Received: by 2002:a17:90a:db81:: with SMTP id h1mr3980620pjv.46.1638853876549; Mon, 06 Dec 2021 21:11:16 -0800 (PST) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id q10sm11975516pfk.180.2021.12.06.21.11.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 21:11:16 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Masahisa Kojima , Alexander Graf Subject: [PATCH v2 3/3] efi_loader: correctly handle no tpm device error Date: Tue, 7 Dec 2021 14:15:33 +0900 Message-Id: <20211207051533.5597-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211207051533.5597-1-masahisa.kojima@linaro.org> References: <20211207051533.5597-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 and efi_load_image() ends with failure. The same error handling is applied to efi_tcg2_measure_efi_app_invocation(). Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- Changes in v2: - EFI_SECURITY_VIOLATION is returned in efi_tcg2_measure_efi_app_invocation() lib/efi_loader/efi_boottime.c | 9 ++++++--- lib/efi_loader/efi_image_loader.c | 13 ++++++++++--- lib/efi_loader/efi_tcg2.c | 4 ++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 8492b732f3..20b69699fe 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -3016,9 +3016,12 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) { if (image_obj->image_type == IMAGE_SUBSYSTEM_EFI_APPLICATION) { ret = efi_tcg2_measure_efi_app_invocation(image_obj); - if (ret != EFI_SUCCESS) { - log_warning("tcg2 measurement fails(0x%lx)\n", - ret); + if (ret == EFI_SECURITY_VIOLATION) { + /* + * TCG2 Protocol is installed but no TPM device found, + * this is not expected. + */ + return EFI_EXIT(EFI_SECURITY_VIOLATION); } } } diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index eb95580538..773bd0677c 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)) - log_err("PE image measurement failed\n"); + 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, no tpm device found\n"); + goto err; + } + #endif /* Copy PE headers */ diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 59bce85028..0ae07ef083 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: @@ -2200,7 +2200,7 @@ efi_status_t efi_tcg2_measure_efi_app_invocation(struct efi_loaded_image_obj *ha ret = platform_get_tpm2_device(&dev); if (ret != EFI_SUCCESS) - return ret; + return EFI_SECURITY_VIOLATION; ret = tcg2_measure_boot_variable(dev); if (ret != EFI_SUCCESS)