From patchwork Mon Feb 20 10:31:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 655069 Delivered-To: patch@linaro.org Received: by 2002:adf:9bcd:0:0:0:0:0 with SMTP id e13csp1317124wrc; Mon, 20 Feb 2023 02:30:40 -0800 (PST) X-Google-Smtp-Source: AK7set/a71HukmHxP63YiYSXvoSoLYtRSX0PtSUSU+6GD9IliQhFIVVifDWGM+thyaUUprijverW X-Received: by 2002:a5d:5610:0:b0:2c5:8dac:fc5c with SMTP id l16-20020a5d5610000000b002c58dacfc5cmr1221563wrv.2.1676889040113; Mon, 20 Feb 2023 02:30:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676889040; cv=none; d=google.com; s=arc-20160816; b=WOw8G/YcMgDxN0sI/9OgLOtiAVwnvh38Qo0hEm86EQLoR1HKhwwg2XqSQ8QUf4RlZR yjuOqYI8wIznYOqjfSJMjSnUPquXFsCioAgW0Yzc82GdoaQ4rMZNTOnZK5i9Fe2Q+HGh hbFIiSCaWvcmMKK1ECKALRn9NI6XXkHyeeFILgMD90VNVS8CEfMu2n1a9L5QUKdyj0ux i946szl1be7O64PWWgLOv2mQQh6n294U0tCIImPJTYfq3g7oKeV1ryafEc3OjXOwVskw rjcAqGxsOlVmShyPlrUHUipJql00jcwlOY/hznap6weHBPnzDAD1wA3rZ1SdzgD6nSf7 JzCA== 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=EG9cYxswdNNQTUallSo4z3/nW4TkVpqyOgR7LD2S31w=; b=cAKuQGePLWTWOdxvBw6Vb/gy9jRicRAE1ZsJ+QA3CGUtAw7P9JF+yol+TCGa6gtshq O8EV4/Xb2OZTFulU3ZOcW/N8qKa8Ve1TO6z5RDpjTGQhpj3caIn4gNmAyfgP96kWAvku t7y9Kzw22jnxYfOR/mDXfSpdSuDiZWOq68bghbzc/lUTxDBsgorkZaO1JRg0tPV0m6Vk akHw6Q9xpL5DgWsT25TSsALunxEqC+NvTk9byg44sZSZi4AVdXHLqfdb/X/VoCdvgL80 HEhJCiuoE4nzEfNibthpZqKL2m+PU3/fj43aOqP0cnRfIqCdMPX/iDjHG+DaRfBOQPfj tp/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=urAD5+yB; 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 b7-20020a5d5507000000b002c55e9b146bsi13558592wrv.83.2023.02.20.02.30.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 02:30:40 -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=urAD5+yB; 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 79B0A84CFA; Mon, 20 Feb 2023 11:30:35 +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="urAD5+yB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ECE4784517; Mon, 20 Feb 2023 11:30:32 +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-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) (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 780638547B for ; Mon, 20 Feb 2023 11:30: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=masahisa.kojima@linaro.org Received: by mail-pl1-x634.google.com with SMTP id h14so973193plf.10 for ; Mon, 20 Feb 2023 02:30:29 -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=EG9cYxswdNNQTUallSo4z3/nW4TkVpqyOgR7LD2S31w=; b=urAD5+yBBPGjVhSO7FIRW/AOR5BmxOSKTkGUs+rGJtZR7eimu3V5QGveuTgfastjaE 33weHMyCIZW7xVt/tMpkE5dIDttHd8kHcDLmB3hlOiEBlPToszepT0zcHo2p7IIXj8PC j3tnRd/UyLyP304/xIv70mqcf1+T/r7o+ca0MP4A897j1DJ+fT2et+JkfjakgtVxKLn2 C4xeD+fhFq14UHyDkXNKkGvqLKz3iVVZ75WVaTA+R2Kw3x9QsgnChIUfx13ZkYaTrFKr it9QiIY89LrX9J+urvU5IiZAivHCO1o+D5Ys8bc2UuP1hFCYJ2esI+QNsR93DvZHdOlw hnVA== 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=EG9cYxswdNNQTUallSo4z3/nW4TkVpqyOgR7LD2S31w=; b=p0PjfRZei60JbKz/EQAL18KkRWFYlheqtc+3WI2RTy9hlKA4+QaRqcBoNZaXZAA5+W flx2qIeim9z3XyHyIQg2BHaL9cVKAubWxzcvZdf5f1on8YJ3CJH7f4lVrzzigW1l3YKv uxR1cZ347ZmjeVzpLTkAtAUcseMkjKJJJfQqf1807jMFTBo7wv6usYW4Z72Qqa9IM21b VJvSo1WTte7u49jF1mtc9LMLZO6k14uRJlcAPfF84IMfxFaV+bP6yWAlpb1IAjCv40Io ORFOFQ1sUwFT1dDIRyuGPWe7KJPWS++gtIUYi3aL0ODBrVbO//k5oT/bvQsDb31ElCtJ yJpA== X-Gm-Message-State: AO0yUKUWauQWzElagFkxkSOb+iV+dZWMdKbj189FyaFBlq7S9CLV2oZg WRnXVo+h4JayYQst9CLEO9NUunXQePTrd0C85Sw= X-Received: by 2002:a17:902:d4d2:b0:198:adc4:22a2 with SMTP id o18-20020a170902d4d200b00198adc422a2mr3717330plg.29.1676889027323; Mon, 20 Feb 2023 02:30:27 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id j10-20020a170902c3ca00b0019a777ff433sm7550312plj.17.2023.02.20.02.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 02:30:26 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH v4] efi_loader: update SetVariable attribute check Date: Mon, 20 Feb 2023 19:31:48 +0900 Message-Id: <20230220103148.32317-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. UEFI specification says "HwErrRecSupport" variable supplies the level of support for Hardware Error Record Persistence, add check of this variable for EFI_VARIABLE_HARDWARE_ERROR_RECORD attribute. Signed-off-by: Masahisa Kojima --- Changes in v4: - update HR attribute check(need NV,BS,RT) - check HwErrRecSupport variable for HR variables 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 | 43 +++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 5804f69954..f25006badf 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -230,11 +230,43 @@ 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; + + if (attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) { + efi_uintn_t size; + u16 hw_err_rec_support = 0; + + /* Make sure HR is set with NV, BS and RT */ + if (!(attributes & EFI_VARIABLE_NON_VOLATILE) || + !(attributes & EFI_VARIABLE_RUNTIME_ACCESS) || + !(attributes & EFI_VARIABLE_BOOTSERVICE_ACCESS)) + return EFI_INVALID_PARAMETER; + + size = sizeof(hw_err_rec_support); + ret = efi_get_variable_mem(L"HwErrRecSupport", &efi_global_variable_guid, + NULL, &size, &hw_err_rec_support, NULL); + if (ret == EFI_NOT_FOUND || !hw_err_rec_support) + return EFI_UNSUPPORTED; + } + /* check if a variable exists */ var = efi_var_mem_find(vendor, variable_name, NULL); append = !!(attributes & EFI_VARIABLE_APPEND_WRITE); @@ -281,8 +313,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 +330,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; }