From patchwork Tue Feb 14 09:19:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 653457 Delivered-To: patch@linaro.org Received: by 2002:adf:f90f:0:0:0:0:0 with SMTP id b15csp2922564wrr; Tue, 14 Feb 2023 01:19:27 -0800 (PST) X-Google-Smtp-Source: AK7set8aZCwvXmdqn5MQht4KL7S/UjtMTbaNUJLud8Ep1iAyMBHbDORu7JJ6Qq9Y1HxC59Oe1Gbj X-Received: by 2002:a54:4896:0:b0:36e:cc57:33a3 with SMTP id r22-20020a544896000000b0036ecc5733a3mr752857oic.22.1676366367088; Tue, 14 Feb 2023 01:19:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676366367; cv=none; d=google.com; s=arc-20160816; b=Yy8KDMKdOcSv7aKqKzpiCFdEll7rRsfMeLCtVDOfRa0CqhOD/zgrzrpWEEdYjF/3PG vJrAQf4paIeCTo19R3v+MWVxSD64XlzP5NXpAKMFII4i+htWBPDZjlx4qJs+dOMMGzSp DExm4aHEklqJm8Q/8Vc1mcMokrh/KkpYVcBM4dd40yDRor13FvEjQpbqJkRWrFc1CKJ7 MCveVfysH+BxYq3CrGpnCuLkt0dTBrXliQE4N/hCVjjVYyqe7vLF5z13PL92vdGURcG2 IagNj5uc6+V3+rpjE0K5PgYJgwpDwP40pH7lVGQGNNxiAKjmLTai7u2/zCaENufZALZO nC1g== 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=iSMjqdRaadd3mAuU5AJF+Ke3nVeNQNfDbxQ1Z9QbZxA=; b=Dc8SIy1U8ZSL+jQg39awPaR3zh0+nGe7GJkhguTe7IfMUZc1F8uFvvMnIdQTbj7zzR j0gBQNJsElyoQVrtc95QsfR8pBgC29T5ndpYHVrhowOJLO0IhuWBMzHjDTOivEYRzvHv lnvr7cTv7c+NBH2exSky5nE+nhDhGMdjQhac3SwbyPjLKKfgoTwQ919kScE8tQIJ0hTy MS01gLtvVok74oFJVDiFcDnrRNjWnK+Jc+TEtnyGuUVoo6ieyAWE6BSDDMB5+9hi5ocr VnAdo8IZ4gY9AvbSuMxvz5QtCuO1YT3XSjnDrFJHKb3l0fBE0bRzh2HrjLk2bTAG7HA8 Jg5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dEaFuXKm; 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 v192-20020acaacc9000000b0037b827d980fsi14247605oie.213.2023.02.14.01.19.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 01:19:27 -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=dEaFuXKm; 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 C00A48588D; Tue, 14 Feb 2023 10:19:21 +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="dEaFuXKm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1844180BB0; Tue, 14 Feb 2023 10:19:19 +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-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) (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 568CE85890 for ; Tue, 14 Feb 2023 10:19:11 +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-x102a.google.com with SMTP id nh19-20020a17090b365300b00233ceae8407so7301293pjb.3 for ; Tue, 14 Feb 2023 01:19: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=iSMjqdRaadd3mAuU5AJF+Ke3nVeNQNfDbxQ1Z9QbZxA=; b=dEaFuXKmMHtNODkqzLZxYi/1QP0PM3Xo9kvjY3oCDmL2oc1VUhGxgR/R4tmHmO1pSl tMJv1kb/teQ8lCUvJBOLGQT3iieIOZAzYJ/NnlZr8drylWIYsF+a+gNHKosNBU5PuEPs oYJhIrcyXZ6i20GokURnScKzr95/HU6/CCKgUmAE8aIMmTzuoi1v6kQR6Cf4eoI0oueU 9H0RuKvxC2zWQz13OJWZI4QVnPYj45KJhiaYZ3eiV5nwF0hcdQLB6qpetdwSJRsZVlS/ Lz/p7nmL+RIVwe/jeGPHZCIGO2v/eF28j/qN0u6YH4BmfoiJjSFfR6IVpAX4SilBJsdQ lVPg== 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=iSMjqdRaadd3mAuU5AJF+Ke3nVeNQNfDbxQ1Z9QbZxA=; b=kbRZkReQjFNjDiDLR3AuKChaPTv2wiJ7ylEMVziax/k5LwNrQ7rJIQz/ROIWZqWiZP 86RmPvrymOACn/Q3e9KwfIPyhMyfc4TQiD8lLTl4cSMpZsigYhgFDTX4/MHWqezjEFsG eHQKoHeV//5G77fiFJWuy4eEw+SH4cqQkAuuvxIJTdP9CPXMPwPRwNOJfS2dgAB+XzwC k74OoN6gr+vdFdsHfHcJhdpy544WuWJtLai4dlfKS8LCxNH9zgHy3vAAWObFyPioo8Fj vzUDZ6/ElPu+5HXAe7Q5Qx0PhR4bOi+UOPQltqI6arDoN/bPLj4iVNvYdNOYo8psejpz Gx9Q== X-Gm-Message-State: AO0yUKVMHLOZOdBUr3coEoe1GlrVAKpi1BokJvLE6jCw7fr4MjlCaglx eeO9c8BIHZQp1jtVRlIaS0b3T4KHPx/SKagGWxs= X-Received: by 2002:a17:90b:202:b0:230:a7e5:b42c with SMTP id fy2-20020a17090b020200b00230a7e5b42cmr1736176pjb.17.1676366347821; Tue, 14 Feb 2023 01:19:07 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id gj5-20020a17090b108500b00228f45d589fsm5493929pjb.29.2023.02.14.01.19.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 01:19:07 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH] efi_loader: update SetVariable attribute check Date: Tue, 14 Feb 2023 18:19:43 +0900 Message-Id: <20230214091943.30544-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 --- lib/efi_loader/efi_variable.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 4c85cfa607..1076ff7585 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -230,9 +230,28 @@ 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 != 0 && !data) + return EFI_INVALID_PARAMETER; + + /* EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS is deprecated */ + if (attributes & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS || + ((attributes & EFI_VARIABLE_MASK) == 0)) + 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; + + if (attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) return EFI_INVALID_PARAMETER; /* check if a variable exists */ @@ -281,8 +300,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 +317,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; }