From patchwork Wed Feb 15 02:29:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 653685 Delivered-To: patch@linaro.org Received: by 2002:adf:f90f:0:0:0:0:0 with SMTP id b15csp90779wrr; Tue, 14 Feb 2023 18:29:10 -0800 (PST) X-Google-Smtp-Source: AK7set8bwkSmwr6q03uVuACdRlJIRRQq1rdWFMIxRNkeL4+6AL5fKghfKSzmLuuCDis6MQA0Wtoz X-Received: by 2002:a05:6871:547:b0:16a:2473:fa5 with SMTP id t7-20020a056871054700b0016a24730fa5mr379420oal.4.1676428149958; Tue, 14 Feb 2023 18:29:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676428149; cv=none; d=google.com; s=arc-20160816; b=IL2b/n7zv0+zb7lBqiaeBD4VbR+y5BytzqoKZj9JksKQCSarbpa2VBswhjwKbzHWp7 AC4bYhcwtvrTUxRBTbJj+fd9fLRbrpJcBOiYguHzs+vF/xyoROLIRaIO3V0lv2W4U2yt CeHRw4zJ7g0XmNEPN9GTZxHeeBTWR0cNN+uT5RXffMPGt8seA7prE3Wxh5j27Ridaayl 8grQqo6TV+achUzzAJVqkK16ieL6HtthwrmlA4XvmjMpY//gqbeeDMvAFso7E+5L7GgU QrVpqygLU4nP3n9C7UA12QlvllGkuT/7R2+0UYU5NiGVtK0LEKLjsScBV41YFKsRV8nc bheg== 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=Dr5zbF6aZ7Lv1Ss3cNM18EgbFEAJPBwRXZaM/6u2MC8=; b=aQ04gL7nNI0I77tsUVV6ya9/ClkL+298V4Ru695Bsv/Jz8Yy/C6pOJCbtze5a2Snf7 7zva0YkRQEftULoDMIYyuM59LPmX8CU6IAWRtIK3TpD2WNQEjF3SRsDt3Hy48m90M21L PZiTt227bKPYRg95PTgboyqDvglOVjoCO6XgiQOB5gGH8Bc9YUgSDdDVtZVooOhwdR/Q Vb7vlbu4MJI3u2Ig3NAjUFtatxFE6ijGCR8E9z+Rk9FJLFeJHFKaQD2fbWjid8Ggbx82 C5QJbsyCH0gMfZpiELWLkVDhSu/nyX9Cm8SSumAi7mARr5dInliuN6GyN75Vh4Edo4cJ 9YjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="l1NE/t5T"; 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 a11-20020a05687073cb00b0016e3be5f632si2914601oan.71.2023.02.14.18.29.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 18:29: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="l1NE/t5T"; 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 21074859E9; Wed, 15 Feb 2023 03:29:08 +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="l1NE/t5T"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D2D10859AF; Wed, 15 Feb 2023 03:29:04 +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-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) (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 43A6885854 for ; Wed, 15 Feb 2023 03:29:00 +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-pf1-x42e.google.com with SMTP id bw10so1752007pfb.0 for ; Tue, 14 Feb 2023 18:29:00 -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=Dr5zbF6aZ7Lv1Ss3cNM18EgbFEAJPBwRXZaM/6u2MC8=; b=l1NE/t5TUpV51SRpHgzVb/v1TLuL5sbC7tbvtrLIzX8cmtO1EMbeHGARGTaEtPdg8b F9EUe1eiggWKsulf3jI/k4k3zhxBHV3qkPTS5riLpGwtjEdADq+lCBNmYHNjqc9/Aa99 FQ4buxxvacPPyHj6T5/OP9nm2xtsW6AqBX/O/cGiC6QPf9KN4Xmi7cMnmnz4L1k0Gc7y ecJ9IjydncZ2SMsGSnmlluWdLieTIWziHgfJqwJ0fQCM4hgwmmEF14r/ycNFW9rUl1e+ KrWdi4a7orrmOpYyUZlmgzUttDE0/R7Jwo1OuzUKpDdjwl8HdOhCBzTVPDrmm9REex99 /REQ== 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=Dr5zbF6aZ7Lv1Ss3cNM18EgbFEAJPBwRXZaM/6u2MC8=; b=6zWsnem9Qyk3DK5x1lteKDVnMgq0C0LLR5DDuG7XvZbkZTW5+5iTnbjpeFj36idtcm 8dydpmiKhoIHXl8OHolOlVuGyQP+t8bavUzTdOpOSlAeOXtQEts63B0gl11fJYGVZCVY ut3VvDNzSeHlcseQifkyHs7AN/JsORC+W1sWA2hp/NZg7ikvQ6WgOiJNi7e3/Hl068xv xfSPHHp4c/4EvEshLjXholTkKTn+MCVtHC3e0173Ou6T08+BRsoibkXqJOs9RUJpecYO xhx+zSIthbIJrqDiIXFhBduzjYSmn4S8kdXVeRoM25wa+pR+V1nhsd8+1/A5DZKDQUgx tEKg== X-Gm-Message-State: AO0yUKWcymQeH/vl0L5j8fHVEVfy8rAxiGPw1MVZt4QTlL1Vv1Qbu62W cKqkg/gl7NoFtIFo9bBr+iObxo2/RkN1nFrtbto= X-Received: by 2002:aa7:978e:0:b0:5a8:de1e:2e97 with SMTP id o14-20020aa7978e000000b005a8de1e2e97mr327364pfp.18.1676428138476; Tue, 14 Feb 2023 18:28:58 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id n17-20020a62e511000000b005a54a978c1bsm10433660pff.7.2023.02.14.18.28.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 18:28:57 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH v2] efi_loader: update SetVariable attribute check Date: Wed, 15 Feb 2023 11:29:59 +0900 Message-Id: <20230215022959.8370-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 UEFI specification v2.10 says that EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS is deprecated and EFI_UNSUPPORTED should be returned in SetVariable variable service. Current implementation returns EFI_INVALID_PARAMETER, let's fix the return value. Together with above change, this commit also updates the SetVariable attribute check to be aligned with the EDK2 reference implementation. Signed-off-by: Masahisa Kojima --- Changes in v2: - fix coding style - HR must be set with NV lib/efi_loader/efi_variable.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 4c85cfa607..b12e79d658 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -230,9 +230,31 @@ efi_status_t efi_set_variable_int(const u16 *variable_name, u64 time = 0; enum efi_auth_var_type var_type; - if (!variable_name || !*variable_name || !vendor || - ((attributes & EFI_VARIABLE_RUNTIME_ACCESS) && - !(attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS))) + if (!variable_name || !*variable_name || !vendor) + return EFI_INVALID_PARAMETER; + + if (data_size && !data) + return EFI_INVALID_PARAMETER; + + /* EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS is deprecated */ + if (attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS || + (!(attributes & EFI_VARIABLE_MASK))) + return EFI_UNSUPPORTED; + + /* Make sure if runtime bit is set, boot service bit is set also */ + if ((attributes & + (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == + EFI_VARIABLE_RUNTIME_ACCESS) + return EFI_INVALID_PARAMETER; + + /* only EFI_VARIABLE_NON_VOLATILE attribute is invalid */ + if ((attributes & EFI_VARIABLE_MASK) == EFI_VARIABLE_NON_VOLATILE) + return EFI_INVALID_PARAMETER; + + /* Make sure HR is set with NV */ + if ((attributes & + (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == + EFI_VARIABLE_HARDWARE_ERROR_RECORD) return EFI_INVALID_PARAMETER; /* check if a variable exists */ @@ -281,8 +303,6 @@ efi_status_t efi_set_variable_int(const u16 *variable_name, /* authenticate a variable */ if (IS_ENABLED(CONFIG_EFI_SECURE_BOOT)) { - if (attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) - return EFI_INVALID_PARAMETER; if (attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) { u32 env_attr; @@ -300,8 +320,7 @@ efi_status_t efi_set_variable_int(const u16 *variable_name, } } else { if (attributes & - (EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | - EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS)) { + EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) { EFI_PRINT("Secure boot is not configured\n"); return EFI_INVALID_PARAMETER; }