mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/2] efi: loader: don't let VarToFile stop the variable file from being written
Date: Wed, 26 Aug 2026 11:47:57 +0200	[thread overview]
Message-ID: <20260826094800.2564299-1-a.fatoum@pengutronix.de> (raw)

efi_var_collect() walks the variable store with GetNextVariableName() and
reads every variable it finds into a buffer the size of the store, then
keeps only those matching the attribute mask. Reading a variable whose
value does not fit aborts the collection, and with it the write of the
variable file:

  efi-loader: var-file: Failed to persist EFI variables Out of memory

VarToFile is such a variable. Its value is not stored anywhere: reading
it serializes all non-volatile variables, so it needed as much room as
everything collected before it.

Assisted-by: Claude:opus-5
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/loader/efi_var_common.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/efi/loader/efi_var_common.c b/efi/loader/efi_var_common.c
index 4c6cb77e7c2c..dcdfa6fb0165 100644
--- a/efi/loader/efi_var_common.c
+++ b/efi/loader/efi_var_common.c
@@ -454,6 +454,14 @@ efi_status_t __maybe_unused efi_var_collect(struct efi_var_file **bufp, loff_t *
 		ret = efi_get_variable_int(var->name, &var->guid,
 					   &var->attr, &data_length, data,
 					   &var->time);
+		/*
+		 * The attributes are valid even when the value did not fit.
+		 * Variables we are not going to keep may thus be skipped
+		 * without their value ever being copied, e.g. VarToFile.
+		 */
+		if (ret == EFI_BUFFER_TOO_SMALL &&
+		    (var->attr & check_attr_mask) != check_attr_mask)
+			continue;
 		if (ret != EFI_SUCCESS) {
 			free(buf);
 			return ret;
-- 
2.47.3




             reply	other threads:[~2026-08-26  9:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-26  9:47 Ahmad Fatoum [this message]
2026-08-26  9:47 ` [PATCH 2/2] efi: loader: keep booting when the runtime variable store is unavailable Ahmad Fatoum
2026-08-28 13:07 ` [PATCH 1/2] efi: loader: don't let VarToFile stop the variable file from being written Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260826094800.2564299-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox