From 75208de41a50b786e71c7124006a7fc7d51eb9b8 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Wed, 16 Oct 2024 11:00:46 -0700 Subject: [PATCH] Fix UEFI Variable Reading on Linux The UEFI variable fetching on Linux was broken, it was reading the attributes as part of the data, not correctly skipping over the attributes and fetching the data. For Linux, the value read is a UINT32 Attributes + Variable Length Data. This change has been tested to fix that but reading (and ignoring but logging an error if the attributes aren't 7, as ConfigEditor expects) the attributes and then fetching the data past that. --- edk2toollib/os/uefivariablesupport.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/edk2toollib/os/uefivariablesupport.py b/edk2toollib/os/uefivariablesupport.py index 3f087dbd..eb4e194f 100644 --- a/edk2toollib/os/uefivariablesupport.py +++ b/edk2toollib/os/uefivariablesupport.py @@ -137,7 +137,15 @@ def GetUefiVar(self, name: str, guid: str) -> tuple[int, str]: efi_var = fd.read() length = len(efi_var) - return (err, efi_var[:length]) + # Unpack a uint32 from the start of efi_var, which is the attributes + # we always expect the attributes to be 7, since we are reading from runtime, + # report an error so the user knows it may fail to load if not 7 + (attrs,) = struct.unpack("=I", efi_var[:4]) + if attrs != 7: + logging.error(f"Unexpected attributes value: {attrs} for {name}-{guid}") + efi_var = efi_var[4:length] + + return (err, efi_var) def GetUefiAllVarNames(self) -> tuple[int, bytes]: """Get all Uefi Variables in the system, and return a byte packed byte string.