aboutsummaryrefslogtreecommitdiff
path: root/src/usr
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/usr
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/usr')
-rw-r--r--src/usr/shimmgmt.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/usr/shimmgmt.c b/src/usr/shimmgmt.c
new file mode 100644
index 0000000..ba9c348
--- /dev/null
+++ b/src/usr/shimmgmt.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2023 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <ipxe/efi/efi.h>
+#include <ipxe/efi/efi_shim.h>
+#include <usr/shimmgmt.h>
+
+/** @file
+ *
+ * EFI shim management
+ *
+ */
+
+/**
+ * Set shim image
+ *
+ * @v image Shim image, or NULL to clear shim
+ * @v require_loader Require use of a third party loader
+ * @v allow_pxe Allow use of PXE base code
+ * @ret rc Return status code
+ */
+int shim ( struct image *image, int require_loader, int allow_pxe ) {
+
+ /* Record (or clear) shim image */
+ image_tag ( image, &efi_shim );
+
+ /* Avoid including image in constructed initrd */
+ if ( image )
+ image_hide ( image );
+
+ /* Record configuration */
+ efi_shim_require_loader = require_loader;
+ efi_shim_allow_pxe = allow_pxe;
+
+ return 0;
+}