summaryrefslogtreecommitdiff
path: root/mok.c
diff options
context:
space:
mode:
authorPeter Jones <pjones@redhat.com>2021-04-10 16:05:23 -0400
committerPeter Jones <pjones@redhat.com>2021-05-24 16:05:18 -0400
commit493bd940e5c6e28e673034687de7adef9529efff (patch)
tree7b65c7673e846934dd9148d3e7208fb748175edc /mok.c
parent4068fd42c891ea6ebdec056f461babc6e4048844 (diff)
downloadefi-boot-shim-493bd940e5c6e28e673034687de7adef9529efff.tar.gz
efi-boot-shim-493bd940e5c6e28e673034687de7adef9529efff.zip
Don't call QueryVariableInfo() on EFI 1.10 machines
The EFI 1.10 spec (and presumably earlier revisions as well) didn't have RT->QueryVariableInfo(), and on Chris Murphy's MacBookPro8,2 , that memory appears to be initialized randomly. This patch changes it to not call RT->QueryVariableInfo() if the EFI_RUNTIME_SERVICES table's major revision is less than two, and assumes our maximum variable size is 1024 in that case. Signed-off-by: Peter Jones <pjones@redhat.com>
Diffstat (limited to 'mok.c')
-rw-r--r--mok.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/mok.c b/mok.c
index 9b8fc2bc..beac0ff6 100644
--- a/mok.c
+++ b/mok.c
@@ -261,6 +261,9 @@ static const uint8_t null_sha256[32] = { 0, };
typedef UINTN SIZE_T;
+#define EFI_MAJOR_VERSION(tablep) ((UINT16)((((tablep)->Hdr.Revision) >> 16) & 0xfffful))
+#define EFI_MINOR_VERSION(tablep) ((UINT16)(((tablep)->Hdr.Revision) & 0xfffful))
+
static EFI_STATUS
get_max_var_sz(UINT32 attrs, SIZE_T *max_var_szp)
{
@@ -270,11 +273,21 @@ get_max_var_sz(UINT32 attrs, SIZE_T *max_var_szp)
uint64_t max_var_sz = 0;
*max_var_szp = 0;
- efi_status = gRT->QueryVariableInfo(attrs, &max_storage_sz,
- &remaining_sz, &max_var_sz);
- if (EFI_ERROR(efi_status)) {
- perror(L"Could not get variable storage info: %r\n", efi_status);
- return efi_status;
+ if (EFI_MAJOR_VERSION(gRT) < 2) {
+ dprint(L"EFI %d.%d; no RT->QueryVariableInfo(). Using 1024!\n",
+ EFI_MAJOR_VERSION(gRT), EFI_MINOR_VERSION(gRT));
+ max_var_sz = remaining_sz = max_storage_sz = 1024;
+ efi_status = EFI_SUCCESS;
+ } else {
+ dprint(L"calling RT->QueryVariableInfo() at 0x%lx\n",
+ gRT->QueryVariableInfo);
+ efi_status = gRT->QueryVariableInfo(attrs, &max_storage_sz,
+ &remaining_sz, &max_var_sz);
+ if (EFI_ERROR(efi_status)) {
+ perror(L"Could not get variable storage info: %r\n",
+ efi_status);
+ return efi_status;
+ }
}
/*