From patchwork Tue Oct 26 08:27:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 516167 Delivered-To: patch@linaro.org Received: by 2002:ac0:c404:0:0:0:0:0 with SMTP id t4csp47022imj; Tue, 26 Oct 2021 01:27:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCfSCdvzShvwzrHdj5OC6cs7ogCTGi3LRUeXaS0GjBzMQK/uwy5J/Vl7RlWMj12lV6bVKk X-Received: by 2002:a17:907:8a20:: with SMTP id sc32mr25046063ejc.134.1635236825508; Tue, 26 Oct 2021 01:27:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635236825; cv=none; d=google.com; s=arc-20160816; b=bpcHT+hjna3NDI3Dd8xQVNi2FzynSfUQd2vE3vwQkicAzMkd50mN3kMIyyNlJEIsOV 7USaBc7fGXqDDlrVIPmDUmqnEhfco7V4Tcw5KANSqdLsmt2tKkCdNPGb6ZI6AuFdaUGf YRmMjZhg1jWWFwnow0WGIdc5XAQOrVd/1MqdIY+hgze4S69g34C75kgfh7CNK31vn4jR njQ9ujuuCKUYyTUJL5cFi/WIWVSvU/Hp3Dz8gorC3ckacTRkQltzcb3o++cjDMvPLm2k yQu1sB82Ao9m92Uw64DpkeAWUeWnuTLUbIZE47PfJN8p5L8eesN+HFDCkEl1aaWXo9Ct 0oJg== 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=ZfhVmo77rYEAtoSBeJpMlpKrIxravrVpVSpi7503kLw=; b=Ob7W/rhStSxa0I3ajJgTMeD4U0Wj2okEddQitaz3ZLV3PiJvs9ey5Zm03HjHjtlt+R EANJM/j0L9j2hTbaKQ2/iSI2lT3URp58IFXfvibjpwJbl8MUNm5VBJRa53SYWVMJM7cV BDYAepEzzeomseWzlLZeR+VOro6aKLT8fak9oeu9nHNga9/QpEjHQM63WLkeVyDMnxur 4aj3lW7uczKIzMlhnkKBRfs2bu5djq1E/D3M0LaHfs+hHdGsrfREWG0OYT96psyi04e8 uSTrIeMY+M2ViNfQFFI0fB4xGFsS+eq/pHmIYHWm/jTXhwmGMXHm+W/SV+M4uMWQGlPb mwEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="b1aiArh/"; 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 hr33si12176398ejc.509.2021.10.26.01.27.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 01:27:05 -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="b1aiArh/"; 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 DDE598352A; Tue, 26 Oct 2021 10:26:49 +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="b1aiArh/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5773283381; Tue, 26 Oct 2021 10:26:35 +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-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) (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 4972C834CD for ; Tue, 26 Oct 2021 10:26:25 +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-x634.google.com with SMTP id v16so4414709ple.9 for ; Tue, 26 Oct 2021 01:26:25 -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=ZfhVmo77rYEAtoSBeJpMlpKrIxravrVpVSpi7503kLw=; b=b1aiArh/GvDTvDTaXI1bX2f7Cpsrf6NPRJeMrkm3uEGNgjt6rhseO4AmlDnSU8tPUV D4oRoStSLTkrasV7AtILgwKhZFJiEqEQ6SPJUILqQEU48ReUIbD3iNzpCONp732HWg57 95EBI5ZQV+B421ODCjLr7kK7o5Zyq4lF10Ko3f4dyv7RfaynlomLkMRwq546vk8Z7SBw tI0GVSUfCyj6WB2KHIS+YWZlRlf1d/vvZOQjk8IzNZKBepcyntCrjKso0Vk/ov+1oLqN HAOsc0GT9MaFx28uzOZuhQv+bFEG9pl7I74Ee75nxzVZbPIw1zbGQNAE+NKuZLEfNSgP KG1Q== 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=ZfhVmo77rYEAtoSBeJpMlpKrIxravrVpVSpi7503kLw=; b=HbUJtc1x1VoikAM4sYrpTTRpm5r5kyuOUWqc3uczxYbuKmfsTOsJEINAZ8ewVkXYCG 4YQyujQ8kolY5V8bsPNFT+IYCPZhyeZh/Dmio9TZr7D+9VtbD4XWENhJJIU4ARIv/926 18wACm2Y1n3uVn1JkZNsAHQLUJbYJ7mHIcVWIQWS9ApkRqoG4Xp+GWQJU7BXeLFIzRI9 yJ+Ere5QZPsp6jvq2zlnMP267VRrfFgezCNqxoTeGe8zUYkw1GmTEhniZA45aBpqn7Qg GXI6RxrWykzonq5Bt/SsUF81/hJ0r+Tk03MJzw8BVGsJT0PYrWMKb6f2D8bPgRMKlt5H QlDA== X-Gm-Message-State: AOAM530OklZ1tD3FKXnzDUJz9MSspGET5kFA/tXR7UCp72SRmlhZ4+30 hFOTgUHmCltlGUXeDoZYmnxDN15R6HB/CA== X-Received: by 2002:a17:90b:d94:: with SMTP id bg20mr24010565pjb.63.1635236783728; Tue, 26 Oct 2021 01:26:23 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 01:26:23 -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 4/4] efi_loader: add DeployedMode and AuditMode variable measurement Date: Tue, 26 Oct 2021 17:27:27 +0900 Message-Id: <20211026082727.23399-5-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 adds the DeployedMode and AuditMode variable measurement required in TCG PC Client Platform Firmware Profile Specification. Signed-off-by: Masahisa Kojima --- Changes in v4: - use table and loop - update commit message Changes in v3: - read variable first, then mesure the variable lib/efi_loader/efi_tcg2.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) -- 2.17.1 diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 6545ec9e79..6f0f36394a 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -84,16 +84,19 @@ static const struct digest_info hash_algo_list[] = { struct variable_info { const u16 *name; bool accept_empty; + u32 pcr_index; }; 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}, + {u"SecureBoot", true, 7}, + {u"PK", true, 7}, + {u"KEK", true, 7}, + {u"db", true, 7}, + {u"dbx", true, 7}, + {u"dbt", false, 7}, + {u"dbr", false, 7}, + {u"DeployedMode", false, 1}, + {u"AuditMode", false, 1}, }; #define MAX_HASH_COUNT ARRAY_SIZE(hash_algo_list) @@ -1822,6 +1825,15 @@ static efi_status_t tcg2_measure_secure_boot_variable(struct udevice *dev) efi_uintn_t data_size; u32 count, i; efi_status_t ret; + u8 deployed_mode; + efi_uintn_t size; + u32 deployed_audit_pcr_index = 1; + + size = sizeof(deployed_mode); + ret = efi_get_variable_int(u"DeployedMode", &efi_global_variable_guid, + NULL, &size, &deployed_mode, NULL); + if (ret != EFI_SUCCESS || !deployed_mode) + deployed_audit_pcr_index = 7; count = ARRAY_SIZE(secure_variables); for (i = 0; i < count; i++) { @@ -1833,7 +1845,12 @@ static efi_status_t tcg2_measure_secure_boot_variable(struct udevice *dev) if (!data && !secure_variables[i].accept_empty) continue; - ret = tcg2_measure_variable(dev, 7, + if (u16_strcmp(u"DeployedMode", secure_variables[i].name)) + secure_variables[i].pcr_index = deployed_audit_pcr_index; + if (u16_strcmp(u"AuditMode", secure_variables[i].name)) + secure_variables[i].pcr_index = deployed_audit_pcr_index; + + ret = tcg2_measure_variable(dev, secure_variables[i].pcr_index, EV_EFI_VARIABLE_DRIVER_CONFIG, secure_variables[i].name, guid, data_size, data);