Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
From 6883130d13a2fbeda06289affa97b49283a3cfd7 Mon Sep 17 00:00:00 2001
From: Julian Andres Klode <julian.klode@canonical.com>
Date: Wed, 4 Aug 2021 10:43:30 +0200
Subject: [PATCH] Extract is_removable_media_path() out of
should_use_fallback()
Simple refactoring that extracts the path checking on the given
loaded image. This will be useful to check if we were booted via
removable media path in other places.
---
shim.c | 46 ++++++++++++++++++++++++++++++----------------
1 file changed, 30 insertions(+), 16 deletions(-)
diff --git a/shim.c b/shim.c
index 94a51768..febd2706 100644
--- a/shim.c
+++ b/shim.c
@@ -710,25 +710,12 @@ verify_buffer (char *data, int datasize,
}
static int
-should_use_fallback(EFI_HANDLE image_handle)
+is_removable_media_path(EFI_LOADED_IMAGE *li)
{
- EFI_LOADED_IMAGE *li;
unsigned int pathlen = 0;
CHAR16 *bootpath = NULL;
- EFI_FILE_IO_INTERFACE *fio = NULL;
- EFI_FILE *vh = NULL;
- EFI_FILE *fh = NULL;
- EFI_STATUS efi_status;
int ret = 0;
- efi_status = gBS->HandleProtocol(image_handle, &EFI_LOADED_IMAGE_GUID,
- (void **)&li);
- if (EFI_ERROR(efi_status)) {
- perror(L"Could not get image for bootx64.efi: %r\n",
- efi_status);
- return 0;
- }
-
bootpath = DevicePathToStr(li->FilePath);
/* Check the beginning of the string and the end, to avoid
@@ -746,6 +733,35 @@ should_use_fallback(EFI_HANDLE image_handle)
if (pathlen < 5 || StrCaseCmp(bootpath + pathlen - 4, L".EFI"))
goto error;
+ ret = 1;
+
+error:
+ if (bootpath)
+ FreePool(bootpath);
+
+ return ret;
+}
+static int
+should_use_fallback(EFI_HANDLE image_handle)
+{
+ EFI_LOADED_IMAGE *li;
+ EFI_FILE_IO_INTERFACE *fio = NULL;
+ EFI_FILE *vh = NULL;
+ EFI_FILE *fh = NULL;
+ EFI_STATUS efi_status;
+ int ret = 0;
+
+ efi_status = gBS->HandleProtocol(image_handle, &EFI_LOADED_IMAGE_GUID,
+ (void **)&li);
+ if (EFI_ERROR(efi_status)) {
+ perror(L"Could not get image for bootx64.efi: %r\n",
+ efi_status);
+ return 0;
+ }
+
+ if (!is_removable_media_path(li))
+ goto error;
+
efi_status = gBS->HandleProtocol(li->DeviceHandle, &FileSystemProtocol,
(void **) &fio);
if (EFI_ERROR(efi_status)) {
@@ -778,8 +794,6 @@ should_use_fallback(EFI_HANDLE image_handle)
fh->Close(fh);
if (vh)
vh->Close(vh);
- if (bootpath)
- FreePool(bootpath);
return ret;
}