From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 30B8BC433F5 for ; Wed, 16 Mar 2022 15:13:51 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 64203837C9; Wed, 16 Mar 2022 16:13:48 +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="M/zo7NEP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 889EC838AB; Wed, 16 Mar 2022 16:13:45 +0100 (CET) Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) (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 2143E803F5 for ; Wed, 16 Mar 2022 16:13: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=ilias.apalodimas@linaro.org Received: by mail-wr1-x430.google.com with SMTP id j26so3458033wrb.1 for ; Wed, 16 Mar 2022 08:13:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5Tm0JU7ckCZogR0vt9JmgJDwWIFEp+SpTTnZoMb7T60=; b=M/zo7NEP9y2zYZvIXHKwIIG9gsB01OmVFlA+tjgvAAIFWoKC4QmpAtuOvQ6MGhxSaI 2PCk1j9Sd8di9w6jEbIysL23pT1QH+ID+ALGxY+RgbIin2bkw+1Hu8N7VjSAkDKEZExY QIRFAuwNjy5EP9EiD1BmdCzC1jJT+LnS+QLutH9DZtE7ez3Oa8sXJiq/GmlCUfR6Eji+ ikTpin9P4MrBSBnllZZy8QQ/EUOB0n/nf01AgdzguCwm4+YxHwFqlt8YhArsFaOw66Al i991bpQ+MlrPZAYt64BM1JVrn02jrhTYMd+H6iPBPldchhaY7qM5pnpKhwvAxhk70eN3 UHgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5Tm0JU7ckCZogR0vt9JmgJDwWIFEp+SpTTnZoMb7T60=; b=Qxgtu/b6/HBn5jeAcTff4UjXDY/FLWJtyx75woP0ctfWiNyoAqGplp2cMRg+8iSqlM fVEkSXlbYaIkZ6/WS9/9k6lmFghJYnAUllD4kfI7daHEAoBXrMbgKgdaL/gIGD6YPahI 4GTcDW+YKGPcQyPieQuirjEt5IPSRtVLE6K7SnNqWxrYWMoEzxlxJKmdf33i+zqUCPJ9 57ikeVvZezRLua2bWVnPBYJDc+fMWzkYmQ1Vws9UfExzDWnAPYvA4y0aOe2/MTWaECUF VxOCmFuMiA4AwqtvYNB6RoqH/kiQhtoH3B03AwxeJyZ+F04ND383AXEVqIdGiXcLWutg Xsxg== X-Gm-Message-State: AOAM532HxBPetsOXD4ZkAOZYfO6RtoXy90YOTJWXglNanWUiJWuGGU9w qXpbvIbBnMAwnjYCzCdyLTf8zA== X-Google-Smtp-Source: ABdhPJzQj6cQL2cCdZBIXUW+tLh3opuUXYABgC2iIoMkawy/goaOnvdWOBqelUzW8i4pi93/tZdyzg== X-Received: by 2002:a05:6000:184f:b0:203:7fca:727e with SMTP id c15-20020a056000184f00b002037fca727emr353449wri.186.1647443621700; Wed, 16 Mar 2022 08:13:41 -0700 (PDT) Received: from hades.. ([2a02:587:4679:5116:3efd:feff:fe6b:c5cb]) by smtp.gmail.com with ESMTPSA id n1-20020a5d5981000000b00203d8ea8c94sm2123275wri.84.2022.03.16.08.13.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:13:41 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: Stuart.Yoder@arm.com, paul.liu@linaro.org, Ilias Apalodimas , u-boot@lists.denx.de Subject: [PATCH v2] efi_loader: Set variable attributes when EFI_BUFFER_TOO_SMALL is returned Date: Wed, 16 Mar 2022 17:13:37 +0200 Message-Id: <20220316151337.1497396-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.5 at phobos.denx.de X-Virus-Status: Clean Starting UEFI Spec 2.8 we must fill in the variable attributes when GetVariable() returns EFI_BUFFER_TOO_SMALL and Attributes is non-NULL. This code was written with 2.7 in mind so let's move the code around a bit and fill in the attributes EFI_BUFFER_TOO_SMALL is returned Signed-off-by: Ilias Apalodimas --- Changes since v1: - tmp variables switched to efi_status_t instead of int - switched (ret == EFI_SUCCESS || ret == EFI_BUFFER_TOO_SMALL) to (ret != EFI_SUCCESS && ret != EFI_BUFFER_TOO_SMALL) to make the code easier to read - Only call get_property_int() if attributes != NULL lib/efi_loader/efi_variable_tee.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/efi_loader/efi_variable_tee.c b/lib/efi_loader/efi_variable_tee.c index 58931c4efd74..dfef18435dfa 100644 --- a/lib/efi_loader/efi_variable_tee.c +++ b/lib/efi_loader/efi_variable_tee.c @@ -368,7 +368,7 @@ efi_status_t efi_get_variable_int(const u16 *variable_name, efi_uintn_t name_size; efi_uintn_t tmp_dsize; u8 *comm_buf = NULL; - efi_status_t ret; + efi_status_t ret, tmp; if (!variable_name || !vendor || !data_size) { ret = EFI_INVALID_PARAMETER; @@ -407,23 +407,32 @@ efi_status_t efi_get_variable_int(const u16 *variable_name, /* Communicate */ ret = mm_communicate(comm_buf, payload_size); - if (ret == EFI_SUCCESS || ret == EFI_BUFFER_TOO_SMALL) { - /* Update with reported data size for trimmed case */ - *data_size = var_acc->data_size; - } - if (ret != EFI_SUCCESS) - goto out; - - ret = get_property_int(variable_name, name_size, vendor, &var_property); - if (ret != EFI_SUCCESS) + if (ret != EFI_SUCCESS && ret != EFI_BUFFER_TOO_SMALL) goto out; + /* Update with reported data size for trimmed case */ + *data_size = var_acc->data_size; + /* + * UEFI > 2.7 needs the attributes set even if the buffer is + * smaller + */ if (attributes) { + tmp = get_property_int(variable_name, name_size, vendor, + &var_property); + if (tmp != EFI_SUCCESS) { + ret = tmp; + goto out; + } *attributes = var_acc->attr; - if (var_property.property & VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY) + if (var_property.property & + VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY) *attributes |= EFI_VARIABLE_READ_ONLY; } + /* return if ret is EFI_BUFFER_TOO_SMALL */ + if (ret != EFI_SUCCESS) + goto out; + if (data) memcpy(data, (u8 *)var_acc->name + var_acc->name_size, var_acc->data_size); -- 2.32.0