aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2023-05-22 14:11:22 +0100
committerMichael Brown <mcb30@ipxe.org>2023-05-22 15:37:11 +0100
commit28184b7c22ca2297bd5c0ad9d333bc8620d38915 (patch)
tree916e215eb19846c47dedcbdca4f0057c28f8690d /src/include
parent3c214f046507fb7b4e67845d61f38a13fa1bc2b5 (diff)
downloadipxe-28184b7c22ca2297bd5c0ad9d333bc8620d38915.zip
ipxe-28184b7c22ca2297bd5c0ad9d333bc8620d38915.tar.gz
ipxe-28184b7c22ca2297bd5c0ad9d333bc8620d38915.tar.bz2
[efi] Add support for executing images via a shim
Add support for using a shim as a helper to execute an EFI image. When a shim has been specified via shim(), the shim image will be passed to LoadImage() instead of the selected EFI image and the command line will be prepended with the name of the selected EFI image. The selected EFI image will be accessible to the shim via the virtual filesystem as a hidden file. Reduce the Secure Boot attack surface by removing, where possible, the spurious requirement for a third party second stage loader binary such as GRUB to be used solely in order to call the "shim lock protocol" entry point. Do not install the EFI PXE APIs when using a shim, since if shim finds EFI_PXE_BASE_CODE_PROTOCOL on the loaded image's device handle then it will attempt to download files afresh instead of using the files already downloaded by iPXE and exposed via the EFI_SIMPLE_FILE_SYSTEM protocol. (Experience shows that there is no point in trying to get a fix for this upstreamed into shim.) Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include')
-rw-r--r--src/include/ipxe/efi/efi_image.h27
-rw-r--r--src/include/ipxe/efi/efi_shim.h23
-rw-r--r--src/include/ipxe/errfile.h1
-rw-r--r--src/include/ipxe/image.h9
-rw-r--r--src/include/usr/shimmgmt.h16
5 files changed, 76 insertions, 0 deletions
diff --git a/src/include/ipxe/efi/efi_image.h b/src/include/ipxe/efi/efi_image.h
new file mode 100644
index 0000000..0fc0402
--- /dev/null
+++ b/src/include/ipxe/efi/efi_image.h
@@ -0,0 +1,27 @@
+#ifndef _IPXE_EFI_IMAGE_H
+#define _IPXE_EFI_IMAGE_H
+
+/** @file
+ *
+ * EFI images
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <ipxe/image.h>
+
+extern struct image_type efi_image_type[] __image_type ( PROBE_NORMAL );
+
+/**
+ * Check if EFI image can be loaded directly
+ *
+ * @v image EFI image
+ * @ret can_load EFI image can be loaded directly
+ */
+static inline int efi_can_load ( struct image *image ) {
+
+ return ( image->type == efi_image_type );
+}
+
+#endif /* _IPXE_EFI_IMAGE_H */
diff --git a/src/include/ipxe/efi/efi_shim.h b/src/include/ipxe/efi/efi_shim.h
new file mode 100644
index 0000000..ad8d24d
--- /dev/null
+++ b/src/include/ipxe/efi/efi_shim.h
@@ -0,0 +1,23 @@
+#ifndef _IPXE_EFI_SHIM_H
+#define _IPXE_EFI_SHIM_H
+
+/** @file
+ *
+ * UEFI shim special handling
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <ipxe/image.h>
+#include <ipxe/efi/efi.h>
+
+extern int efi_shim_require_loader;
+extern int efi_shim_allow_pxe;
+extern struct image_tag efi_shim __image_tag;
+
+extern int efi_shim_install ( struct image *shim, EFI_HANDLE handle,
+ wchar_t **cmdline );
+extern void efi_shim_uninstall ( void );
+
+#endif /* _IPXE_EFI_SHIM_H */
diff --git a/src/include/ipxe/errfile.h b/src/include/ipxe/errfile.h
index 235611a..daa038c 100644
--- a/src/include/ipxe/errfile.h
+++ b/src/include/ipxe/errfile.h
@@ -405,6 +405,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#define ERRFILE_dhe ( ERRFILE_OTHER | 0x005a0000 )
#define ERRFILE_efi_cmdline ( ERRFILE_OTHER | 0x005b0000 )
#define ERRFILE_efi_rng ( ERRFILE_OTHER | 0x005c0000 )
+#define ERRFILE_efi_shim ( ERRFILE_OTHER | 0x005d0000 )
/** @} */
diff --git a/src/include/ipxe/image.h b/src/include/ipxe/image.h
index cd51188..bfbf236 100644
--- a/src/include/ipxe/image.h
+++ b/src/include/ipxe/image.h
@@ -257,6 +257,15 @@ static inline void image_untrust ( struct image *image ) {
}
/**
+ * Mark image as hidden
+ *
+ * @v image Image
+ */
+static inline void image_hide ( struct image *image ) {
+ image->flags |= IMAGE_HIDDEN;
+}
+
+/**
* Tag image
*
* @v image Image
diff --git a/src/include/usr/shimmgmt.h b/src/include/usr/shimmgmt.h
new file mode 100644
index 0000000..5030607
--- /dev/null
+++ b/src/include/usr/shimmgmt.h
@@ -0,0 +1,16 @@
+#ifndef _USR_SHIMMGMT_H
+#define _USR_SHIMMGMT_H
+
+/** @file
+ *
+ * EFI shim management
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <ipxe/image.h>
+
+extern int shim ( struct image *image, int require_loader, int allow_pxe );
+
+#endif /* _USR_SHIMMGMT_H */