From patchwork Wed Feb 15 09:55:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 653687 Delivered-To: patch@linaro.org Received: by 2002:adf:f90f:0:0:0:0:0 with SMTP id b15csp240344wrr; Wed, 15 Feb 2023 01:55:32 -0800 (PST) X-Google-Smtp-Source: AK7set+s45PeXijp/40hwr5eFdKMS9KivgOw0wWKt0kfD3hac2Oolx2gshtf5+668r/Tq9gRNz9U X-Received: by 2002:a4a:987:0:b0:517:7580:4764 with SMTP id 129-20020a4a0987000000b0051775804764mr771632ooa.0.1676454932160; Wed, 15 Feb 2023 01:55:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676454932; cv=none; d=google.com; s=arc-20160816; b=E7Qq29gJ4kjKHGI84ADp/N+tkS2zPOPkPdNSCwLBDcpQMKIIdBiDLLB9Vgw+yUKNG+ qBXJnPaSEsE+9N4md8O6NJZt99ODuTiOg/PAhwVWrTql8pLRdDq4+hNcVE2+jOPk18nM SiVOtG6ndum5QfRUd0kur5GC7aYSOWRVgXOOck09ueNQhVKxLi2gZ5R/WTsRc0NZDb8F 9wYz1HxW3Aw2gDQGGNQrwhmlw+H2yrhv/fTl1fcZNzeSUwK/GyGjDXPr+GH0I0PfZnqi RwgkjEodGtUTZZ77K+22ag7YrWjtBXkaBfQeiw6h+xhknHYhybrlK4qAMknwS4VcwscL cjHQ== 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=WBy2qsTQ+f4rh2uPDi0SD6GVEPQVvrTe//VCQHWp10g=; b=cbklR+PHNInJzr3rdreJUEqVH97049+sDqw50ObwZqtq5H5r9fOcN7+IUUSV2P0YMs VMHIipoEADO5lit+LPByBBEBrXHV98ktTYebyAwlyAigZ+lZgsn7IkAmx6dewaXv2yfi PrRn0CvdrPVun6VBW7BvCCtS1GmId+jFgl0Jwk+wxrYIRT2FV82bjw5ENjFV7/CoZtnX HkLxGaZyPsRbYS+ZpjWq1BPyKnf48U8Vu1PM4gI3DpwdfhfDtXAF8bjc0FeXrQMZZPqj iU2Cs17dieymavsmLntL6dRdyV9hHQiOO30xfB0jt7C8HMWGbgYA6br5dPeJNSGJmCnt W8fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HPefRbKD; 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 v15-20020a4a244f000000b0051a1462f06dsi19993910oov.60.2023.02.15.01.55.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 01:55:32 -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=HPefRbKD; 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 A1ABC85A16; Wed, 15 Feb 2023 10:55:29 +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="HPefRbKD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7EC3485A22; Wed, 15 Feb 2023 10:55:27 +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-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) (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 45E7585A2A for ; Wed, 15 Feb 2023 10:55:09 +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-x1032.google.com with SMTP id bg2so8389057pjb.4 for ; Wed, 15 Feb 2023 01:55:09 -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=WBy2qsTQ+f4rh2uPDi0SD6GVEPQVvrTe//VCQHWp10g=; b=HPefRbKDu7KNSPYynhZceKd1a3FwB9NbD/Btzrdl69kkLUzEjCQV9ps247yt0imXN6 /rxsOCVoBb86j3WfPLC0+iJWOclySNcxU24T+/RONzEh42cLHe1moF2VgElifqb8URpd kKoJiIW0FtP8+6b0dyHN3NzIk/9GLsLEUN1saJlU32gYIqw/9WnQ9qFKLoSacxcj3GEz b4QQ26Pm8B3qPBtlxd14NzoxgvrDsClxezMxcJowII46qmspGEd7r1xDRVlbuF9Og7OU +bRZH/eoA1uvIR/nGLgGPjQgw2w/olHWVXEaMFmP7jgisYnee2XwGOrHrlcB4yj+X7fz Eokw== 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=WBy2qsTQ+f4rh2uPDi0SD6GVEPQVvrTe//VCQHWp10g=; b=otPyxGynhyc8T0QzD1rE1uiklrrFEv8eUP64MQnjD5BX3eS8J6kR05NnrFl6SV7Pjc aUJT7I6T4RieRYsdyBi20Z9fEFUYUzRgTukYEfFzw5g4K65GtW4yYvbHDZ5KgbHxMady oinVivxe90jvhKpr533/VFOZfkjh7buHPuSOi3WSgONKhloOJScm/MCwpeb5tTgGXzQm LK+wKp6sxsXX+8XUqUezTy5wOxO0YJXanlZ/ZdOBjO/hXXaq77/LZ5jUNRrwhB80sl9I RepFVtjExV+4pepqyYO99s00d2R5Fbd2LOiPebU/rodyIWo17Y0b0ZSCm2sAG+nSJKIw aAZg== X-Gm-Message-State: AO0yUKWjfnbL3EKKEgiIkALvT0yrHz6DGehd0J0XrDDOMk5PRsnDT9/p Vj/RAMd+4KiiqZ46wfVxGtkyRXgcxyPhL2iZghw= X-Received: by 2002:a05:6a21:29cb:b0:bf:6e94:3721 with SMTP id tv11-20020a056a2129cb00b000bf6e943721mr988279pzb.26.1676454907116; Wed, 15 Feb 2023 01:55:07 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id v8-20020a637a08000000b004fbe67bab14sm1432692pgc.0.2023.02.15.01.55.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 01:55:06 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH v3] efi_loader: update SetVariable attribute check Date: Wed, 15 Feb 2023 18:55:54 +0900 Message-Id: <20230215095555.30150-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 v3: - accept no access attribute for deletion Changes in v2: - fix coding style - HR must be set with NV lib/efi_loader/efi_variable.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 4c85cfa607..3e11373331 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -230,9 +230,30 @@ 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) + 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 +302,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 +319,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; }