Skip to content

Commit

Permalink
Fix UEFI Variable Reading on Linux (#655)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
os-d authored Oct 18, 2024
1 parent db0565d commit 1d941cf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion edk2toollib/os/uefivariablesupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1d941cf

Please sign in to comment.