summaryrefslogtreecommitdiff
path: root/shim.c
diff options
context:
space:
mode:
authorJan Setje-Eilers <jan.setjeeilers@oracle.com>2023-12-06 15:43:32 -0800
committerPeter Jones <pjones@redhat.com>2024-01-22 14:17:20 -0500
commitc46c975591b99a4c7374b3f14bcd500f316d0b73 (patch)
tree436a15dc4a8ff02ab5c34d9d0598ae0dd7b84cb6 /shim.c
parent13abd9f51b285db7eb46bf375cae623bf1153404 (diff)
downloadefi-boot-shim-c46c975591b99a4c7374b3f14bcd500f316d0b73.tar.gz
efi-boot-shim-c46c975591b99a4c7374b3f14bcd500f316d0b73.zip
Suppress "Failed to open <..>\revocations.efi" when file does not exist
Attempting to call loadimage on revocations.efi when it isn't present should results in error messages being printed to the console on at least some firmware: Failed to open \EFI\distro\revocations.efi - Not Found Failed to load image ...: Not Found Of course this is going to be the normal case on nearly all systems, at least to begin with. Since we are about to loop through the directory entries anyway, we can just make two passes, first looking for revocations.efi and then looking for shim_certificate.efi. This will still ensure that any revocations in revocations.efi are picked up before shim_certificate.efi is loaded without resulting in any noise on the console. Signed-off-by: Jan Setje-Eilers <Jan.SetjeEilers@oracle.com>
Diffstat (limited to 'shim.c')
-rw-r--r--shim.c50
1 files changed, 40 insertions, 10 deletions
diff --git a/shim.c b/shim.c
index a0379721..d800f675 100644
--- a/shim.c
+++ b/shim.c
@@ -1549,6 +1549,7 @@ load_unbundled_trust(EFI_HANDLE image_handle)
EFI_FILE_IO_INTERFACE *drive;
UINTN buffersize = 0;
void *buffer = NULL;
+ BOOLEAN search_revocations = TRUE;
efi_status = gBS->HandleProtocol(image_handle, &EFI_LOADED_IMAGE_GUID,
(void **)&li);
@@ -1584,13 +1585,6 @@ load_unbundled_trust(EFI_HANDLE image_handle)
if (!secure_mode())
goto done;
- /*
- * In the event that there are unprocessed revocation additions, they
- * could be intended to ban any *new* trust anchors we find here.
- * With that in mind, we always want to do a pass of loading
- * revocations before we try to add anything new to our allowlist.
- */
- load_revocations_file(image_handle, PathName);
while (true) {
UINTN old = buffersize;
@@ -1625,10 +1619,46 @@ load_unbundled_trust(EFI_HANDLE image_handle)
}
info = (EFI_FILE_INFO *)buffer;
- if (buffersize == 0 || !info)
- goto done;
+ if (buffersize == 0 || !info) {
+ if (search_revocations) {
+ search_revocations = FALSE;
+ efi_status = root->Open(root, &dir, PathName,
+ EFI_FILE_MODE_READ, 0);
+ if (EFI_ERROR(efi_status)) {
+ perror(L"Failed to open %s - %r\n",
+ PathName, efi_status);
+ goto done;
+ }
+ continue;
+ } else {
+ goto done;
+ }
+ }
+
+ /*
+ * In the event that there are unprocessed revocation
+ * additions, they could be intended to ban any *new* trust
+ * anchors we find here. With that in mind, we always want to
+ * do a pass of loading revocations before we try to add
+ * anything new to our allowlist. This is done by making two
+ * passes over the directory, first to search for the
+ * revocations.efi file then to search for shim_certificate.efi
+ */
+ if (search_revocations &&
+ StrCaseCmp(info->FileName, L"revocations.efi") == 0) {
+ load_revocations_file(image_handle, PathName);
+ search_revocations = FALSE;
+ efi_status = root->Open(root, &dir, PathName,
+ EFI_FILE_MODE_READ, 0);
+ if (EFI_ERROR(efi_status)) {
+ perror(L"Failed to open %s - %r\n",
+ PathName, efi_status);
+ goto done;
+ }
+ }
- if (StrCaseCmp(info->FileName, L"shim_certificate.efi") == 0) {
+ if (!search_revocations &&
+ StrCaseCmp(info->FileName, L"shim_certificate.efi") == 0) {
load_cert_file(image_handle, info->FileName, PathName);
}
}