From patchwork Tue Dec 20 10:38:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 635432 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2836729pvb; Tue, 20 Dec 2022 02:38:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf63SVwnqf+sV6lhI4Qj/kslTR/K9iFfi9ehJXpEmRfF19HXlpqVevWuV4WUKUjl9CYmozkO X-Received: by 2002:a05:6808:e8f:b0:355:2e6c:2d12 with SMTP id k15-20020a0568080e8f00b003552e6c2d12mr22976893oil.52.1671532726646; Tue, 20 Dec 2022 02:38:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671532726; cv=none; d=google.com; s=arc-20160816; b=jgxoQLEaptE7k64FPTmiO0YpcSKGJyEvwfiiIaQU8IkdsZQA/SCzl2MmqVexiKHtI2 jcvka4GtwFnZrQW8mAwjtxs44X4gD8dAEP0bWN6xxvLabru9s0fIRmn5fuJInYseB0BC /vEb/i4FN1f0ngWwkmH/zOfx9s7GCXbQtGxMqfkOKNJBkPkHVkGb6D1RHY/3sZiNxSWi kQwsMVOjeOcWhNe+O0QRbIkoru3Ga0iBQE/p6L1V5T2jFmj81mMS4z/4GKCrVsMF5cLK aGJOQFz4iSVOY0NuioV3zt1BhsLC1Wo9p9AS+vuP+6V++aLe/QVt0uWX+kyJeFRQ/QbS K7Bw== 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=+NnneuCRi3h72PdLX5VBnZ+J5b4uVE04iCf25luiMlI=; b=wyLTmvMK1XoN7yzv8uGB1nKi8q29KEXUOZcJE3bFXmrvoG3pUAFTvzMhZurg2qUt8V 6kFCP+WzfeXB6vKsJ9AfmKNs4jPVUKzqgIiWXgp7PAn+8GdPBsG/C/8OkpiHSyjNQIJt ZrgfNNz65gBSZTtrjJktr5JZuPnEYKZW3ZljoOt/6gRFEGqRAAeolZij6TBA+p022rn2 MCOEWUArMz7YWr2hx4xOTxBb/Rt0m/4xNfekLUrA+Z5rApB9Qk6oZVuL8ot6puPWbpcO RNnT9UMthhxQWk6Ax8db8zQLtVTzb4kpcj8iwGecyGBOrpMOypD8je6nXU8oANgBvFI2 +MHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oSFO5TsS; 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 15-20020aca280f000000b0035e7ff9788bsi9104158oix.284.2022.12.20.02.38.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 02:38:45 -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=oSFO5TsS; 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 3908384F87; Tue, 20 Dec 2022 11:38:42 +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="oSFO5TsS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 34FA584881; Tue, 20 Dec 2022 11:38:40 +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-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) (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 81B5F85174 for ; Tue, 20 Dec 2022 11:38:37 +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-x102f.google.com with SMTP id o12so11978423pjo.4 for ; Tue, 20 Dec 2022 02:38:37 -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=+NnneuCRi3h72PdLX5VBnZ+J5b4uVE04iCf25luiMlI=; b=oSFO5TsS3EZypt+deM9TWdMNTtqkfBUiB8Geev59VuDWRErGI8V3PwVKZv3j0gRTMb yNnwTuVkySif4nrmIRSifHDR7F6o2hoF43D+fbQ6dxojmYBQQz6my1EPDoJLWKoY11/E p8DSaAukAj0wZum5lnKTOZB2I4tymhPqi0O5dLxJChBO1e0DcZf0F3YKf0D3pMgT6vw8 OSuw8uU0gon3Qyv3eUCXjD/hLGRK4CAk3BTIQ8vyIAazEo6ZGOSNYeecL4xgXYfBO2Q3 uYokmLtmFrdLAhQallxTInXV+nvwWZGxOvctth2CiQGOTID0qmLemmpFGbKgRWTVx0Dc GoCg== 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=+NnneuCRi3h72PdLX5VBnZ+J5b4uVE04iCf25luiMlI=; b=dg96aYkh0IlGcvByG2L0or4VatcxbhxBeBj9gD+Hxz45JLwmzZmGqtwR0vjf3as0lw BOdGjsWZnZZyoVVRYtKfZN1OsaAGy1Qd2oMN+2X8yYSwoBfSlyhwQld4Z+lG6z8NpavV B21ZdKwB3kgMwdX3n1oPCEDBQsOZQk/7LqDes7L/aiCjsdLKy/hIFR2ISEO/B1fyikAB YHF+lP17wj8UlQf4ts8bwIPPRoaaAx0enJpeLazNzvylJRBwpFbFh6/FToqmnMkCI5wN JMObFB+CQ06tGoegtvSukzvR+5ubJP59/JomoNyxXcrCfz7dpxs4lTNmjyfZZYHT/ZGS 1S5w== X-Gm-Message-State: ANoB5pkflvklbETGcH4q3NkH3ul8ywRTvqZ8HHPmBWUJk/WrAAGC/HDw y3uwS6RnGLUy25D4ubq7NIinENFINtB4Q7MB X-Received: by 2002:a17:90b:494:b0:213:1d5:8acf with SMTP id bh20-20020a17090b049400b0021301d58acfmr46639313pjb.18.1671532715560; Tue, 20 Dec 2022 02:38:35 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id q43-20020a17090a17ae00b0021929c71b14sm11144243pja.40.2022.12.20.02.38.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 02:38:34 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH v2] eficonfig: EFI_VARIABLE_APPEND_WRITE is not set for null key Date: Tue, 20 Dec 2022 19:38:52 +0900 Message-Id: <20221220103852.27180-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 Reviewed-by: Heinrich Schuchardt --- Changes in v2: - s/size == 0/!size/ 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..7fb0467543 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) /* 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 */