From patchwork Tue Oct 26 08:27:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 516166 Delivered-To: patch@linaro.org Received: by 2002:ac0:c404:0:0:0:0:0 with SMTP id t4csp46932imj; Tue, 26 Oct 2021 01:26:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwN1Rl78S0eqSPPJuGz5xIQ6FgDmpa95A+c4MMAlZh04foxK6HnRAUK4KDy1sPjWBlLp9Tu X-Received: by 2002:a17:906:a1da:: with SMTP id bx26mr29450354ejb.558.1635236815894; Tue, 26 Oct 2021 01:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635236815; cv=none; d=google.com; s=arc-20160816; b=cPXMM4Sau41muuO4YILWjPVpUvxEE+67lxseNKrFfI4/DYut/tAs47BnyMtQql3rLT v0lG4wHJXKo6BKI+W0YQwwZbR65itBdYgSP25DQoxuYPMbrAv3ZvsSz0+8lWl8zaXGXB PopMTVv31C1cjjCU5ZF+ew28bKx7DPXNSGHYneEPdBFDOQgFtMczYNds/+0CGc4wZlJN +Zp894TRn+X/h+5mOfNFGSZyNXcxWfL4PoYEH9tzJ23dWk52fWS++wFh23RMTyoJYssv kHJsoaHtfz+lMWxtPOJ0Kqe0ZPcDCv/R6lNgLgfkSQlwLbSwI1mjHj4YGYDaKQ3UZ2PO OPog== 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=Qw8Hbqrw+E94UNqpVogZ1vVn0O9Hd6wqsCQPKRgBNX0=; b=saFtqoDlbVkJW15PWCV+qlrx0B3Zq1Xkao3w84eBOHSyEPNsZxnMH0UQZ/tMUXCZcb fcrJHZQXA9OK+8VEqRDdV5fedsPPl/islZ4ZDN+HVSfMrU93jbPpQBwqaOn8HRzV5K1S qah+XjR4p+r1h7QZjueX4u8bxZR65XMqQ1go8n18k7OKqQTmP59fWx3SI5C0h/sgeRYh FQQ7TTV9M9qqWY4khz8zJ5SVLsbtf2dVHoAHgFmyTDSh0d/KXNCZXU+xiFzghIuPlOiz k48EgNvhMZz8/ujlVrQ898FcIMeOH/0V+ihO08T7qqvUvSaHGzn7FoEAIvwxPuSj22B5 QAVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GLvWWoMh; 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 e1si23761919ejs.278.2021.10.26.01.26.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 01:26:55 -0700 (PDT) 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=GLvWWoMh; 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 A77B983542; Tue, 26 Oct 2021 10:26:45 +0200 (CEST) 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="GLvWWoMh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 85A1680F5F; Tue, 26 Oct 2021 10:26:34 +0200 (CEST) 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-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) (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 293E6833B5 for ; Tue, 26 Oct 2021 10:26:23 +0200 (CEST) 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-x629.google.com with SMTP id n11so9800736plf.4 for ; Tue, 26 Oct 2021 01:26:23 -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:in-reply-to:references; bh=Qw8Hbqrw+E94UNqpVogZ1vVn0O9Hd6wqsCQPKRgBNX0=; b=GLvWWoMhFeRQlUdRH6dk3g2TvIwOCa/m8RBx4P5NhyHwzalmt0Trt0pN89UtPW1Tp4 NNK5z2ArmMYEEz/V4SqgxjkcHf8VVhlcWEVuTndLKGfwiTiU8GNP6Ilu3cdKcJ7uM3pJ iXzGvXNjawaTWfMUO6rdPHtc9v8Z5y4nFccAMtibOU28a6oj2dL4SFpWw9sCouO7OyPi srZmCJ+xcsi4pWTp1vKMOZy+5+5MpArSGz0TK9nYnEHKwy1xF4Pr64DkzdrPTHP4nTR/ 606vNM2/ZvQIsyez+c6Em9+evMedzdho0fvrVICvhF4hyCHoeERgx25elru3gUsqOyfx U0bg== 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=Qw8Hbqrw+E94UNqpVogZ1vVn0O9Hd6wqsCQPKRgBNX0=; b=bi3nQvpue+VXKDkaUunBJRkdyZy2tXcvtGHCurarHEKJdzKvrPSB9sS2wQKVkGdeN+ XQaFjum6joymTpK3guZeZb2k5xgbLWSEhfZwQWSU8yLYvwH+Vthsxo9mOzWp8LTIKdRg G/4igL55x6P0XSE7Bj9Ipw2Rx/hK2D18e5vegid5RMdRyF5q1dpG7Xu4Jhg18U9mtApv F3ri0zwJcOLt9P3ZwZOtAM6FycJ/0ACIYsCtwMTyeDCnwMTXdgzZ6z/RKpuzNvrSsOdC YN+ymflpGCrdSO9PoW2fhGBr+a+Ebi+YtUK2Q7qDD4CNyDoirpTm2c31jQTuI/8POJC2 2LIA== X-Gm-Message-State: AOAM533Vtv5voaUD2yVNCSEkY+p9oQd5/nJmvfX3JQCcrMy++wfHTumD hld6A/SihIpqaTBnYQQEf/rVoYJTJ19LmA== X-Received: by 2002:a17:90b:38c7:: with SMTP id nn7mr41536013pjb.214.1635236781508; Tue, 26 Oct 2021 01:26:21 -0700 (PDT) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id c8sm20135873pjr.38.2021.10.26.01.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 01:26:21 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Masahisa Kojima , Alexander Graf Subject: [PATCH v4 3/4] efi_loader: simplify tcg2_measure_secure_boot_variable() Date: Tue, 26 Oct 2021 17:27:26 +0900 Message-Id: <20211026082727.23399-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211026082727.23399-1-masahisa.kojima@linaro.org> References: <20211026082727.23399-1-masahisa.kojima@linaro.org> 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.103.2 at phobos.denx.de X-Virus-Status: Clean This commit simplifies tcg2_measure_secure_boot_variable() using secure_variables table. Signed-off-by: Masahisa Kojima --- Newly added in v4 lib/efi_loader/efi_tcg2.c | 60 ++++++++++++--------------------------- 1 file changed, 18 insertions(+), 42 deletions(-) -- 2.17.1 diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 377b138855..6545ec9e79 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -81,12 +81,19 @@ static const struct digest_info hash_algo_list[] = { }, }; -static const u16 *secure_variables[] = { - u"SecureBoot", - u"PK", - u"KEK", - u"db", - u"dbx", +struct variable_info { + const u16 *name; + bool accept_empty; +}; + +static struct variable_info secure_variables[] = { + {u"SecureBoot", true}, + {u"PK", true}, + {u"KEK", true}, + {u"db", true}, + {u"dbx", true}, + {u"dbt", false}, + {u"dbr", false}, }; #define MAX_HASH_COUNT ARRAY_SIZE(hash_algo_list) @@ -1820,52 +1827,21 @@ static efi_status_t tcg2_measure_secure_boot_variable(struct udevice *dev) for (i = 0; i < count; i++) { const efi_guid_t *guid; - guid = efi_auth_var_get_guid(secure_variables[i]); + guid = efi_auth_var_get_guid(secure_variables[i].name); - /* - * According to the TCG2 PC Client PFP spec, "SecureBoot", - * "PK", "KEK", "db" and "dbx" variables must be measured - * even if they are empty. - */ - data = efi_get_var(secure_variables[i], guid, &data_size); + data = efi_get_var(secure_variables[i].name, guid, &data_size); + if (!data && !secure_variables[i].accept_empty) + continue; ret = tcg2_measure_variable(dev, 7, EV_EFI_VARIABLE_DRIVER_CONFIG, - secure_variables[i], guid, + secure_variables[i].name, guid, data_size, data); free(data); if (ret != EFI_SUCCESS) goto error; } - /* - * TCG2 PC Client PFP spec says "dbt" and "dbr" are - * measured if present and not empty. - */ - data = efi_get_var(L"dbt", - &efi_guid_image_security_database, - &data_size); - if (data) { - ret = tcg2_measure_variable(dev, 7, - EV_EFI_VARIABLE_DRIVER_CONFIG, - L"dbt", - &efi_guid_image_security_database, - data_size, data); - free(data); - } - - data = efi_get_var(L"dbr", - &efi_guid_image_security_database, - &data_size); - if (data) { - ret = tcg2_measure_variable(dev, 7, - EV_EFI_VARIABLE_DRIVER_CONFIG, - L"dbr", - &efi_guid_image_security_database, - data_size, data); - free(data); - } - error: return ret; }