From patchwork Mon Dec 19 15:12:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 635119 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2385852pvb; Mon, 19 Dec 2022 07:13:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXt/+Juz0sEY/DK6DCPtE7mlEmZFY7Yhofcp456DC5IrNJetoUSmF6J+9BNtf59WwMnMrvpl X-Received: by 2002:a05:6871:4605:b0:144:d26f:a77d with SMTP id nf5-20020a056871460500b00144d26fa77dmr4718944oab.25.1671462789092; Mon, 19 Dec 2022 07:13:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671462789; cv=none; d=google.com; s=arc-20160816; b=JMfPMvLSKljZGst+gYjmNWyzi9D8UyPvoZeCCCy6DHAlpT5k6Ba7kmhGTbyqgT6Zop yyn1Uu/LvPtLw68fveK9fJIwycu/3hM5DR3f3Jiy8H5s8Zh2lMgBE5bap1zHeWztFxdg zemrFBXkC33xch6gxbnt0V22aaD6VW6zvov4IDAsoL+LWt1AeVHvu6USar/Q8j0n0FVP v3x/xT4x73X+bvYSIasysT6epWNGkXAVigqqP8kXccnTKAUWYvvqI1UEil5DmNoKZuA+ C1n+wuZVryvNJKk7fScqXCt0YESiyh7PM1Oy0jvNKWJ0ZfDuDPPKROqXcyZR+y1gFEVZ Xfzg== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=45C6kwcEfMxSC5N9p8jXgp4iaKt7RLXKU51+F6KwghY=; b=DURmNrCrqKgiNJh79nsJyzAK0/N2PDkIhpzyQYGc2RruwMLLiE0lExSpZQBpPw/sqR VkF9TEYuLe0Lb894ju3lyxAnQh9+BfhnwTgD7YJZJ/wD5wz60syCyhxTNnC0RP43lhhS A+fp7SwfaXa6xVTI6voLi+0lsc4lkMpFLx69CfeT9dxDcmUbFclel6BndkrjCgbUz8JI EEiDwl4X2dK/T8MDHc/cP26m1+GpYRgcb53NE+1cWf3CYL82IjSOvgx7p8JmMUUqyvha W9U4XZVIqBXFkuUiw3jj5IuE8nKeharWIGpWeEbwyW1GA4dxjHUKaUwiNCCt47uH+Fqp w/lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KC5ttklw; 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 f11-20020a056871070b00b00144e25525fasi8227464oap.241.2022.12.19.07.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Dec 2022 07:13:09 -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=KC5ttklw; 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 3D4D985170; Mon, 19 Dec 2022 16:13:05 +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="KC5ttklw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 32A388517E; Mon, 19 Dec 2022 16:13:03 +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-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) (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 E301F85165 for ; Mon, 19 Dec 2022 16:12:58 +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-x102b.google.com with SMTP id v23so4132377pju.3 for ; Mon, 19 Dec 2022 07:12:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=45C6kwcEfMxSC5N9p8jXgp4iaKt7RLXKU51+F6KwghY=; b=KC5ttklwjj3zLNoZDLUhpqOPczy39gBhemHq7rsAKRHtdR2ljabXTwq4k/Tano+8tO WZZzPHWE39iraWl3tLpwqtFDz/YzXwGh/P9lV//UBur9Fsid2s1v5kDNFmB3Q3LFjiJQ w6CRNCXaWNVs9eg6ArABPO9VdqRydt/LHyOBhNxOWC5E6F8h9VSmJchltW2XlyzkyvFh 4Xf3bn9uxVpp/sRk8wSVJ1Y3/82gkieueaczPcbEu6jfRO3lGSEsHblqILtCVjtHnA3y lqxtJQkwwXmXaewd6McT5mOvZ9xX4gJBbTA695wzwnPkAAHBbMKdr4TQEIzAOxArR/93 q4kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=45C6kwcEfMxSC5N9p8jXgp4iaKt7RLXKU51+F6KwghY=; b=sIpScmFV60wJlsDIhtukxezzE/m/P9bLZWTBmf6eoui5MMFd6NxPcbioZGlua7Xxty nI8sFcAIYRdtNuGVtpJaRaIgvhcwhEEauva69eT1moUu9pqTAjJMXCenOUgsIWr0QnKw p3C2fDrz+VY73EUzfkyK9wJq9HliI0SZjW4BSezjPm7uZIV+Fofw2QSEq+iV//mvFtX4 YMLX3JDj5pHUUy51iijbizrv4d2GfDh/l9t1vZi8Cj/02yyy3NcUVhN2HLWAZNIS1o5R hGEs6dvOtGbYoQpcNSi8zPizY+qPl8Yk6bEFiLcT++HWBGk09uJK2rYPEQmc3XhxzdXf XaNA== X-Gm-Message-State: AFqh2koaM1aOQlCUWHlqfESksvp1SKVz5Idh89fMOtKCk9g29oUbwmS4 8MiSMo89HM6FUtJBc9VSBxAGdDn+dqwl1f0s X-Received: by 2002:a17:902:bf0c:b0:189:8329:dba8 with SMTP id bi12-20020a170902bf0c00b001898329dba8mr10765130plb.39.1671462776877; Mon, 19 Dec 2022 07:12:56 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id ij23-20020a170902ab5700b00186ffe62502sm7230222plb.254.2022.12.19.07.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Dec 2022 07:12:56 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH] eficonfig: EFI_VARIABLE_APPEND_WRITE is not set for null key Date: Tue, 20 Dec 2022 00:12:56 +0900 Message-Id: <20221219151257.23623-1-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean The signed null key with authenticated header is used to clear the PK, KEK, db and dbx. When CONFIG_EFI_MM_COMM_TEE is enabled (StMM and OP-TEE based RPMB storage is used as the EFI variable storage), clearing KEK, db and dbx by enrolling a signed null key does not work as expected if EFI_VARIABLE_APPEND_WRITE attritube is set. This commit checks the selected file is null key, then EFI_VARIABLE_APPEND_WRITE attibute will not be used for the null key. Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- cmd/eficonfig_sbkey.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/cmd/eficonfig_sbkey.c b/cmd/eficonfig_sbkey.c index 6e0bebf1d4..bd2671bf8f 100644 --- a/cmd/eficonfig_sbkey.c +++ b/cmd/eficonfig_sbkey.c @@ -72,6 +72,30 @@ static bool file_have_auth_header(void *buf, efi_uintn_t size) return true; } +/** + * file_is_null_key() - check the file is an authenticated and signed null key + * @auth: pointer to the file + * @size: file size + * @null_key: pointer to store the result + * Return: status code + */ +static efi_status_t file_is_null_key(struct efi_variable_authentication_2 *auth, + efi_uintn_t size, bool *null_key) +{ + efi_status_t ret = EFI_SUCCESS; + + if (size < (sizeof(auth->time_stamp) + auth->auth_info.hdr.dwLength)) + return EFI_INVALID_PARAMETER; + + size -= (sizeof(auth->time_stamp) + auth->auth_info.hdr.dwLength); + if (size == 0) /* No payload */ + *null_key = true; + else + *null_key = false; + + return ret; +} + /** * eficonfig_process_enroll_key() - enroll key into signature database * @@ -84,6 +108,7 @@ static efi_status_t eficonfig_process_enroll_key(void *data) char *buf = NULL; efi_uintn_t size; efi_status_t ret; + bool null_key = false; struct efi_file_handle *f = NULL; struct efi_device_path *full_dp = NULL; struct eficonfig_select_file_info file_info; @@ -149,13 +174,24 @@ static efi_status_t eficonfig_process_enroll_key(void *data) goto out; } + ret = file_is_null_key((struct efi_variable_authentication_2 *)buf, + size, &null_key); + if (ret != EFI_SUCCESS) { + eficonfig_print_msg("ERROR! Invalid file format."); + goto out; + } + attr = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS; - /* PK can enroll only one certificate */ - if (u16_strcmp(data, u"PK")) { + /* + * PK can enroll only one certificate. + * The signed null key is used to clear KEK, db and dbx. + * EFI_VARIABLE_APPEND_WRITE attribute must not be set in these cases. + */ + if (u16_strcmp(data, u"PK") && !null_key) { efi_uintn_t db_size = 0; /* check the variable exists. If exists, add APPEND_WRITE attribute */