From patchwork Thu Dec 29 06:55:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 637557 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2799732pvb; Wed, 28 Dec 2022 22:56:05 -0800 (PST) X-Google-Smtp-Source: AMrXdXucYhwFzmMpM7YQgIP5oFGuSDw0719fPbl1J5rRgjkvjqVtQYk8rD1S97f5B4nHthB0Svqt X-Received: by 2002:aca:2216:0:b0:35b:f934:2f8d with SMTP id b22-20020aca2216000000b0035bf9342f8dmr17306797oic.16.1672296965810; Wed, 28 Dec 2022 22:56:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672296965; cv=none; d=google.com; s=arc-20160816; b=Cc2RPUL5sUf2HSwjsHosx80FZm1aTMOQ0eE1RLdwKWPOw60yrST4aP4h8KMvdQxpWm niqbgD3eF+VK3N8+wL+uDDqP6X+LYmFIJ5h+GSZwKq8IM/BnCEO5zWHJjtehjUT3LMzJ gcXPgBFOA7CeGN55VQZEQ9NFLqA+IRXzyD4b/gF+MRqvk5/9W/06JlKzMyeAZyT5/5DQ VYBeCOVIRjJP4VWrylzcYsfFtCXQqEFzxmvNrqgmG79KpI9C4scnh5RW5EKaaE0li+yO GTs7X0aKOR8B7fRDJYifNChyDPwujFK/l5iEI5hfSeF+Dv5xhpAie4J+Zg5cVUxR5cVh dfRw== 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=T0Z8L2B3/hSy2i82qaCoSkUxq+K0hkGaaPPZzbQ8ies=; b=z9F20pv3PYb1ITrHfWsDOYFMakJia6FKOd0TQsShf/jDlx+ews/tZvZScrlMc1tJO4 NfxywU8p9CkN47sZXnQF806bWglXgjZjyTw9g0DKRxzFrPFt/HW9tj1/uCtDrJsU3jjI uvkrx1Fv+wIE7xlOYVyRsNQnsDui//zRWK9FFLKfeW+5aw3ZZSc5sSGYJqkUFkdC3mfB C99demcLbk+IkBRRQylApFf9KyykJPGiKMoTUeCuoSkdcmzxqC1HNpqyBsmWoOyzttm/ pafJXwKJGvgRhTMkw20LYGRxAmdTR3AWTRR+1qRHGzQnPsObB/ad1L95qH4lgqnoxa04 1xzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LORlDgre; 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 x4-20020a9d4584000000b00670600bd5d7si12515325ote.259.2022.12.28.22.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 22:56:05 -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=LORlDgre; 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 D7B7285475; Thu, 29 Dec 2022 07:56:02 +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="LORlDgre"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 90E5E85477; Thu, 29 Dec 2022 07:56:01 +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-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) (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 3BFB385467 for ; Thu, 29 Dec 2022 07:55:59 +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-x631.google.com with SMTP id u19so43072023ejm.8 for ; Wed, 28 Dec 2022 22:55:59 -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=T0Z8L2B3/hSy2i82qaCoSkUxq+K0hkGaaPPZzbQ8ies=; b=LORlDgreepko1p3B4nB2yCAHl8wnf6KWIwCIcXeugdXoq5rPxoXfWd1DwQMriqF4r/ cZv48e2I2H2utEDJP9GnzK3mwMGsXz260Df36W5W5l8RpsW29NoMJ8tQEUyUtC9stusg 3VzkVlHmxnquD51yS1Bp44FlfMUW9pOJzBUl3AI1C1sy+R+zsTGpnszWE2T6O/tEwFA0 uq3zArO+sVbWUTvr0ozGaBBW6f5M1KEh2o97EP8eDnjMsontlbjSuuzcHcySdmbpBPLK 9cDHhGlbkhVm91Z68O98U0ntRA1RPrMps5SoQRHrK9Mb2e3eUlKOulERaNFtelkgalHD +Djg== 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=T0Z8L2B3/hSy2i82qaCoSkUxq+K0hkGaaPPZzbQ8ies=; b=VF2zJqP3O2rPD0lJ846dF/CA4sPkC9ERDcY5o+DwrX+HPVIH2oc1a5XJ1S2vyd9aiE UgULoRc4sObC/fT+sHJrHDQA1RI4jiy5Ia31JkGleZF9VjcIXxBLmdyEYYWp4nnuEiqK RSOm0veBE4EJOWeMA7FiJxsa8HCRi0Wz5c+AxakC+ly0d2XlmjTjIAjOLX8C5zgTRO60 s3kbdvwVMtpoeZ5WS5uzzd9Ew2qsL3rx6SKrvIxP/c68QnmXSaFSpvFfvH12ljAL2mxh vu0AK3XE+vbznKLZbn/ajOb3RrBURiGluEqguRCaV2xg8tQKS4Nmp5gWoMjeFqJJzygn B8JA== X-Gm-Message-State: AFqh2konbg2iXXyqghUPGDtE2L8iiA20Tk8aSu4ofIM6EHk0Y5unoSA8 LmJUykkW1T9ZpBm2BhbSqs5mhVVKQBHDeJ9T X-Received: by 2002:a17:906:5786:b0:78d:f455:3105 with SMTP id k6-20020a170906578600b0078df4553105mr22422834ejq.45.1672296958861; Wed, 28 Dec 2022 22:55:58 -0800 (PST) Received: from localhost.localdomain ([2a02:85f:fc9d:e4b5:2471:3c5a:6106:b21b]) by smtp.gmail.com with ESMTPSA id w13-20020a1709060a0d00b007b9269a0423sm8338965ejf.172.2022.12.28.22.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 22:55:58 -0800 (PST) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: heinrich.schuchardt@canonical.com, Ilias Apalodimas , Leo Yan , Heinrich Schuchardt Subject: [PATCH] efi_loader: avoid adding variables twice Date: Thu, 29 Dec 2022 08:55:28 +0200 Message-Id: <20221229065528.421350-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 --- lib/efi_loader/efi_var_mem.c | 3 +++ lib/efi_loader/efi_variable.c | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/efi_loader/efi_var_mem.c b/lib/efi_loader/efi_var_mem.c index 0bac594e004d..17a2ad2e4951 100644 --- a/lib/efi_loader/efi_var_mem.c +++ b/lib/efi_loader/efi_var_mem.c @@ -144,6 +144,9 @@ efi_status_t __efi_runtime efi_var_mem_ins( struct efi_var_entry *var; u32 var_name_len; + if (efi_var_mem_find(vendor, variable_name, NULL)) + return EFI_SUCCESS; + var = (struct efi_var_entry *) ((uintptr_t)efi_var_buf + efi_var_buf->length); for (var_name_len = 0; variable_name[var_name_len]; ++var_name_len) 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(); }