From patchwork Thu Dec 29 08:13:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 637558 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2820642pvb; Thu, 29 Dec 2022 00:13:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXvrfmqKyTLQAossXECUYlhJlX4rc5/RsK89MxP7B8qG2VSS6WDDHx5nJcHj6YxIh0+Gy7Rq X-Received: by 2002:aca:2109:0:b0:360:de9c:98d2 with SMTP id 9-20020aca2109000000b00360de9c98d2mr14143675oiz.31.1672301617976; Thu, 29 Dec 2022 00:13:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672301617; cv=none; d=google.com; s=arc-20160816; b=yUEThtShZCStx0V+7JaLcYOlBPLkYCDaeEFbs8jdoFlE755P3sXijnkpcPIFakZe6A E5izZ1IxJTJwBTu0o6axqPqTPbh7XbDN+7FBcHsWzSbblB1PEbnJfrTP4YjsuE+WRogA ybriZ4FIc7p0tfBGcKfjIHA7n0fLoqgBv0k5STHgQtcxrdKo9TMNOhwHj4FvyVkfRwy+ pZ6qxRczaTvLMWeBmeHadh5NNtlXMYtoOnSI6aDT2dSBqbb/7Zd2uQ8he0AAdEKcevA1 IQQoLw5o2JfC5eGVszAYhTmSACsWUy2Cbg7HdmmQrwlxv6fqf9a/yks86PZHNtRCHbyn U/8g== 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=Cuq3oQZQHbiVyGEQRmzZhAme0QXBgowfB9xW6Gz9QXw=; b=R86KY4JTtJg7y426gvCZjHL5glcmkvZ8iseQnA9gndL2EgyaMjIQ9oyKvz3Onzf/t0 6PiMwlVN5cTIb7Ob/dFMrxSfKtoDYoC9EsflBNRy/hd/YVa7tD3PxZAf+MDJHLahNK0A uodkPmMFG1NKaMTWz+0sIvNP5MZhywNer1CcNWLiMayaq3pSZjJ5Ku1KgUWlI+NEba4O 6F4l5Hh1KKks35Pke0qG/r/tl6/48Z7ciCv0ep1LP9/fd0hYxaAeDm83bVE9yqOvZUmy J/2DdrpxxvYKIn1UxgKuICIkHEGrlAcFLOSkc3O8YZ7r98m/jclTULogn3wVUIfyZCiH Dj2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MJrxewLL; 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 v26-20020a056808005a00b00360d47aba44si12673451oic.69.2022.12.29.00.13.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 00:13:37 -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=MJrxewLL; 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 0378385452; Thu, 29 Dec 2022 09:13: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="MJrxewLL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A636A854EB; Thu, 29 Dec 2022 09:13:33 +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-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) (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 7D9D385445 for ; Thu, 29 Dec 2022 09:13:31 +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-ej1-x630.google.com with SMTP id ud5so43438651ejc.4 for ; Thu, 29 Dec 2022 00:13:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Cuq3oQZQHbiVyGEQRmzZhAme0QXBgowfB9xW6Gz9QXw=; b=MJrxewLLwzBXjKF0RpBMHZJQlXU4Q1DOwe2IZim2cDj7WiG3TWswtXtoPaGOiKVxUr qhGQsj1j+IMtXy1Mbm+EJrzz46qQOK0W34yPJHVmq9YnLx91YkZ6BW4ZpUriN2jqKH0j 6f/fFrM/zSix/kKZ++liUQ9N1ttP+v2+vfgu7POCk+soKMzbjF9EjYQ7jj74j8XoZpTN 2eJ2oEgJIzQ5pZNVUdmzXyECagSKph0R1jg206POiXTWgRqyxBqHifRGxQFjU40Zh5Ng 53buPA2deGP2yeE/GYuhJbGEs/kcvv4WM185iAAFfudko0t+KlTGVZZPdd9UXG2gUNfl cYRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Cuq3oQZQHbiVyGEQRmzZhAme0QXBgowfB9xW6Gz9QXw=; b=sN1Q4NZpvid9bpmk6jJDBEP0WE7pc6JPAy94XjiMv1ulW5qMDUe/f7vayL6JjhEM7l WWTtpEs9pTSDf2vfmb8RIjrvS/2m1yZi5gpIkjXkRVpE4bfZ/C1Xu4osFiYtVGojaIjM TdBkq4nfaIDe1eurGRKyWaXghcz22KvXwbXILiqN/VMtzzE3+blEgvl/tW3PDK4Rdkvu otF+V59ZUVVI7Rt3iV51u66Mg1k4D2iticzm9/RTugKmgV0c7BNsZPGpMTGkaVHZ4Xvm rbWM/Onkzlh2KHJLI/FKTzmDxRKNOSK0M/A73/q9IdXSTPH1kXeKs9+2AJ+y+853z2Cd K82A== X-Gm-Message-State: AFqh2kqIkUAGfvdGW0yWEtK+mcNz90n7BXafGbmx3j/8Tg0AC34hF45I paf3J9m02zV1IE4aTlYAOZg2Tda6Iu1CLMxt X-Received: by 2002:a17:906:55cb:b0:844:44e0:1c5b with SMTP id z11-20020a17090655cb00b0084444e01c5bmr19612621ejp.12.1672301611060; Thu, 29 Dec 2022 00:13:31 -0800 (PST) Received: from localhost.localdomain ([2a02:85f:fc9d:e4b5:2fbc:1d5a:aaa9:9068]) by smtp.gmail.com with ESMTPSA id t20-20020a170906949400b007c10bb5b4b8sm8267983ejx.224.2022.12.29.00.13.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 00:13:30 -0800 (PST) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: heinrich.schuchardt@canonical.com, Ilias Apalodimas , Leo Yan , Heinrich Schuchardt Subject: [PATCH v2] efi_loader: avoid adding variables twice Date: Thu, 29 Dec 2022 10:13:22 +0200 Message-Id: <20221229081322.448138-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.38.1 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.6 at phobos.denx.de X-Virus-Status: Clean When the efi subsystem starts we restore variables that are both in a file or stored into the .efi_runtime section of U-Boot. However once a variable gets created or changed the preseeded entries will end up in the file. As a consequence on the next boot we will end up adding identical variable entries twice. Fix this by checking if the to be inserted variable already exists. Also swap the restoration order and start with the file instead of the builtin variables, so a user can replace the preseeded ones if needed. Tested-by: Leo Yan Signed-off-by: Ilias Apalodimas --- changes since v1: - Move the check in efi_var_restore(), since it would break updating variables in efi_var_mem_ins() lib/efi_loader/efi_var_file.c | 2 ++ lib/efi_loader/efi_variable.c | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) -- 2.38.1 diff --git a/lib/efi_loader/efi_var_file.c b/lib/efi_loader/efi_var_file.c index 3d58caa13da2..d70a72d12684 100644 --- a/lib/efi_loader/efi_var_file.c +++ b/lib/efi_loader/efi_var_file.c @@ -187,6 +187,8 @@ efi_status_t efi_var_restore(struct efi_var_file *buf, bool safe) continue; if (!var->length) continue; + if (efi_var_mem_find(&var->guid, var->name, NULL)) + continue; ret = efi_var_mem_ins(var->name, &var->guid, var->attr, var->length, data, 0, NULL, var->time); diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 8ca2d85694c8..503a33ed65c5 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -425,6 +425,9 @@ efi_status_t efi_init_variables(void) if (ret != EFI_SUCCESS) return ret; + ret = efi_var_from_file(); + if (ret != EFI_SUCCESS) + return ret; if (IS_ENABLED(CONFIG_EFI_VARIABLES_PRESEED)) { ret = efi_var_restore((struct efi_var_file *) __efi_var_file_begin, true); @@ -432,9 +435,6 @@ efi_status_t efi_init_variables(void) log_err("Invalid EFI variable seed\n"); } - ret = efi_var_from_file(); - if (ret != EFI_SUCCESS) - return ret; return efi_init_secure_state(); }