From patchwork Wed Mar 16 15:13:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 551839 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp369573mag; Wed, 16 Mar 2022 08:13:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyA9o8+G3KhDgKj0CB2yn1zncl5cPKW46oLIsUDdmncsYhUB8ckvx/ZgMeh1uq1um+1tjZv X-Received: by 2002:a05:6402:1941:b0:413:2b80:b245 with SMTP id f1-20020a056402194100b004132b80b245mr30536637edz.252.1647443631917; Wed, 16 Mar 2022 08:13:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647443631; cv=none; d=google.com; s=arc-20160816; b=Lv7k1TOHhzElpxRIwCXv45I2Xe7cVcFxakEtZtPibCM0+ZDnWH2mKqk3J3yUm++9uN 5jFm33Xvg7REjPiWwpLe3WpZFPKN80F6MhJwmxals2DUQOfpiiXSwsdrV0IjLyYo3rY/ Zeb01Ov2CaOLuJ9OEJpDyxvslGkc7jmg3WKY4pJebiJi704TADfRC4GP0PbN8uHT7+o8 vBShp0rcuLvFCWYxpQQDgcp19iUroNTJqa4x51yEbmytm5Sj8ckMW/+YBg/geWlonnOg 1EXc+oCQzcEtsHEjkxa0WTdOfVc8Aub3xBMcZ1A0oDuee4A6qppJ4WDnbQe1twzixUGG hrYg== 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:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=5Tm0JU7ckCZogR0vt9JmgJDwWIFEp+SpTTnZoMb7T60=; b=0fiMYC3AHqX69vdbShxNjCqptqXM81nKYOGBPsyZlV62ImTNLuFo7b6Y6RMiLK628M pViNG63J/GdeS8MNNxz3Ymn2OPCZPe1dfm+Rtw/yNXDXX6hkheHgy+Mnep4W0/aePAHm baFO4rphYVoL1arfesgwzd3VRsmlvmsPRDUc9EsQBk2wMQ8QJIvG94qU0PQs5HvbOZkL CqCYNsx3X0fGmNl9JbWvrLmuL0fc+yUUmnJLEgZUA3lJ6nu7sckAkivRPEZuPQhAK5v9 2vumFI8stXb26K69lUjelGro/BGf2Hwj9x13oNtV+IBFjh62xGucdLgX74L6fQUHTd9m EjVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="M/zo7NEP"; 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 el6-20020a056402360600b0041614eca4e2si1317689edb.42.2022.03.16.08.13.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:13:51 -0700 (PDT) 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="M/zo7NEP"; 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 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) 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 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-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 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 Reviewed-by: Heinrich Schuchardt --- 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);