summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwrvsrx <wrvsrx@outlook.com>2024-12-07 03:32:15 +0100
committerLennart Poettering <lennart@poettering.net>2025-01-15 16:53:21 +0100
commit6013dee98d6543ac290a2938c4ec8494e26531ab (patch)
tree0e2a6ee5f92a2eb2aa940240c6a812be284a50c5
parentmachine: introduce io.systemd.MachineImage.SetPoolLimit (#35953) (diff)
downloadsystemd-6013dee98d6543ac290a2938c4ec8494e26531ab.tar.xz
systemd-6013dee98d6543ac290a2938c4ec8494e26531ab.zip
efivars: deal with uncommitted efi variables
Unfortunately kernel reports EOF if there's an inconsistency between efivarfs var list and what's actually stored in firmware, c.f. #34304. A zero size env var is not allowed in efi and hence the variable doesn't really exist in the backing store as long as it is zero sized, and the kernel calls this "uncommitted". Hence we translate EOF back to ENOENT here, as with kernel behavior before https://github.com/torvalds/linux/commit/3fab70c165795431f00ddf9be8b84ddd07bd1f8f If the kernel changes behaviour (to flush dentries on resume), we can drop this at some point in the future. But note that the commit is 11 years old at this point so we'll need to deal with the current behaviour for a long time. Fix #34304.
-rw-r--r--src/basic/efivars.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/basic/efivars.c b/src/basic/efivars.c
index 5e04c32212..1811f9e37e 100644
--- a/src/basic/efivars.c
+++ b/src/basic/efivars.c
@@ -96,6 +96,22 @@ int efi_get_variable(
(void) usleep_safe(EFI_RETRY_DELAY);
}
+ /* Unfortunately kernel reports EOF if there's an inconsistency between efivarfs var list
+ * and what's actually stored in firmware, c.f. #34304. A zero size env var is not allowed in
+ * efi and hence the variable doesn't really exist in the backing store as long as it is zero
+ * sized, and the kernel calls this "uncommitted". Hence we translate EOF back to ENOENT here,
+ * as with kernel behavior before
+ * https://github.com/torvalds/linux/commit/3fab70c165795431f00ddf9be8b84ddd07bd1f8f
+ *
+ * If the kernel changes behaviour (to flush dentries on resume), we can drop
+ * this at some point in the future. But note that the commit is 11
+ * years old at this point so we'll need to deal with the current behaviour for
+ * a long time.
+ */
+ if (n == 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(ENOENT),
+ "EFI variable %s is uncommitted", p);
+
if (n != sizeof(a))
return log_debug_errno(SYNTHETIC_ERRNO(EIO),
"Read %zi bytes from EFI variable %s, expected %zu.", n, p, sizeof(a));