!359 update to 2.12
From: @zhangqiumiao Reviewed-by: @t_feng Signed-off-by: @t_feng
This commit is contained in:
commit
24f7187f72
68
0001-Add-grub_envblk_buf-helper-function.patch
Normal file
68
0001-Add-grub_envblk_buf-helper-function.patch
Normal file
@ -0,0 +1,68 @@
|
||||
From a326e486bdcf99e6be973ba54c0abfb6d2d95b73 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Mon, 17 Jan 2022 17:45:00 +0800
|
||||
Subject: [PATCH 1/5] Add grub_envblk_buf helper function
|
||||
|
||||
This helps in creation and initialization of memory buffer for
|
||||
environment block of given size.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/lib/envblk.c | 12 ++++++++++++
|
||||
include/grub/lib/envblk.h | 1 +
|
||||
util/grub-editenv.c | 4 +---
|
||||
3 files changed, 14 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/grub-core/lib/envblk.c b/grub-core/lib/envblk.c
|
||||
index 2e4e78b132..24efbe7ffa 100644
|
||||
--- a/grub-core/lib/envblk.c
|
||||
+++ b/grub-core/lib/envblk.c
|
||||
@@ -23,6 +23,18 @@
|
||||
#include <grub/mm.h>
|
||||
#include <grub/lib/envblk.h>
|
||||
|
||||
+char *
|
||||
+grub_envblk_buf (grub_size_t size)
|
||||
+{
|
||||
+ char *buf;
|
||||
+
|
||||
+ buf = grub_malloc (size);
|
||||
+ grub_memcpy (buf, GRUB_ENVBLK_SIGNATURE, sizeof (GRUB_ENVBLK_SIGNATURE) - 1);
|
||||
+ grub_memset (buf + sizeof (GRUB_ENVBLK_SIGNATURE) - 1, '#', size - sizeof (GRUB_ENVBLK_SIGNATURE) + 1);
|
||||
+
|
||||
+ return buf;
|
||||
+}
|
||||
+
|
||||
grub_envblk_t
|
||||
grub_envblk_open (char *buf, grub_size_t size)
|
||||
{
|
||||
diff --git a/include/grub/lib/envblk.h b/include/grub/lib/envblk.h
|
||||
index c3e6559217..83f3fcf841 100644
|
||||
--- a/include/grub/lib/envblk.h
|
||||
+++ b/include/grub/lib/envblk.h
|
||||
@@ -31,6 +31,7 @@ struct grub_envblk
|
||||
};
|
||||
typedef struct grub_envblk *grub_envblk_t;
|
||||
|
||||
+char *grub_envblk_buf (grub_size_t size);
|
||||
grub_envblk_t grub_envblk_open (char *buf, grub_size_t size);
|
||||
int grub_envblk_set (grub_envblk_t envblk, const char *name, const char *value);
|
||||
void grub_envblk_delete (grub_envblk_t envblk, const char *name);
|
||||
diff --git a/util/grub-editenv.c b/util/grub-editenv.c
|
||||
index b8219335f7..a02d3f2a63 100644
|
||||
--- a/util/grub-editenv.c
|
||||
+++ b/util/grub-editenv.c
|
||||
@@ -210,9 +210,7 @@ create_envblk_fs (void)
|
||||
if (! fp)
|
||||
grub_util_error (_("cannot open `%s': %s"), device, strerror (errno));
|
||||
|
||||
- buf = xmalloc (size);
|
||||
- memcpy (buf, GRUB_ENVBLK_SIGNATURE, sizeof (GRUB_ENVBLK_SIGNATURE) - 1);
|
||||
- memset (buf + sizeof (GRUB_ENVBLK_SIGNATURE) - 1, '#', size - sizeof (GRUB_ENVBLK_SIGNATURE) + 1);
|
||||
+ buf = grub_envblk_buf (size);
|
||||
|
||||
if (fseek (fp, offset, SEEK_SET) < 0)
|
||||
grub_util_error (_("cannot seek `%s': %s"), device, strerror (errno));
|
||||
--
|
||||
2.34.1
|
||||
|
||||
526
0001-Add-support-for-Linux-EFI-stub-loading-on-aarch64.patch
Normal file
526
0001-Add-support-for-Linux-EFI-stub-loading-on-aarch64.patch
Normal file
@ -0,0 +1,526 @@
|
||||
From db4da8095b5ba722d22502c8d090e66816a5577d Mon Sep 17 00:00:00 2001
|
||||
From: Matthew Garrett <mjg@redhat.com>
|
||||
Date: Fri, 6 Nov 2020 08:36:36 +0000
|
||||
Subject: [PATCH 1/9] Add support for Linux EFI stub loading on aarch64.
|
||||
|
||||
Add support for Linux EFI stub loading on aarch64.
|
||||
|
||||
v1:
|
||||
Make efi handoff the default loader for arm64 platform.
|
||||
|
||||
v2:
|
||||
The efi shim_lock verifier has been moved to grub core so local
|
||||
shim_lock protocol is no longer needed here for aarch64 efi to verify
|
||||
the loaded kernel image. From now on the framework will take care the
|
||||
verificaion, consolidating the integration of various security verifiers
|
||||
like secure boot, gpg and tpm.
|
||||
|
||||
---
|
||||
grub-core/Makefile.core.def | 4 +-
|
||||
grub-core/loader/arm64/efi/linux.c | 443 +++++++++++++++++++++++++++++
|
||||
include/grub/arm/linux.h | 9 +
|
||||
include/grub/arm64/linux.h | 10 +
|
||||
4 files changed, 465 insertions(+), 1 deletion(-)
|
||||
create mode 100644 grub-core/loader/arm64/efi/linux.c
|
||||
|
||||
--- a/grub-core/Makefile.core.def
|
||||
+++ b/grub-core/Makefile.core.def
|
||||
@@ -1854,7 +1854,7 @@
|
||||
arm_coreboot = loader/arm/linux.c;
|
||||
arm_efi = loader/efi/linux.c;
|
||||
arm_uboot = loader/arm/linux.c;
|
||||
- arm64 = loader/efi/linux.c;
|
||||
+ arm64 = loader/arm64/efi/linux.c;
|
||||
loongarch64 = loader/efi/linux.c;
|
||||
riscv32 = loader/efi/linux.c;
|
||||
riscv64 = loader/efi/linux.c;
|
||||
@@ -1922,7 +1922,7 @@
|
||||
|
||||
module = {
|
||||
name = linuxefi;
|
||||
- efi = lib/fake_module.c;
|
||||
+ x86 = lib/fake_module.c;
|
||||
enable = i386_efi;
|
||||
enable = x86_64_efi;
|
||||
};
|
||||
--- /dev/null
|
||||
+++ b/grub-core/loader/arm64/efi/linux.c
|
||||
@@ -0,0 +1,411 @@
|
||||
+/*
|
||||
+ * GRUB -- GRand Unified Bootloader
|
||||
+ * Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
+ *
|
||||
+ * GRUB 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 3 of the License, or
|
||||
+ * (at your option) any later version.
|
||||
+ *
|
||||
+ * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
+ */
|
||||
+
|
||||
+#include <grub/charset.h>
|
||||
+#include <grub/command.h>
|
||||
+#include <grub/err.h>
|
||||
+#include <grub/file.h>
|
||||
+#include <grub/fdt.h>
|
||||
+#include <grub/linux.h>
|
||||
+#include <grub/loader.h>
|
||||
+#include <grub/mm.h>
|
||||
+#include <grub/types.h>
|
||||
+#include <grub/cpu/linux.h>
|
||||
+#include <grub/efi/efi.h>
|
||||
+#include <grub/efi/fdtload.h>
|
||||
+#include <grub/efi/memory.h>
|
||||
+#include <grub/efi/pe32.h>
|
||||
+#include <grub/i18n.h>
|
||||
+#include <grub/lib/cmdline.h>
|
||||
+#include <grub/verify.h>
|
||||
+
|
||||
+GRUB_MOD_LICENSE ("GPLv3+");
|
||||
+
|
||||
+static grub_dl_t my_mod;
|
||||
+static int loaded;
|
||||
+
|
||||
+static void *kernel_addr;
|
||||
+static grub_uint64_t kernel_size;
|
||||
+static grub_uint32_t handover_offset;
|
||||
+
|
||||
+static char *linux_args;
|
||||
+static grub_uint32_t cmdline_size;
|
||||
+
|
||||
+static grub_addr_t initrd_start;
|
||||
+static grub_addr_t initrd_end;
|
||||
+
|
||||
+#pragma GCC diagnostic push
|
||||
+#pragma GCC diagnostic ignored "-Wcast-align"
|
||||
+
|
||||
+typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *);
|
||||
+
|
||||
+static grub_err_t
|
||||
+grub_efi_linux_boot (void *kernel_address, grub_off_t offset,
|
||||
+ void *kernel_params)
|
||||
+{
|
||||
+ handover_func hf;
|
||||
+
|
||||
+ hf = (handover_func)((char *)kernel_address + offset);
|
||||
+ hf (grub_efi_image_handle, grub_efi_system_table, kernel_params);
|
||||
+
|
||||
+ return GRUB_ERR_BUG;
|
||||
+}
|
||||
+
|
||||
+#pragma GCC diagnostic pop
|
||||
+
|
||||
+static grub_err_t
|
||||
+grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh)
|
||||
+{
|
||||
+ if (lh->magic != GRUB_LINUX_ARMXX_MAGIC_SIGNATURE)
|
||||
+ return grub_error(GRUB_ERR_BAD_OS, "invalid magic number");
|
||||
+
|
||||
+ if ((lh->code0 & 0xffff) != GRUB_PE32_MAGIC)
|
||||
+ return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
+ N_("plain image kernel not supported - rebuild with CONFIG_(U)EFI_STUB enabled"));
|
||||
+
|
||||
+ grub_dprintf ("linux", "UEFI stub kernel:\n");
|
||||
+ grub_dprintf ("linux", "PE/COFF header @ %08x\n", lh->hdr_offset);
|
||||
+
|
||||
+ return GRUB_ERR_NONE;
|
||||
+}
|
||||
+
|
||||
+static grub_err_t
|
||||
+finalize_params_linux (void)
|
||||
+{
|
||||
+ grub_efi_loaded_image_t *loaded_image = NULL;
|
||||
+ int node, retval, len;
|
||||
+
|
||||
+ void *fdt;
|
||||
+
|
||||
+ fdt = grub_fdt_load (GRUB_EFI_LINUX_FDT_EXTRA_SPACE);
|
||||
+
|
||||
+ if (!fdt)
|
||||
+ goto failure;
|
||||
+
|
||||
+ node = grub_fdt_find_subnode (fdt, 0, "chosen");
|
||||
+ if (node < 0)
|
||||
+ node = grub_fdt_add_subnode (fdt, 0, "chosen");
|
||||
+
|
||||
+ if (node < 1)
|
||||
+ goto failure;
|
||||
+
|
||||
+ /* Set initrd info */
|
||||
+ if (initrd_start && initrd_end > initrd_start)
|
||||
+ {
|
||||
+ grub_dprintf ("linux", "Initrd @ %p-%p\n",
|
||||
+ (void *) initrd_start, (void *) initrd_end);
|
||||
+
|
||||
+ retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-start",
|
||||
+ initrd_start);
|
||||
+ if (retval)
|
||||
+ goto failure;
|
||||
+ retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-end",
|
||||
+ initrd_end);
|
||||
+ if (retval)
|
||||
+ goto failure;
|
||||
+ }
|
||||
+
|
||||
+ if (grub_fdt_install() != GRUB_ERR_NONE)
|
||||
+ goto failure;
|
||||
+
|
||||
+ grub_dprintf ("linux", "Installed/updated FDT configuration table @ %p\n",
|
||||
+ fdt);
|
||||
+
|
||||
+ /* Convert command line to UCS-2 */
|
||||
+ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
|
||||
+ if (!loaded_image)
|
||||
+ goto failure;
|
||||
+
|
||||
+ loaded_image->load_options_size = len =
|
||||
+ (grub_strlen (linux_args) + 1) * sizeof (grub_efi_char16_t);
|
||||
+ loaded_image->load_options =
|
||||
+ grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
|
||||
+ if (!loaded_image->load_options)
|
||||
+ return grub_error(GRUB_ERR_BAD_OS, "failed to create kernel parameters");
|
||||
+
|
||||
+ loaded_image->load_options_size =
|
||||
+ 2 * grub_utf8_to_utf16 (loaded_image->load_options, len,
|
||||
+ (grub_uint8_t *) linux_args, len, NULL);
|
||||
+
|
||||
+ return GRUB_ERR_NONE;
|
||||
+
|
||||
+failure:
|
||||
+ grub_fdt_unload();
|
||||
+ return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT");
|
||||
+}
|
||||
+
|
||||
+static void
|
||||
+free_params (void)
|
||||
+{
|
||||
+ grub_efi_loaded_image_t *loaded_image = NULL;
|
||||
+
|
||||
+ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
|
||||
+ if (loaded_image)
|
||||
+ {
|
||||
+ if (loaded_image->load_options)
|
||||
+ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_efi_uintn_t)loaded_image->load_options,
|
||||
+ GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
|
||||
+ loaded_image->load_options = NULL;
|
||||
+ loaded_image->load_options_size = 0;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+grub_err_t
|
||||
+grub_arch_efi_linux_boot_image (grub_addr_t addr,
|
||||
+ grub_size_t size __attribute__ ((unused)),
|
||||
+ char *args)
|
||||
+{
|
||||
+ grub_err_t retval;
|
||||
+
|
||||
+ retval = finalize_params_linux ();
|
||||
+ if (retval != GRUB_ERR_NONE)
|
||||
+ return grub_errno;
|
||||
+
|
||||
+ grub_dprintf ("linux", "linux command line: '%s'\n", args);
|
||||
+
|
||||
+ retval = grub_efi_linux_boot ((char *)addr, handover_offset, (void *)addr);
|
||||
+
|
||||
+ /* Never reached... */
|
||||
+ free_params();
|
||||
+ return retval;
|
||||
+}
|
||||
+
|
||||
+static grub_err_t
|
||||
+grub_linux_boot (void)
|
||||
+{
|
||||
+ return (grub_arch_efi_linux_boot_image ((grub_addr_t)kernel_addr, kernel_size, linux_args));
|
||||
+}
|
||||
+
|
||||
+static grub_err_t
|
||||
+grub_linux_unload (void)
|
||||
+{
|
||||
+ grub_dl_unref (my_mod);
|
||||
+ loaded = 0;
|
||||
+ if (initrd_start)
|
||||
+ grub_efi_free_pages ((grub_efi_physical_address_t) initrd_start,
|
||||
+ GRUB_EFI_BYTES_TO_PAGES (initrd_end - initrd_start));
|
||||
+ initrd_start = initrd_end = 0;
|
||||
+ grub_free (linux_args);
|
||||
+ if (kernel_addr)
|
||||
+ grub_efi_free_pages ((grub_addr_t) kernel_addr,
|
||||
+ GRUB_EFI_BYTES_TO_PAGES (kernel_size));
|
||||
+ grub_fdt_unload ();
|
||||
+ return GRUB_ERR_NONE;
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * As per linux/Documentation/arm/Booting
|
||||
+ * ARM initrd needs to be covered by kernel linear mapping,
|
||||
+ * so place it in the first 512MB of DRAM.
|
||||
+ *
|
||||
+ * As per linux/Documentation/arm64/booting.txt
|
||||
+ * ARM64 initrd needs to be contained entirely within a 1GB aligned window
|
||||
+ * of up to 32GB of size that covers the kernel image as well.
|
||||
+ * Since the EFI stub loader will attempt to load the kernel near start of
|
||||
+ * RAM, place the buffer in the first 32GB of RAM.
|
||||
+ */
|
||||
+#ifdef __arm__
|
||||
+#define INITRD_MAX_ADDRESS_OFFSET (512U * 1024 * 1024)
|
||||
+#else /* __aarch64__ */
|
||||
+#define INITRD_MAX_ADDRESS_OFFSET (32ULL * 1024 * 1024 * 1024)
|
||||
+#endif
|
||||
+
|
||||
+/*
|
||||
+ * This function returns a pointer to a legally allocated initrd buffer,
|
||||
+ * or NULL if unsuccessful
|
||||
+ */
|
||||
+static void *
|
||||
+allocate_initrd_mem (int initrd_pages)
|
||||
+{
|
||||
+ grub_addr_t max_addr;
|
||||
+
|
||||
+ if (grub_efi_get_ram_base (&max_addr) != GRUB_ERR_NONE)
|
||||
+ return NULL;
|
||||
+
|
||||
+ max_addr += INITRD_MAX_ADDRESS_OFFSET - 1;
|
||||
+
|
||||
+ return grub_efi_allocate_pages_real (max_addr, initrd_pages,
|
||||
+ GRUB_EFI_ALLOCATE_MAX_ADDRESS,
|
||||
+ GRUB_EFI_LOADER_DATA);
|
||||
+}
|
||||
+
|
||||
+static grub_err_t
|
||||
+grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
+ int argc, char *argv[])
|
||||
+{
|
||||
+ struct grub_linux_initrd_context initrd_ctx = { 0, 0, 0 };
|
||||
+ int initrd_size, initrd_pages;
|
||||
+ void *initrd_mem = NULL;
|
||||
+
|
||||
+ if (argc == 0)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ if (!loaded)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
+ N_("you need to load the kernel first"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ if (grub_initrd_init (argc, argv, &initrd_ctx))
|
||||
+ goto fail;
|
||||
+
|
||||
+ initrd_size = grub_get_initrd_size (&initrd_ctx);
|
||||
+ grub_dprintf ("linux", "Loading initrd\n");
|
||||
+
|
||||
+ initrd_pages = (GRUB_EFI_BYTES_TO_PAGES (initrd_size));
|
||||
+ initrd_mem = allocate_initrd_mem (initrd_pages);
|
||||
+
|
||||
+ if (!initrd_mem)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ if (grub_initrd_load (&initrd_ctx, initrd_mem))
|
||||
+ goto fail;
|
||||
+
|
||||
+ initrd_start = (grub_addr_t) initrd_mem;
|
||||
+ initrd_end = initrd_start + initrd_size;
|
||||
+ grub_dprintf ("linux", "[addr=%p, size=0x%x]\n",
|
||||
+ (void *) initrd_start, initrd_size);
|
||||
+
|
||||
+ fail:
|
||||
+ grub_initrd_close (&initrd_ctx);
|
||||
+ if (initrd_mem && !initrd_start)
|
||||
+ grub_efi_free_pages ((grub_addr_t) initrd_mem, initrd_pages);
|
||||
+
|
||||
+ return grub_errno;
|
||||
+}
|
||||
+
|
||||
+static grub_err_t
|
||||
+grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
+ int argc, char *argv[])
|
||||
+{
|
||||
+ grub_file_t file = 0;
|
||||
+ struct linux_arch_kernel_header lh;
|
||||
+ struct grub_armxx_linux_pe_header *pe;
|
||||
+ grub_err_t err;
|
||||
+
|
||||
+ grub_dl_ref (my_mod);
|
||||
+
|
||||
+ if (argc == 0)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
|
||||
+ if (!file)
|
||||
+ goto fail;
|
||||
+
|
||||
+ kernel_size = grub_file_size (file);
|
||||
+
|
||||
+ if (grub_file_read (file, &lh, sizeof (lh)) < (long) sizeof (lh))
|
||||
+ return grub_errno;
|
||||
+
|
||||
+ if (grub_arch_efi_linux_check_image (&lh) != GRUB_ERR_NONE)
|
||||
+ goto fail;
|
||||
+
|
||||
+ grub_loader_unset();
|
||||
+
|
||||
+ grub_dprintf ("linux", "kernel file size: %lld\n", (long long) kernel_size);
|
||||
+ kernel_addr = grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (kernel_size));
|
||||
+ grub_dprintf ("linux", "kernel numpages: %lld\n",
|
||||
+ (long long) GRUB_EFI_BYTES_TO_PAGES (kernel_size));
|
||||
+ if (!kernel_addr)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ grub_file_seek (file, 0);
|
||||
+ if (grub_file_read (file, kernel_addr, kernel_size)
|
||||
+ < (grub_int64_t) kernel_size)
|
||||
+ {
|
||||
+ if (!grub_errno)
|
||||
+ grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), argv[0]);
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ grub_dprintf ("linux", "kernel @ %p\n", kernel_addr);
|
||||
+
|
||||
+ pe = (void *)((unsigned long)kernel_addr + lh.hdr_offset);
|
||||
+ handover_offset = pe->opt.entry_addr;
|
||||
+
|
||||
+ cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE);
|
||||
+ linux_args = grub_malloc (cmdline_size);
|
||||
+ if (!linux_args)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+ grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
+ err = grub_create_loader_cmdline (argc, argv,
|
||||
+ linux_args + sizeof (LINUX_IMAGE) - 1,
|
||||
+ cmdline_size,
|
||||
+ GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
+ if (err)
|
||||
+ goto fail;
|
||||
+
|
||||
+ if (grub_errno == GRUB_ERR_NONE)
|
||||
+ {
|
||||
+ grub_loader_set (grub_linux_boot, grub_linux_unload, 0);
|
||||
+ loaded = 1;
|
||||
+ }
|
||||
+
|
||||
+fail:
|
||||
+ if (file)
|
||||
+ grub_file_close (file);
|
||||
+
|
||||
+ if (grub_errno != GRUB_ERR_NONE)
|
||||
+ {
|
||||
+ grub_dl_unref (my_mod);
|
||||
+ loaded = 0;
|
||||
+ }
|
||||
+
|
||||
+ if (linux_args && !loaded)
|
||||
+ grub_free (linux_args);
|
||||
+
|
||||
+ if (kernel_addr && !loaded)
|
||||
+ grub_efi_free_pages ((grub_addr_t) kernel_addr,
|
||||
+ GRUB_EFI_BYTES_TO_PAGES (kernel_size));
|
||||
+
|
||||
+ return grub_errno;
|
||||
+}
|
||||
+
|
||||
+
|
||||
+static grub_command_t cmd_linux, cmd_initrd;
|
||||
+
|
||||
+GRUB_MOD_INIT (linux)
|
||||
+{
|
||||
+ cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0,
|
||||
+ N_("Load Linux."));
|
||||
+ cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0,
|
||||
+ N_("Load initrd."));
|
||||
+ my_mod = mod;
|
||||
+}
|
||||
+
|
||||
+GRUB_MOD_FINI (linux)
|
||||
+{
|
||||
+ grub_unregister_command (cmd_linux);
|
||||
+ grub_unregister_command (cmd_initrd);
|
||||
+}
|
||||
--- a/include/grub/arm/linux.h
|
||||
+++ b/include/grub/arm/linux.h
|
||||
@@ -20,10 +20,22 @@
|
||||
#ifndef GRUB_ARM_LINUX_HEADER
|
||||
#define GRUB_ARM_LINUX_HEADER 1
|
||||
|
||||
+#include <grub/efi/pe32.h>
|
||||
#include "system.h"
|
||||
|
||||
#include <grub/efi/pe32.h>
|
||||
|
||||
+struct grub_arm_linux_pe_header
|
||||
+{
|
||||
+ grub_uint32_t magic;
|
||||
+ struct grub_pe32_coff_header coff;
|
||||
+ struct grub_pe32_optional_header opt;
|
||||
+};
|
||||
+
|
||||
+#if defined(__arm__)
|
||||
+# define grub_armxx_linux_pe_header grub_arm_linux_pe_header
|
||||
+#endif
|
||||
+
|
||||
#if defined GRUB_MACHINE_UBOOT
|
||||
# include <grub/uboot/uboot.h>
|
||||
# define LINUX_ADDRESS (start_of_ram + 0x8000)
|
||||
--- /dev/null
|
||||
+++ b/include/grub/arm64/linux.h
|
||||
@@ -0,0 +1,39 @@
|
||||
+/*
|
||||
+ * GRUB -- GRand Unified Bootloader
|
||||
+ * Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
+ *
|
||||
+ * GRUB 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 3 of the License, or
|
||||
+ * (at your option) any later version.
|
||||
+ *
|
||||
+ * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
+ */
|
||||
+
|
||||
+#ifndef GRUB_ARM64_LINUX_HEADER
|
||||
+#define GRUB_ARM64_LINUX_HEADER 1
|
||||
+
|
||||
+#include <grub/types.h>
|
||||
+#include <grub/efi/pe32.h>
|
||||
+
|
||||
+#define GRUB_LINUX_ARM64_MAGIC_SIGNATURE 0x644d5241 /* 'ARM\x64' */
|
||||
+
|
||||
+struct grub_arm64_linux_pe_header
|
||||
+{
|
||||
+ grub_uint32_t magic;
|
||||
+ struct grub_pe32_coff_header coff;
|
||||
+ struct grub_pe64_optional_header opt;
|
||||
+};
|
||||
+
|
||||
+#if defined(__aarch64__)
|
||||
+# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE
|
||||
+# define grub_armxx_linux_pe_header grub_arm64_linux_pe_header
|
||||
+#endif
|
||||
+
|
||||
+#endif /* ! GRUB_ARM64_LINUX_HEADER */
|
||||
215
0001-Factor-out-grub_efi_linux_boot.patch
Normal file
215
0001-Factor-out-grub_efi_linux_boot.patch
Normal file
@ -0,0 +1,215 @@
|
||||
From 82d95254ca0496c8843113665bb9a99876101025 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Fri, 8 Oct 2021 13:36:45 +0800
|
||||
Subject: [PATCH 01/11] Factor out grub_efi_linux_boot
|
||||
|
||||
Both x86 and arm64 on efi are using handover protocol to boot linux
|
||||
kernel. To enable better code reuse, factor out grub_efi_linux_boot from
|
||||
arm64 so that it can be shared with x86 platform for the common fixes.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/Makefile.core.def | 1 +
|
||||
grub-core/loader/arm64/efi/linux.c | 35 +-----------------
|
||||
grub-core/loader/efi/linux.c | 58 ++++++++++++++++++++++++++++++
|
||||
grub-core/loader/i386/efi/linux.c | 13 ++-----
|
||||
include/grub/efi/linux.h | 29 +++++++++++++++
|
||||
5 files changed, 92 insertions(+), 44 deletions(-)
|
||||
create mode 100644 grub-core/loader/efi/linux.c
|
||||
create mode 100644 include/grub/efi/linux.h
|
||||
|
||||
--- a/grub-core/Makefile.core.def
|
||||
+++ b/grub-core/Makefile.core.def
|
||||
@@ -1860,6 +1860,9 @@
|
||||
riscv64 = loader/efi/linux.c;
|
||||
emu = loader/emu/linux.c;
|
||||
common = loader/linux.c;
|
||||
+ i386_efi = loader/efi/linux_boot.c;
|
||||
+ x86_64_efi = loader/efi/linux_boot.c;
|
||||
+ arm64 = loader/efi/linux_boot.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
--- a/grub-core/loader/arm64/efi/linux.c
|
||||
+++ b/grub-core/loader/arm64/efi/linux.c
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/lib/cmdline.h>
|
||||
#include <grub/verify.h>
|
||||
+#include <grub/efi/linux.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -51,40 +52,6 @@
|
||||
static grub_addr_t initrd_start;
|
||||
static grub_addr_t initrd_end;
|
||||
|
||||
-#pragma GCC diagnostic push
|
||||
-#pragma GCC diagnostic ignored "-Wcast-align"
|
||||
-
|
||||
-typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *);
|
||||
-
|
||||
-static grub_err_t
|
||||
-grub_efi_linux_boot (void *kernel_address, grub_off_t offset,
|
||||
- void *kernel_params)
|
||||
-{
|
||||
- grub_efi_loaded_image_t *loaded_image = NULL;
|
||||
- handover_func hf;
|
||||
-
|
||||
- /*
|
||||
- * Since the EFI loader is not calling the LoadImage() and StartImage()
|
||||
- * services for loading the kernel and booting respectively, it has to
|
||||
- * set the Loaded Image base address.
|
||||
- */
|
||||
- loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
|
||||
- if (loaded_image)
|
||||
- loaded_image->image_base = kernel_addr;
|
||||
- else
|
||||
- grub_dprintf ("linux", "Loaded Image base address could not be set\n");
|
||||
-
|
||||
- grub_dprintf ("linux", "kernel_addr: %p handover_offset: %p params: %p\n",
|
||||
- kernel_address, (void *)(grub_efi_uintn_t)offset, kernel_params);
|
||||
- hf = (handover_func)((char *)kernel_address + offset);
|
||||
- grub_dprintf ("linux", "handover_func() = %p\n", hf);
|
||||
- hf (grub_efi_image_handle, grub_efi_system_table, kernel_params);
|
||||
-
|
||||
- return GRUB_ERR_BUG;
|
||||
-}
|
||||
-
|
||||
-#pragma GCC diagnostic pop
|
||||
-
|
||||
static grub_err_t
|
||||
grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh)
|
||||
{
|
||||
--- a/grub-core/loader/i386/efi/linux.c
|
||||
+++ b/grub-core/loader/i386/efi/linux.c
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/lib/cmdline.h>
|
||||
#include <grub/efi/efi.h>
|
||||
+#include <grub/efi/linux.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -40,26 +41,18 @@
|
||||
|
||||
#define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12)
|
||||
|
||||
-typedef void(*handover_func)(void *, grub_efi_system_table_t *, struct linux_kernel_params *);
|
||||
-
|
||||
static grub_err_t
|
||||
grub_linuxefi_boot (void)
|
||||
{
|
||||
- handover_func hf;
|
||||
int offset = 0;
|
||||
|
||||
#ifdef __x86_64__
|
||||
offset = 512;
|
||||
#endif
|
||||
-
|
||||
- hf = (handover_func)((char *)kernel_mem + handover_offset + offset);
|
||||
-
|
||||
asm volatile ("cli");
|
||||
|
||||
- hf (grub_efi_image_handle, grub_efi_system_table, params);
|
||||
-
|
||||
- /* Not reached */
|
||||
- return GRUB_ERR_NONE;
|
||||
+ return grub_efi_linux_boot ((char *)kernel_mem, handover_offset + offset,
|
||||
+ params);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
--- /dev/null
|
||||
+++ b/include/grub/efi/linux.h
|
||||
@@ -0,0 +1,29 @@
|
||||
+/*
|
||||
+ * GRUB -- GRand Unified Bootloader
|
||||
+ * Copyright (C) 2014 Free Software Foundation, Inc.
|
||||
+ *
|
||||
+ * GRUB 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 3 of the License, or
|
||||
+ * (at your option) any later version.
|
||||
+ *
|
||||
+ * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
+ */
|
||||
+#ifndef GRUB_EFI_LINUX_HEADER
|
||||
+#define GRUB_EFI_LINUX_HEADER 1
|
||||
+
|
||||
+#include <grub/efi/api.h>
|
||||
+#include <grub/err.h>
|
||||
+#include <grub/symbol.h>
|
||||
+
|
||||
+grub_err_t
|
||||
+EXPORT_FUNC(grub_efi_linux_boot) (void *kernel_address, grub_off_t offset,
|
||||
+ void *kernel_param);
|
||||
+
|
||||
+#endif /* ! GRUB_EFI_LINUX_HEADER */
|
||||
--- /dev/null
|
||||
+++ b/grub-core/loader/efi/linux_boot.c
|
||||
@@ -0,0 +1,58 @@
|
||||
+/*
|
||||
+ * GRUB -- GRand Unified Bootloader
|
||||
+ * Copyright (C) 2014 Free Software Foundation, Inc.
|
||||
+ *
|
||||
+ * GRUB 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 3 of the License, or
|
||||
+ * (at your option) any later version.
|
||||
+ *
|
||||
+ * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
+ */
|
||||
+
|
||||
+#include <grub/err.h>
|
||||
+#include <grub/mm.h>
|
||||
+#include <grub/types.h>
|
||||
+#include <grub/cpu/linux.h>
|
||||
+#include <grub/efi/efi.h>
|
||||
+#include <grub/efi/pe32.h>
|
||||
+#include <grub/efi/linux.h>
|
||||
+
|
||||
+#pragma GCC diagnostic push
|
||||
+#pragma GCC diagnostic ignored "-Wcast-align"
|
||||
+
|
||||
+typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *);
|
||||
+
|
||||
+grub_err_t
|
||||
+grub_efi_linux_boot (void *kernel_addr, grub_off_t offset,
|
||||
+ void *kernel_params)
|
||||
+{
|
||||
+ grub_efi_loaded_image_t *loaded_image = NULL;
|
||||
+ handover_func hf;
|
||||
+
|
||||
+ /*
|
||||
+ * Since the EFI loader is not calling the LoadImage() and StartImage()
|
||||
+ * services for loading the kernel and booting respectively, it has to
|
||||
+ * set the Loaded Image base address.
|
||||
+ */
|
||||
+ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
|
||||
+ if (loaded_image)
|
||||
+ loaded_image->image_base = kernel_addr;
|
||||
+ else
|
||||
+ grub_dprintf ("linux", "Loaded Image base address could not be set\n");
|
||||
+
|
||||
+ grub_dprintf ("linux", "kernel_addr: %p handover_offset: %p params: %p\n",
|
||||
+ kernel_addr, (void *)(grub_efi_uintn_t)offset, kernel_params);
|
||||
+ hf = (handover_func)((char *)kernel_addr + offset);
|
||||
+ hf (grub_efi_image_handle, grub_efi_system_table, kernel_params);
|
||||
+
|
||||
+ return GRUB_ERR_BUG;
|
||||
+}
|
||||
+
|
||||
+#pragma GCC diagnostic pop
|
||||
66
0001-Fix-infinite-boot-loop-on-headless-system-in-qemu.patch
Normal file
66
0001-Fix-infinite-boot-loop-on-headless-system-in-qemu.patch
Normal file
@ -0,0 +1,66 @@
|
||||
From f76317d9dc35dbc576820ba6c2a6a8e41f5338b5 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Thu, 19 May 2022 13:08:12 +0800
|
||||
Subject: [PATCH] Fix infinite boot loop on headless system in qemu
|
||||
|
||||
After finishing headless virtual machine installation via serial
|
||||
console, the reboot fails in grub with infinte boot loop and also
|
||||
keyboard input for serial console is unresponsive.
|
||||
|
||||
The cause of infinte loop boils down to legacy vga driver in grub
|
||||
crashes when '-dispaly none' is used as qemu's display type described in
|
||||
the manual as:
|
||||
|
||||
"Do not display video output. The guest will still see an emulated
|
||||
graphics card, but its output will not be displayed tothe QEMU user.
|
||||
This option differs from the -nographic option in that it only affects
|
||||
what is done with video output; -nographic also changes the destination
|
||||
of the serial and parallel port data."
|
||||
|
||||
Given there's no sensible way found to skip the emulated device from the
|
||||
legacy vga module, we ended up removing it from all_video dependency so
|
||||
it wouldn't be loaded by default. In any case, the vbe module remain
|
||||
loaded and should fulfill the requirement of most hardwares even twenty
|
||||
years old or more.
|
||||
|
||||
The unresponsive serial input is also fixed by ensuring that console
|
||||
input is loaded via appended so that they won't fail altogether with
|
||||
errors by other console device if specifying on the same list.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/genmoddep.awk | 3 +++
|
||||
util/grub.d/00_header.in | 10 +++++++++-
|
||||
2 files changed, 12 insertions(+), 1 deletion(-)
|
||||
|
||||
--- a/grub-core/genmoddep.awk
|
||||
+++ b/grub-core/genmoddep.awk
|
||||
@@ -98,6 +98,9 @@
|
||||
}
|
||||
modlist = ""
|
||||
while (getline <"video.lst") {
|
||||
+ if ($1 == "vga") {
|
||||
+ continue;
|
||||
+ }
|
||||
modlist = modlist " " $1;
|
||||
}
|
||||
printf "all_video:%s\n", modlist;
|
||||
--- a/util/grub.d/00_header.in
|
||||
+++ b/util/grub.d/00_header.in
|
||||
@@ -287,7 +287,15 @@
|
||||
;;
|
||||
x*)
|
||||
cat << EOF
|
||||
-terminal_output ${GRUB_TERMINAL_OUTPUT}
|
||||
+
|
||||
+for i in ${GRUB_TERMINAL_OUTPUT}; do
|
||||
+ if [ x\${use_append} = xtrue ]; then
|
||||
+ terminal_output --append \$i
|
||||
+ elif terminal_output \$i; then
|
||||
+ use_append=true;
|
||||
+ fi
|
||||
+done
|
||||
+
|
||||
EOF
|
||||
;;
|
||||
esac
|
||||
286
0001-Improve-TPM-key-protection-on-boot-interruptions.patch
Normal file
286
0001-Improve-TPM-key-protection-on-boot-interruptions.patch
Normal file
@ -0,0 +1,286 @@
|
||||
From fe7ed9104cef56f9e532a0c9a7164393d5d69ae1 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Fri, 17 Nov 2023 12:32:59 +0800
|
||||
Subject: [PATCH 1/4] Improve TPM key protection on boot interruptions
|
||||
|
||||
The unattended boot process for full disk encryption relies on an
|
||||
authorized TPM policy to ensure the system's integrity before releasing
|
||||
the key to grub. Subsequently, grub assumes responsibility for securing
|
||||
the boot process, directing it towards a trusted default without any
|
||||
expected interruptions. Any interruption during this process indicates
|
||||
potential modification attempts, and releasing the obtained key to the
|
||||
next stage should not occur in such cases.
|
||||
|
||||
This commit addresses a vulnerability associated with interrupted boot
|
||||
processes that could potentially enable malicious modifications to the
|
||||
default or trusted boot target. To reinforce system security, the code
|
||||
has been updated to incorporate measures that discard the TPM protected
|
||||
key in the event of boot interruptions.
|
||||
|
||||
Furthermore, this patch aims to enhance code readability by renaming
|
||||
structures and function names related to cryptographic keys, improving
|
||||
clarity and maintainability.
|
||||
|
||||
By implementing these changes, this enhancement seeks to fortify the
|
||||
protection of TPM keys, thereby ensuring a more robust defense against
|
||||
potential unauthorized modifications during the boot process.
|
||||
|
||||
Signed-Off-by Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/commands/crypttab.c | 38 ++++++++++++++++++++++++++---------
|
||||
grub-core/disk/cryptodisk.c | 8 +++++++-
|
||||
grub-core/loader/linux.c | 6 +++---
|
||||
grub-core/normal/main.c | 2 +-
|
||||
grub-core/normal/menu.c | 7 +++++++
|
||||
grub-core/normal/menu_entry.c | 2 +-
|
||||
include/grub/crypttab.h | 18 ++++++++++-------
|
||||
7 files changed, 59 insertions(+), 22 deletions(-)
|
||||
|
||||
diff --git a/grub-core/commands/crypttab.c b/grub-core/commands/crypttab.c
|
||||
index c2217ca98..9397bede9 100644
|
||||
--- a/grub-core/commands/crypttab.c
|
||||
+++ b/grub-core/commands/crypttab.c
|
||||
@@ -9,17 +9,20 @@
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
-struct grub_key_publisher *kpuber;
|
||||
+grub_crypto_key_list_t *cryptokey_lst;
|
||||
|
||||
grub_err_t
|
||||
-grub_initrd_publish_key (const char *uuid, const char *key, grub_size_t key_len, const char *path)
|
||||
+grub_cryptokey_add_or_update (const char *uuid, const char *key, grub_size_t key_len, const char *path, int is_tpmkey)
|
||||
{
|
||||
- struct grub_key_publisher *cur = NULL;
|
||||
+ grub_crypto_key_list_t *cur = NULL;
|
||||
|
||||
- FOR_LIST_ELEMENTS (cur, kpuber)
|
||||
+ FOR_LIST_ELEMENTS (cur, cryptokey_lst)
|
||||
if (grub_uuidcasecmp (cur->name, uuid, sizeof (cur->name)) == 0)
|
||||
break;
|
||||
|
||||
+ if (!cur && !uuid)
|
||||
+ return GRUB_ERR_NONE;
|
||||
+
|
||||
if (!cur)
|
||||
cur = grub_zalloc (sizeof (*cur));
|
||||
if (!cur)
|
||||
@@ -44,21 +47,24 @@ grub_initrd_publish_key (const char *uuid, const char *key, grub_size_t key_len,
|
||||
cur->path = grub_strdup (path);
|
||||
}
|
||||
|
||||
+ if (is_tpmkey >= 0)
|
||||
+ cur->is_tpmkey = is_tpmkey;
|
||||
+
|
||||
if (!cur->name)
|
||||
{
|
||||
cur->name = grub_strdup (uuid);
|
||||
- grub_list_push (GRUB_AS_LIST_P (&kpuber), GRUB_AS_LIST (cur));
|
||||
+ grub_list_push (GRUB_AS_LIST_P (&cryptokey_lst), GRUB_AS_LIST (cur));
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
void
|
||||
-grub_initrd_discard_key (void)
|
||||
+grub_cryptokey_discard (void)
|
||||
{
|
||||
- struct grub_key_publisher *cur, *nxt;
|
||||
+ grub_crypto_key_list_t *cur, *nxt;
|
||||
|
||||
- FOR_LIST_ELEMENTS_SAFE (cur, nxt, kpuber)
|
||||
+ FOR_LIST_ELEMENTS_SAFE (cur, nxt, cryptokey_lst)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST (cur));
|
||||
grub_memset (cur->key, 0, cur->key_len);
|
||||
@@ -69,6 +75,20 @@ grub_initrd_discard_key (void)
|
||||
}
|
||||
}
|
||||
|
||||
+void
|
||||
+grub_cryptokey_tpmkey_discard (void)
|
||||
+{
|
||||
+ grub_crypto_key_list_t *cur = NULL;
|
||||
+
|
||||
+ FOR_LIST_ELEMENTS (cur, cryptokey_lst)
|
||||
+ if (cur->is_tpmkey)
|
||||
+ break;
|
||||
+
|
||||
+ /* Discard all keys if any of them is tpm */
|
||||
+ if (cur)
|
||||
+ grub_cryptokey_discard();
|
||||
+}
|
||||
+
|
||||
static grub_err_t
|
||||
grub_cmd_crypttab_entry (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char **argv)
|
||||
@@ -92,7 +112,7 @@ grub_cmd_crypttab_entry (grub_command_t cmd __attribute__ ((unused)),
|
||||
}
|
||||
|
||||
/*FIXME: Validate UUID string*/
|
||||
- return grub_initrd_publish_key (argv[1], NULL, 0, path);
|
||||
+ return grub_cryptokey_add_or_update (argv[1], NULL, 0, path, -1);
|
||||
}
|
||||
|
||||
static grub_command_t cmd;
|
||||
diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c
|
||||
index c79d4125a..d90ca06dc 100644
|
||||
--- a/grub-core/disk/cryptodisk.c
|
||||
+++ b/grub-core/disk/cryptodisk.c
|
||||
@@ -1071,6 +1071,9 @@ grub_cryptodisk_scan_device_real (const char *name,
|
||||
struct cryptodisk_read_hook_ctx read_hook_data = {0};
|
||||
int askpass = 0;
|
||||
char *part = NULL;
|
||||
+#ifndef GRUB_UTIL
|
||||
+ int is_tpmkey = 0;
|
||||
+#endif
|
||||
|
||||
dev = grub_cryptodisk_get_by_source_disk (source);
|
||||
|
||||
@@ -1183,6 +1186,9 @@ grub_cryptodisk_scan_device_real (const char *name,
|
||||
ret = grub_cryptodisk_insert (dev, name, source);
|
||||
if (ret != GRUB_ERR_NONE)
|
||||
goto error;
|
||||
+#ifndef GRUB_UTIL
|
||||
+ is_tpmkey = 1;
|
||||
+#endif
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
@@ -1244,7 +1250,7 @@ grub_cryptodisk_scan_device_real (const char *name,
|
||||
|
||||
#ifndef GRUB_UTIL
|
||||
if (cargs->key_data && dev)
|
||||
- grub_initrd_publish_key (dev->uuid, (const char *)cargs->key_data, cargs->key_len, NULL);
|
||||
+ grub_cryptokey_add_or_update (dev->uuid, (const char *)cargs->key_data, cargs->key_len, NULL, is_tpmkey);
|
||||
#endif
|
||||
if (askpass)
|
||||
{
|
||||
diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c
|
||||
index 9ee8f3790..e5e792958 100644
|
||||
--- a/grub-core/loader/linux.c
|
||||
+++ b/grub-core/loader/linux.c
|
||||
@@ -226,13 +226,13 @@ grub_initrd_init (int argc, char *argv[],
|
||||
int i;
|
||||
int newc = 0;
|
||||
struct dir *root = 0;
|
||||
- struct grub_key_publisher *pk;
|
||||
+ grub_crypto_key_list_t *pk;
|
||||
int numkey = 0;
|
||||
|
||||
initrd_ctx->nfiles = 0;
|
||||
initrd_ctx->components = 0;
|
||||
|
||||
- FOR_LIST_ELEMENTS (pk, kpuber)
|
||||
+ FOR_LIST_ELEMENTS (pk, cryptokey_lst)
|
||||
if (pk->key && pk->path)
|
||||
numkey++;
|
||||
|
||||
@@ -305,7 +305,7 @@ grub_initrd_init (int argc, char *argv[],
|
||||
goto overflow;
|
||||
}
|
||||
|
||||
- FOR_LIST_ELEMENTS (pk, kpuber)
|
||||
+ FOR_LIST_ELEMENTS (pk, cryptokey_lst)
|
||||
if (pk->key && pk->path)
|
||||
{
|
||||
grub_initrd_component (pk->key, pk->key_len, pk->path, initrd_ctx);
|
||||
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
|
||||
index a3f711d1d..1b426af69 100644
|
||||
--- a/grub-core/normal/main.c
|
||||
+++ b/grub-core/normal/main.c
|
||||
@@ -479,7 +479,7 @@ grub_cmdline_run (int nested, int force_auth)
|
||||
return;
|
||||
}
|
||||
|
||||
- grub_initrd_discard_key ();
|
||||
+ grub_cryptokey_discard ();
|
||||
grub_normal_reader_init (nested);
|
||||
|
||||
while (1)
|
||||
diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
|
||||
index 14b0ab1ec..1df2638d7 100644
|
||||
--- a/grub-core/normal/menu.c
|
||||
+++ b/grub-core/normal/menu.c
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <grub/script_sh.h>
|
||||
#include <grub/gfxterm.h>
|
||||
#include <grub/dl.h>
|
||||
+#include <grub/crypttab.h>
|
||||
|
||||
/* Time to delay after displaying an error message about a default/fallback
|
||||
entry failing to boot. */
|
||||
@@ -708,6 +709,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot, int *notify_boot)
|
||||
if (grub_key_is_interrupt (key))
|
||||
{
|
||||
timeout = -1;
|
||||
+ grub_cryptokey_tpmkey_discard();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -790,6 +792,11 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot, int *notify_boot)
|
||||
clear_timeout ();
|
||||
}
|
||||
|
||||
+ /* Timeout is interrupted by external input, Forget tpmkey if timeout
|
||||
+ * is not cut by enter */
|
||||
+ if (c != '\n' && c != '\r')
|
||||
+ grub_cryptokey_tpmkey_discard();
|
||||
+
|
||||
switch (c)
|
||||
{
|
||||
case GRUB_TERM_KEY_HOME:
|
||||
diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c
|
||||
index 384ab9ce3..e5ba91ea4 100644
|
||||
--- a/grub-core/normal/menu_entry.c
|
||||
+++ b/grub-core/normal/menu_entry.c
|
||||
@@ -1263,7 +1263,7 @@ grub_menu_entry_run (grub_menu_entry_t entry)
|
||||
return;
|
||||
}
|
||||
|
||||
- grub_initrd_discard_key();
|
||||
+ grub_cryptokey_discard();
|
||||
|
||||
screen = make_screen (entry);
|
||||
if (! screen)
|
||||
diff --git a/include/grub/crypttab.h b/include/grub/crypttab.h
|
||||
index 113c53cfc..f86404686 100644
|
||||
--- a/include/grub/crypttab.h
|
||||
+++ b/include/grub/crypttab.h
|
||||
@@ -4,21 +4,25 @@
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
|
||||
-struct grub_key_publisher
|
||||
+typedef struct grub_crypto_key_list
|
||||
{
|
||||
- struct grub_key_publisher *next;
|
||||
- struct grub_key_publisher **prev;
|
||||
+ struct grub_crypto_key_list *next;
|
||||
+ struct grub_crypto_key_list **prev;
|
||||
char *name; /* UUID */
|
||||
char *path;
|
||||
char *key;
|
||||
grub_size_t key_len;
|
||||
-};
|
||||
+ int is_tpmkey;
|
||||
+} grub_crypto_key_list_t;
|
||||
|
||||
-extern struct grub_key_publisher *EXPORT_VAR (kpuber);
|
||||
+extern grub_crypto_key_list_t *EXPORT_VAR (cryptokey_lst);
|
||||
|
||||
grub_err_t
|
||||
-grub_initrd_publish_key (const char *uuid, const char *key, grub_size_t key_len, const char *path);
|
||||
+grub_cryptokey_add_or_update (const char *uuid, const char *key, grub_size_t key_len, const char *path, int is_tpmkey);
|
||||
|
||||
void
|
||||
-grub_initrd_discard_key (void);
|
||||
+grub_cryptokey_discard (void);
|
||||
+
|
||||
+void
|
||||
+grub_cryptokey_tpmkey_discard (void);
|
||||
#endif /* ! GRUB_CRYPTTAB_HEADER */
|
||||
--
|
||||
2.42.1
|
||||
|
||||
82
0001-Make-grub.cfg-compatible-to-old-binaries.patch
Normal file
82
0001-Make-grub.cfg-compatible-to-old-binaries.patch
Normal file
@ -0,0 +1,82 @@
|
||||
From b8457f2e271917c5c83a4fee286bafedf8c5790c Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Tue, 8 Aug 2023 17:57:24 +0800
|
||||
Subject: [PATCH] Make grub.cfg compatible to old binaries
|
||||
|
||||
The new added fwsetup test in the topmost menu is always executed
|
||||
regardless older grub may not be able to handle and thus trapped in a
|
||||
boot loop between grub and fwsetup.
|
||||
|
||||
This in particular is to make sure a smooth transition if grub is rolled
|
||||
back to older release and needs to boot newer snapshots.
|
||||
|
||||
Also removing dashes in the UUID that every version released in the wild
|
||||
can handle.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
util/grub-probe.c | 20 +++++++++++++++++++-
|
||||
util/grub.d/30_uefi-firmware.in | 16 ++++++++++------
|
||||
2 files changed, 29 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/util/grub-probe.c b/util/grub-probe.c
|
||||
index e7efcc268..99c738e44 100644
|
||||
--- a/util/grub-probe.c
|
||||
+++ b/util/grub-probe.c
|
||||
@@ -290,8 +290,26 @@ probe_cryptodisk_uuid (grub_disk_t disk, char delim)
|
||||
}
|
||||
if (disk->dev->id == GRUB_DISK_DEVICE_CRYPTODISK_ID)
|
||||
{
|
||||
+ grub_size_t i, j;
|
||||
const char *uu = grub_util_cryptodisk_get_uuid (disk);
|
||||
- grub_printf ("%s%c", uu, delim);
|
||||
+ grub_size_t len = grub_strlen (uu);
|
||||
+ char *p = grub_malloc (len + 1);
|
||||
+
|
||||
+ /* Removing dash in the UUID string
|
||||
+ * This keeps old grub binary to work with newer config in a system,
|
||||
+ * especially for snapshots. It is a temporary change to make sure smooth
|
||||
+ * transition from 2.06 to 2.12-rc1 and this hunk can be removed
|
||||
+ * after 2.12-rc1 release stablized.
|
||||
+ */
|
||||
+ for (i = 0, j = 0; i < len; i++)
|
||||
+ {
|
||||
+ if (uu[i] != '-')
|
||||
+ p[j++] = uu[i];
|
||||
+ }
|
||||
+ p[j] = '\0';
|
||||
+
|
||||
+ grub_printf ("%s%c", p, delim);
|
||||
+ grub_free (p);
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/util/grub.d/30_uefi-firmware.in b/util/grub.d/30_uefi-firmware.in
|
||||
index 1c2365ddb..96ff112e5 100644
|
||||
--- a/util/grub.d/30_uefi-firmware.in
|
||||
+++ b/util/grub.d/30_uefi-firmware.in
|
||||
@@ -32,11 +32,15 @@ gettext_printf "Adding boot menu entry for UEFI Firmware Settings ...\n" >&2
|
||||
|
||||
cat << EOF
|
||||
if [ "\$grub_platform" = "efi" ]; then
|
||||
- fwsetup --is-supported
|
||||
- if [ "\$?" = 0 ]; then
|
||||
- menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' {
|
||||
- fwsetup
|
||||
- }
|
||||
- fi
|
||||
+ menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' {
|
||||
+ fwsetup --is-supported
|
||||
+ if [ "\$?" = 0 ]; then
|
||||
+ fwsetup
|
||||
+ else
|
||||
+ echo "Your firmware doesn't support setup menu entry from a boot loader"
|
||||
+ echo "Press any key to return ..."
|
||||
+ read
|
||||
+ fi
|
||||
+ }
|
||||
fi
|
||||
EOF
|
||||
--
|
||||
2.41.0
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Javier Martinez Canillas <javierm@redhat.com>
|
||||
Date: Fri, 11 Jun 2021 12:10:45 +0200
|
||||
Subject: [PATCH] Revert "templates: Fix user-facing typo with an incorrect use
|
||||
of "it's""
|
||||
|
||||
This reverts commit 722737630889607c3b5761f1f5a48f1674cd2821.
|
||||
---
|
||||
util/grub.d/30_os-prober.in | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in
|
||||
index 5984e92d291..94622481284 100644
|
||||
--- a/util/grub.d/30_os-prober.in
|
||||
+++ b/util/grub.d/30_os-prober.in
|
||||
@@ -36,7 +36,7 @@ if ! command -v os-prober > /dev/null || ! command -v linux-boot-prober > /dev/n
|
||||
exit 0
|
||||
fi
|
||||
|
||||
-grub_warn "$(gettext_printf "os-prober will be executed to detect other bootable partitions.\nIts output will be used to detect bootable binaries on them and create new boot entries.")"
|
||||
+grub_warn "$(gettext_printf "os-prober will be executed to detect other bootable partitions.\nIt's output will be used to detect bootable binaries on them and create new boot entries.")"
|
||||
|
||||
OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`"
|
||||
if [ -z "${OSPROBED}" ] ; then
|
||||
150
0001-Unify-the-check-to-enable-btrfs-relative-path.patch
Normal file
150
0001-Unify-the-check-to-enable-btrfs-relative-path.patch
Normal file
@ -0,0 +1,150 @@
|
||||
From 80bb1b17b3f596dbd7331cf9cb20a46c8ef9800b Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Sat, 22 Aug 2020 02:32:43 +0800
|
||||
Subject: [PATCH] Unify the check to enable btrfs relative path
|
||||
|
||||
This unified the test in grub-install and grub-mkconfig that the path to
|
||||
default or selected btrfs subvolume/snapshot is used if the root file
|
||||
system is btrfs and the config has enabled btrfs snapshot booting.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
util/grub-install.c | 67 +++++++++++++++++++++++++++------------
|
||||
util/grub-mkconfig_lib.in | 3 +-
|
||||
2 files changed, 48 insertions(+), 22 deletions(-)
|
||||
|
||||
--- a/util/grub-install.c
|
||||
+++ b/util/grub-install.c
|
||||
@@ -886,6 +886,7 @@
|
||||
const char *efi_file = NULL;
|
||||
char **grub_devices;
|
||||
grub_fs_t grub_fs;
|
||||
+ grub_fs_t root_fs;
|
||||
grub_device_t grub_dev = NULL;
|
||||
enum grub_install_plat platform;
|
||||
char *grubdir, *device_map;
|
||||
@@ -898,6 +899,8 @@
|
||||
int efidir_is_mac = 0;
|
||||
int is_prep = 0;
|
||||
const char *pkgdatadir;
|
||||
+ char *rootdir_path;
|
||||
+ char **rootdir_devices;
|
||||
|
||||
grub_util_host_init (&argc, &argv);
|
||||
product_version = xstrdup (PACKAGE_VERSION);
|
||||
@@ -911,9 +914,6 @@
|
||||
|
||||
grub_util_load_config (&config);
|
||||
|
||||
- if (config.is_suse_btrfs_snapshot_enabled)
|
||||
- use_relative_path_on_btrfs = 1;
|
||||
-
|
||||
if (!bootloader_id && config.grub_distributor)
|
||||
{
|
||||
char *ptr;
|
||||
@@ -1064,6 +1064,45 @@
|
||||
grub_hostfs_init ();
|
||||
grub_host_init ();
|
||||
|
||||
+ {
|
||||
+ char *rootdir_grub_devname;
|
||||
+ grub_device_t rootdir_grub_dev;
|
||||
+ char *t = grub_util_path_concat (2, "/", rootdir);
|
||||
+
|
||||
+ rootdir_path = grub_canonicalize_file_name (t);
|
||||
+ if (!rootdir_path)
|
||||
+ grub_util_error (_("failed to get canonical path of `%s'"), t);
|
||||
+
|
||||
+ rootdir_devices = grub_guess_root_devices (rootdir_path);
|
||||
+ if (!rootdir_devices || !rootdir_devices[0])
|
||||
+ grub_util_error (_("cannot find a device for %s (is /dev mounted?)"),
|
||||
+ rootdir_path);
|
||||
+
|
||||
+ for (curdev = rootdir_devices; *curdev; curdev++)
|
||||
+ grub_util_pull_device (*curdev);
|
||||
+
|
||||
+ rootdir_grub_devname = grub_util_get_grub_dev (rootdir_devices[0]);
|
||||
+ if (!rootdir_grub_devname)
|
||||
+ grub_util_error (_("cannot find a GRUB drive for %s. Check your device.map"),
|
||||
+ rootdir_devices[0]);
|
||||
+
|
||||
+ rootdir_grub_dev = grub_device_open (rootdir_grub_devname);
|
||||
+ if (! rootdir_grub_dev)
|
||||
+ grub_util_error ("%s", grub_errmsg);
|
||||
+
|
||||
+ root_fs = grub_fs_probe (rootdir_grub_dev);
|
||||
+ if (!root_fs)
|
||||
+ grub_util_error ("%s", grub_errmsg);
|
||||
+
|
||||
+ if (config.is_suse_btrfs_snapshot_enabled
|
||||
+ && grub_strncmp(root_fs->name, "btrfs", sizeof ("btrfs") - 1) == 0)
|
||||
+ use_relative_path_on_btrfs = 1;
|
||||
+
|
||||
+ free (t);
|
||||
+ free (rootdir_grub_devname);
|
||||
+ grub_device_close (rootdir_grub_dev);
|
||||
+ }
|
||||
+
|
||||
switch (platform)
|
||||
{
|
||||
case GRUB_INSTALL_PLATFORM_I386_EFI:
|
||||
@@ -1478,8 +1517,7 @@
|
||||
debug_image);
|
||||
}
|
||||
|
||||
- if (config.is_suse_btrfs_snapshot_enabled
|
||||
- && grub_strncmp(grub_fs->name, "btrfs", sizeof ("btrfs") - 1) == 0)
|
||||
+ if (use_relative_path_on_btrfs)
|
||||
{
|
||||
if (!load_cfg_f)
|
||||
load_cfg_f = grub_util_fopen (load_cfg, "wb");
|
||||
@@ -1670,21 +1708,13 @@
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
- if (config.is_suse_btrfs_snapshot_enabled
|
||||
- && grub_strncmp(grub_fs->name, "btrfs", sizeof ("btrfs") - 1) == 0)
|
||||
+ if (use_relative_path_on_btrfs)
|
||||
{
|
||||
char *subvol = NULL;
|
||||
char *mount_path = NULL;
|
||||
- char **rootdir_devices = NULL;
|
||||
- char *t = grub_util_path_concat (2, "/", rootdir);
|
||||
- char *rootdir_path = grub_canonicalize_file_name (t);
|
||||
-
|
||||
- if (rootdir_path && grub_util_is_directory (rootdir_path))
|
||||
- rootdir_devices = grub_guess_root_devices (rootdir_path);
|
||||
-
|
||||
- if (rootdir_devices && rootdir_devices[0])
|
||||
- if (grub_strcmp (rootdir_devices[0], grub_devices[0]) == 0)
|
||||
- subvol = grub_util_get_btrfs_subvol (platdir, &mount_path);
|
||||
+
|
||||
+ if (grub_strcmp (rootdir_devices[0], grub_devices[0]) == 0)
|
||||
+ subvol = grub_util_get_btrfs_subvol (platdir, &mount_path);
|
||||
|
||||
if (subvol && mount_path)
|
||||
{
|
||||
@@ -1709,11 +1739,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
- free (t);
|
||||
- free (rootdir_path);
|
||||
- for (curdev = rootdir_devices; *curdev; curdev++)
|
||||
- free (*curdev);
|
||||
- free (rootdir_devices);
|
||||
free (subvol);
|
||||
free (mount_path);
|
||||
}
|
||||
--- a/util/grub-mkconfig_lib.in
|
||||
+++ b/util/grub-mkconfig_lib.in
|
||||
@@ -49,7 +49,8 @@
|
||||
|
||||
make_system_path_relative_to_its_root ()
|
||||
{
|
||||
- if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] ; then
|
||||
+ if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ] &&
|
||||
+ [ "x${GRUB_FS}" = "xbtrfs" ] ; then
|
||||
"${grub_mkrelpath}" -r "$1"
|
||||
else
|
||||
"${grub_mkrelpath}" "$1"
|
||||
289
0001-Workaround-volatile-efi-boot-variable.patch
Normal file
289
0001-Workaround-volatile-efi-boot-variable.patch
Normal file
@ -0,0 +1,289 @@
|
||||
From 71575829c303fe8522b46fc96b1f99f1aa4178e7 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Fri, 19 Mar 2021 22:58:45 +0800
|
||||
Subject: [PATCH] Workaround volatile efi boot variable
|
||||
|
||||
The efi variable in Microsoft Azure virtual machine is volatile that it cannot
|
||||
persist across power cycling. If we use efi variable to communicate with efi
|
||||
boot manager for booting a distribution, the process would silently fail as the
|
||||
default loader in the efi system partition will start to take over the process
|
||||
whenever the efi variable evaporated.
|
||||
|
||||
That will lead to undefined symbol error one day as the default path didn't
|
||||
receive any grub update so it cannot keep up with new ABI requirement by
|
||||
updated grub modules.
|
||||
|
||||
The patch will try to workaround the problem by providing grub update to the
|
||||
default path along with the distribution specific one. To avoid negative side
|
||||
effects of inadvertently overwritting other loader intended in default path,
|
||||
care must be taken to ensure that:
|
||||
|
||||
1. The workaround only takes place on detected Azure virtual machine
|
||||
2. The default path is not in use by shim for the secure boot
|
||||
---
|
||||
Makefile.util.def | 1 +
|
||||
.../osdep/basic/efi_removable_fallback.c | 26 +++
|
||||
grub-core/osdep/efi_removable_fallback.c | 5 +
|
||||
.../osdep/linux/efi_removable_fallback.c | 151 ++++++++++++++++++
|
||||
include/grub/util/install.h | 3 +
|
||||
util/grub-install.c | 19 +++
|
||||
6 files changed, 205 insertions(+)
|
||||
create mode 100644 grub-core/osdep/basic/efi_removable_fallback.c
|
||||
create mode 100644 grub-core/osdep/efi_removable_fallback.c
|
||||
create mode 100644 grub-core/osdep/linux/efi_removable_fallback.c
|
||||
|
||||
--- a/Makefile.util.def
|
||||
+++ b/Makefile.util.def
|
||||
@@ -681,6 +681,9 @@
|
||||
common = grub-core/osdep/journaled_fs.c;
|
||||
extra_dist = grub-core/osdep/basic/journaled_fs.c;
|
||||
extra_dist = grub-core/osdep/linux/journaled_fs.c;
|
||||
+ common = grub-core/osdep/efi_removable_fallback.c;
|
||||
+ extra_dist = grub-core/osdep/basic/efi_removable_fallback.c;
|
||||
+ extra_dist = grub-core/osdep/linux/efi_removable_fallback.c;
|
||||
|
||||
ldadd = '$(LIBLZMA)';
|
||||
ldadd = libgrubmods.a;
|
||||
--- /dev/null
|
||||
+++ b/grub-core/osdep/basic/efi_removable_fallback.c
|
||||
@@ -0,0 +1,26 @@
|
||||
+/*
|
||||
+ * GRUB -- GRand Unified Bootloader
|
||||
+ * Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
+ *
|
||||
+ * GRUB 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 3 of the License, or
|
||||
+ * (at your option) any later version.
|
||||
+ *
|
||||
+ * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
+ */
|
||||
+
|
||||
+#include <grub/util/install.h>
|
||||
+
|
||||
+const char *
|
||||
+grub_install_efi_removable_fallback (const char *efidir, enum grub_install_plat platform)
|
||||
+{
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
--- /dev/null
|
||||
+++ b/grub-core/osdep/efi_removable_fallback.c
|
||||
@@ -0,0 +1,5 @@
|
||||
+#ifdef __linux__
|
||||
+#include "linux/efi_removable_fallback.c"
|
||||
+#else
|
||||
+#include "basic/efi_removable_fallback.c"
|
||||
+#endif
|
||||
--- /dev/null
|
||||
+++ b/grub-core/osdep/linux/efi_removable_fallback.c
|
||||
@@ -0,0 +1,151 @@
|
||||
+/*
|
||||
+ * GRUB -- GRand Unified Bootloader
|
||||
+ * Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
+ *
|
||||
+ * GRUB 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 3 of the License, or
|
||||
+ * (at your option) any later version.
|
||||
+ *
|
||||
+ * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
+ */
|
||||
+
|
||||
+#include <config.h>
|
||||
+
|
||||
+#include <grub/util/install.h>
|
||||
+#include <grub/emu/exec.h>
|
||||
+#include <grub/emu/misc.h>
|
||||
+#include <string.h>
|
||||
+
|
||||
+static char *
|
||||
+get_dmi_id (const char *id)
|
||||
+{
|
||||
+ FILE *fp;
|
||||
+ char *buf = NULL;
|
||||
+ size_t len = 0;
|
||||
+
|
||||
+ char *dmi_entry;
|
||||
+
|
||||
+ dmi_entry = grub_util_path_concat (2, "/sys/class/dmi/id", id);
|
||||
+
|
||||
+ fp = grub_util_fopen (dmi_entry, "r");
|
||||
+ if (!fp)
|
||||
+ {
|
||||
+ free (dmi_entry);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ if (getline (&buf, &len, fp) == -1)
|
||||
+ {
|
||||
+ fclose (fp);
|
||||
+ free (dmi_entry);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ fclose (fp);
|
||||
+ free (dmi_entry);
|
||||
+ return buf;
|
||||
+}
|
||||
+
|
||||
+
|
||||
+static struct dmi {
|
||||
+ const char *id;
|
||||
+ const char *val;
|
||||
+} azure_dmi [3] = {
|
||||
+ {"bios_vendor", "Microsoft Corporation"},
|
||||
+ {"product_name", "Virtual Machine"},
|
||||
+ {"sys_vendor", "Microsoft Corporation"},
|
||||
+};
|
||||
+
|
||||
+static int
|
||||
+is_azure (void)
|
||||
+{
|
||||
+ int i;
|
||||
+ int n = sizeof (azure_dmi) / sizeof (struct dmi);
|
||||
+
|
||||
+ for (i = 0; i < n; ++i)
|
||||
+ {
|
||||
+ char *val;
|
||||
+
|
||||
+ val = get_dmi_id (azure_dmi[i].id);
|
||||
+ if (!val)
|
||||
+ break;
|
||||
+ if (strncmp (val, azure_dmi[i].val, strlen (azure_dmi[i].val)) != 0)
|
||||
+ {
|
||||
+ free (val);
|
||||
+ break;
|
||||
+ }
|
||||
+ free (val);
|
||||
+ }
|
||||
+
|
||||
+ return (i == n) ? 1 : 0;
|
||||
+}
|
||||
+
|
||||
+static int
|
||||
+guess_shim_installed (const char *instdir)
|
||||
+{
|
||||
+ const char *shim[] = {"fallback.efi", "MokManager.efi", NULL};
|
||||
+ const char **s;
|
||||
+
|
||||
+ for (s = shim; *s ; ++s)
|
||||
+ {
|
||||
+ char *p = grub_util_path_concat (2, instdir, *s);
|
||||
+
|
||||
+ if (access (p, F_OK) == 0)
|
||||
+ {
|
||||
+ free (p);
|
||||
+ return 1;
|
||||
+ }
|
||||
+ free (p);
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+const char *
|
||||
+grub_install_efi_removable_fallback (const char *efidir, enum grub_install_plat platform)
|
||||
+{
|
||||
+ char *instdir;
|
||||
+
|
||||
+ if (!is_azure ())
|
||||
+ return NULL;
|
||||
+
|
||||
+ instdir = grub_util_path_concat (3, efidir, "EFI", "BOOT");
|
||||
+
|
||||
+ if (guess_shim_installed (instdir))
|
||||
+ {
|
||||
+ grub_util_info ("skip removable fallback occupied by shim");
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ free (instdir);
|
||||
+
|
||||
+ switch (platform)
|
||||
+ {
|
||||
+ case GRUB_INSTALL_PLATFORM_I386_EFI:
|
||||
+ return "BOOTIA32.EFI";
|
||||
+ case GRUB_INSTALL_PLATFORM_X86_64_EFI:
|
||||
+ return "BOOTX64.EFI";
|
||||
+ case GRUB_INSTALL_PLATFORM_IA64_EFI:
|
||||
+ return "BOOTIA64.EFI";
|
||||
+ case GRUB_INSTALL_PLATFORM_ARM_EFI:
|
||||
+ return "BOOTARM.EFI";
|
||||
+ case GRUB_INSTALL_PLATFORM_ARM64_EFI:
|
||||
+ return "BOOTAA64.EFI";
|
||||
+ case GRUB_INSTALL_PLATFORM_RISCV32_EFI:
|
||||
+ return "BOOTRISCV32.EFI";
|
||||
+ case GRUB_INSTALL_PLATFORM_RISCV64_EFI:
|
||||
+ return "BOOTRISCV64.EFI";
|
||||
+ default:
|
||||
+ grub_util_error ("%s", _("You've found a bug"));
|
||||
+ break;
|
||||
+ }
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
--- a/include/grub/util/install.h
|
||||
+++ b/include/grub/util/install.h
|
||||
@@ -303,4 +303,7 @@
|
||||
|
||||
int
|
||||
grub_install_sync_fs_journal (const char *path);
|
||||
+
|
||||
+const char *
|
||||
+grub_install_efi_removable_fallback (const char *efidir, enum grub_install_plat platform);
|
||||
#endif
|
||||
--- a/util/grub-install.c
|
||||
+++ b/util/grub-install.c
|
||||
@@ -901,6 +901,7 @@
|
||||
const char *pkgdatadir;
|
||||
char *rootdir_path;
|
||||
char **rootdir_devices;
|
||||
+ char *efidir_root;
|
||||
|
||||
grub_util_host_init (&argc, &argv);
|
||||
product_version = xstrdup (PACKAGE_VERSION);
|
||||
@@ -1175,6 +1176,7 @@
|
||||
}
|
||||
if (!efidir)
|
||||
grub_util_error ("%s", _("cannot find EFI directory"));
|
||||
+ efidir_root = grub_strdup (efidir);
|
||||
efidir_device_names = grub_guess_root_devices (efidir);
|
||||
if (!efidir_device_names || !efidir_device_names[0])
|
||||
grub_util_error (_("cannot find a device for %s (is /dev mounted?)"),
|
||||
@@ -2217,6 +2219,23 @@
|
||||
free (grub_efi_cfg);
|
||||
}
|
||||
}
|
||||
+ if (!removable)
|
||||
+ {
|
||||
+ const char *f;
|
||||
+
|
||||
+ f = grub_install_efi_removable_fallback (efidir_root, platform);
|
||||
+ if (f)
|
||||
+ {
|
||||
+ char *t = grub_util_path_concat (3, efidir_root, "EFI", "BOOT");
|
||||
+ char *dst = grub_util_path_concat (2, t, f);
|
||||
+
|
||||
+ grub_install_mkdir_p (t);
|
||||
+ fprintf (stderr, _("Install to %s as fallback.\n"), dst);
|
||||
+ grub_install_copy_file (imgfile, dst, 1);
|
||||
+ grub_free (t);
|
||||
+ grub_free (dst);
|
||||
+ }
|
||||
+ }
|
||||
if (!removable && update_nvram)
|
||||
{
|
||||
char * efifile_path;
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From 10d0f70ac194931c63f2cbd6fdebd6697abae992 Mon Sep 17 00:00:00 2001
|
||||
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
|
||||
Date: Mon, 2 Aug 2021 23:10:01 +1000
|
||||
Subject: [PATCH] arm64: Fix EFI loader kernel image allocation
|
||||
Subject: [PATCH 1/2] arm64: Fix EFI loader kernel image allocation
|
||||
|
||||
We are currently allocating just enough memory for the file size,
|
||||
which means that the kernel BSS is in limbo (and not even zeroed).
|
||||
@ -14,20 +14,15 @@ actual size it needs, including BSS, and make sure we clear it, and
|
||||
honors the specified alignment for the image.
|
||||
|
||||
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
|
||||
[pjones: arm: check for the PE magic for the compiled arch]
|
||||
Signed-off-by: Peter Jones <pjones@redhat.com>
|
||||
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
|
||||
---
|
||||
grub-core/loader/arm64/linux.c | 100 +++++++++++++++++++++++++++--------------
|
||||
include/grub/arm/linux.h | 1 +
|
||||
include/grub/arm64/linux.h | 1 +
|
||||
3 files changed, 68 insertions(+), 34 deletions(-)
|
||||
grub-core/loader/arm64/efi/linux.c | 92 ++++++++++++++++++++----------
|
||||
1 file changed, 63 insertions(+), 29 deletions(-)
|
||||
|
||||
diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
|
||||
index 47f8cf0d84b..f18d90bd749 100644
|
||||
--- a/grub-core/loader/arm64/linux.c
|
||||
+++ b/grub-core/loader/arm64/linux.c
|
||||
@@ -41,6 +41,8 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
||||
diff --git a/grub-core/loader/arm64/efi/linux.c b/grub-core/loader/arm64/efi/linux.c
|
||||
index b73105347..4da49a182 100644
|
||||
--- a/grub-core/loader/arm64/efi/linux.c
|
||||
+++ b/grub-core/loader/arm64/efi/linux.c
|
||||
@@ -39,6 +39,8 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
||||
static grub_dl_t my_mod;
|
||||
static int loaded;
|
||||
|
||||
@ -36,7 +31,7 @@ index 47f8cf0d84b..f18d90bd749 100644
|
||||
static void *kernel_addr;
|
||||
static grub_uint64_t kernel_size;
|
||||
static grub_uint32_t handover_offset;
|
||||
@@ -204,9 +206,8 @@ grub_linux_unload (void)
|
||||
@@ -258,9 +260,8 @@ grub_linux_unload (void)
|
||||
GRUB_EFI_BYTES_TO_PAGES (initrd_end - initrd_start));
|
||||
initrd_start = initrd_end = 0;
|
||||
grub_free (linux_args);
|
||||
@ -48,7 +43,7 @@ index 47f8cf0d84b..f18d90bd749 100644
|
||||
grub_fdt_unload ();
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
@@ -311,14 +312,35 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -365,14 +366,35 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
@ -62,7 +57,7 @@ index 47f8cf0d84b..f18d90bd749 100644
|
||||
+
|
||||
+ pe = (void *)((unsigned long)kernel + lh->hdr_offset);
|
||||
+
|
||||
+ if (pe->opt.magic != GRUB_PE32_PEXX_MAGIC)
|
||||
+ if (pe->opt.magic != GRUB_PE32_PE64_MAGIC)
|
||||
+ return grub_error(GRUB_ERR_BAD_OS, "Invalid PE optional header magic");
|
||||
+
|
||||
+ *total_size = pe->opt.image_size;
|
||||
@ -81,87 +76,74 @@ index 47f8cf0d84b..f18d90bd749 100644
|
||||
- struct grub_armxx_linux_pe_header *pe;
|
||||
grub_err_t err;
|
||||
+ grub_off_t filelen;
|
||||
+ grub_uint32_t align;
|
||||
+ grub_uint32_t align = 0;
|
||||
+ void *kernel = NULL;
|
||||
int rc;
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
@@ -333,40 +355,24 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
@@ -386,39 +408,49 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (!file)
|
||||
goto fail;
|
||||
|
||||
- kernel_size = grub_file_size (file);
|
||||
-
|
||||
+ filelen = grub_file_size (file);
|
||||
+ kernel = grub_malloc(filelen);
|
||||
+ if (!kernel)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel load buffer"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
|
||||
- if (grub_file_read (file, &lh, sizeof (lh)) < (long) sizeof (lh))
|
||||
- return grub_errno;
|
||||
-
|
||||
+ if (grub_file_read (file, kernel, filelen) < (grub_ssize_t)filelen)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_FILE_READ_ERROR, N_("Can't read kernel %s"),
|
||||
+ argv[0]);
|
||||
+ goto fail;
|
||||
+ }
|
||||
|
||||
- if (grub_arch_efi_linux_check_image (&lh) != GRUB_ERR_NONE)
|
||||
- goto fail;
|
||||
-
|
||||
- grub_loader_unset();
|
||||
-
|
||||
+ grub_dprintf ("linux", "kernel @ %p\n", kernel_addr);
|
||||
+
|
||||
+ if (grub_arch_efi_linux_check_image (kernel) != GRUB_ERR_NONE)
|
||||
+ goto fail;
|
||||
+ if (parse_pe_header (kernel, &kernel_size, &handover_offset, &align) != GRUB_ERR_NONE)
|
||||
goto fail;
|
||||
+ grub_dprintf ("linux", "kernel mem size : %lld\n", (long long) kernel_size);
|
||||
+ grub_dprintf ("linux", "kernel entry offset : %d\n", handover_offset);
|
||||
+ grub_dprintf ("linux", "kernel alignment : 0x%x\n", align);
|
||||
|
||||
grub_loader_unset();
|
||||
|
||||
- grub_dprintf ("linux", "kernel file size: %lld\n", (long long) kernel_size);
|
||||
- kernel_addr = grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (kernel_size));
|
||||
- grub_dprintf ("linux", "kernel numpages: %lld\n",
|
||||
- (long long) GRUB_EFI_BYTES_TO_PAGES (kernel_size));
|
||||
- if (!kernel_addr)
|
||||
+ filelen = grub_file_size (file);
|
||||
+ kernel = grub_malloc(filelen);
|
||||
+ if (!kernel)
|
||||
{
|
||||
- grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
||||
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel load buffer"));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
- grub_file_seek (file, 0);
|
||||
- if (grub_file_read (file, kernel_addr, kernel_size)
|
||||
- < (grub_int64_t) kernel_size)
|
||||
+ if (grub_file_read (file, kernel, filelen) < (grub_ssize_t)filelen)
|
||||
{
|
||||
- if (!grub_errno)
|
||||
- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), argv[0]);
|
||||
+ grub_error (GRUB_ERR_FILE_READ_ERROR, N_("Can't read kernel %s"),
|
||||
+ argv[0]);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
- grub_dprintf ("linux", "kernel @ %p\n", kernel_addr);
|
||||
-
|
||||
if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
{
|
||||
- rc = grub_linuxefi_secure_validate (kernel_addr, kernel_size);
|
||||
+ rc = grub_linuxefi_secure_validate (kernel, filelen);
|
||||
if (rc <= 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_INVALID_COMMAND,
|
||||
@@ -375,8 +381,32 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
}
|
||||
}
|
||||
|
||||
- pe = (void *)((unsigned long)kernel_addr + lh.hdr_offset);
|
||||
- handover_offset = pe->opt.entry_addr;
|
||||
+ if (grub_arch_efi_linux_check_image (kernel) != GRUB_ERR_NONE)
|
||||
+ goto fail;
|
||||
+ if (parse_pe_header (kernel, &kernel_size, &handover_offset, &align) != GRUB_ERR_NONE)
|
||||
+ goto fail;
|
||||
+ grub_dprintf ("linux", "kernel mem size : %lld\n", (long long) kernel_size);
|
||||
+ grub_dprintf ("linux", "kernel entry offset : %d\n", handover_offset);
|
||||
+ grub_dprintf ("linux", "kernel alignment : 0x%x\n", align);
|
||||
+
|
||||
+ grub_loader_unset();
|
||||
+
|
||||
+ kernel_alloc_pages = GRUB_EFI_BYTES_TO_PAGES (kernel_size + align - 1);
|
||||
+ kernel_alloc_addr = grub_efi_allocate_any_pages (kernel_alloc_pages);
|
||||
+ grub_dprintf ("linux", "kernel numpages: %d\n", kernel_alloc_pages);
|
||||
+ if (!kernel_alloc_addr)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
||||
goto fail;
|
||||
}
|
||||
-
|
||||
- grub_file_seek (file, 0);
|
||||
- if (grub_file_read (file, kernel_addr, kernel_size)
|
||||
- < (grub_int64_t) kernel_size)
|
||||
- {
|
||||
- if (!grub_errno)
|
||||
- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), argv[0]);
|
||||
- goto fail;
|
||||
- }
|
||||
+ kernel_addr = (void *)ALIGN_UP((grub_uint64_t)kernel_alloc_addr, align);
|
||||
+
|
||||
+ grub_dprintf ("linux", "kernel @ %p\n", kernel_addr);
|
||||
|
||||
grub_dprintf ("linux", "kernel @ %p\n", kernel_addr);
|
||||
-
|
||||
- pe = (void *)((unsigned long)kernel_addr + lh.hdr_offset);
|
||||
- handover_offset = pe->opt.entry_addr;
|
||||
+ grub_memcpy (kernel_addr, kernel, grub_min(filelen, kernel_size));
|
||||
+ if (kernel_size > filelen)
|
||||
+ grub_memset ((char *)kernel_addr + filelen, 0, kernel_size - filelen);
|
||||
@ -170,7 +152,7 @@ index 47f8cf0d84b..f18d90bd749 100644
|
||||
|
||||
cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE);
|
||||
linux_args = grub_malloc (cmdline_size);
|
||||
@@ -400,6 +430,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -442,6 +474,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
}
|
||||
|
||||
fail:
|
||||
@ -180,7 +162,7 @@ index 47f8cf0d84b..f18d90bd749 100644
|
||||
if (file)
|
||||
grub_file_close (file);
|
||||
|
||||
@@ -412,9 +445,8 @@ fail:
|
||||
@@ -454,9 +489,8 @@ fail:
|
||||
if (linux_args && !loaded)
|
||||
grub_free (linux_args);
|
||||
|
||||
@ -192,27 +174,6 @@ index 47f8cf0d84b..f18d90bd749 100644
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h
|
||||
index b582f67f661..966a5074f53 100644
|
||||
--- a/include/grub/arm/linux.h
|
||||
+++ b/include/grub/arm/linux.h
|
||||
@@ -44,6 +44,7 @@ struct grub_arm_linux_pe_header
|
||||
--
|
||||
2.31.1
|
||||
|
||||
#if defined(__arm__)
|
||||
# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE
|
||||
+# define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE32_MAGIC
|
||||
# define linux_arch_kernel_header linux_arm_kernel_header
|
||||
# define grub_armxx_linux_pe_header grub_arm_linux_pe_header
|
||||
#endif
|
||||
diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h
|
||||
index ea030312df3..422bf2bf24b 100644
|
||||
--- a/include/grub/arm64/linux.h
|
||||
+++ b/include/grub/arm64/linux.h
|
||||
@@ -48,6 +48,7 @@ struct grub_arm64_linux_pe_header
|
||||
|
||||
#if defined(__aarch64__)
|
||||
# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE
|
||||
+# define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE64_MAGIC
|
||||
# define linux_arch_kernel_header linux_arm64_kernel_header
|
||||
# define grub_armxx_linux_pe_header grub_arm64_linux_pe_header
|
||||
#endif
|
||||
205
0001-clean-up-crypttab-and-linux-modules-dependency.patch
Normal file
205
0001-clean-up-crypttab-and-linux-modules-dependency.patch
Normal file
@ -0,0 +1,205 @@
|
||||
From e9422d6869f1b2d78a7cfbfcae1610953d87705b Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Thu, 16 Feb 2023 21:28:07 +0800
|
||||
Subject: [PATCH 1/2] clean up crypttab and linux modules dependency
|
||||
|
||||
The linux module could have quite a few dependency to other modules, the
|
||||
i386-pc build in particular has many.
|
||||
|
||||
linux: normal vbe video boot cmdline relocator mmap
|
||||
|
||||
That will be easy to cause loop dependency if one of these modules has
|
||||
to require function from linux. To avoid falling into the pitfall in
|
||||
future extension, we move away the key publish related function from
|
||||
linux to crypttab module in that it is also a right thing to do.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/commands/crypttab.c | 48 +++++++++++++++++++++++++++++-
|
||||
grub-core/disk/cryptodisk.c | 2 +-
|
||||
grub-core/loader/linux.c | 55 +----------------------------------
|
||||
include/grub/crypttab.h | 22 ++++++++++++++
|
||||
include/grub/linux.h | 3 --
|
||||
5 files changed, 71 insertions(+), 59 deletions(-)
|
||||
create mode 100644 include/grub/crypttab.h
|
||||
|
||||
--- a/grub-core/commands/crypttab.c
|
||||
+++ b/grub-core/commands/crypttab.c
|
||||
@@ -3,10 +3,56 @@
|
||||
#include <grub/command.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/i18n.h>
|
||||
-#include <grub/linux.h>
|
||||
+#include <grub/mm.h>
|
||||
+#include <grub/list.h>
|
||||
+#include <grub/crypttab.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
+struct grub_key_publisher *kpuber;
|
||||
+
|
||||
+grub_err_t
|
||||
+grub_initrd_publish_key (const char *uuid, const char *key, grub_size_t key_len, const char *path)
|
||||
+{
|
||||
+ struct grub_key_publisher *cur = NULL;
|
||||
+
|
||||
+ FOR_LIST_ELEMENTS (cur, kpuber)
|
||||
+ if (grub_uuidcasecmp (cur->name, uuid, sizeof (cur->name)) == 0)
|
||||
+ break;
|
||||
+
|
||||
+ if (!cur)
|
||||
+ cur = grub_zalloc (sizeof (*cur));
|
||||
+ if (!cur)
|
||||
+ return grub_errno;
|
||||
+
|
||||
+ if (key && key_len)
|
||||
+ {
|
||||
+ grub_free (cur->key);
|
||||
+ cur->key = grub_malloc (key_len);
|
||||
+ if (!cur->key)
|
||||
+ {
|
||||
+ grub_free (cur);
|
||||
+ return grub_errno;
|
||||
+ }
|
||||
+ grub_memcpy (cur->key, key, key_len);
|
||||
+ cur->key_len = key_len;
|
||||
+ }
|
||||
+
|
||||
+ if (path)
|
||||
+ {
|
||||
+ grub_free (cur->path);
|
||||
+ cur->path = grub_strdup (path);
|
||||
+ }
|
||||
+
|
||||
+ if (!cur->name)
|
||||
+ {
|
||||
+ cur->name = grub_strdup (uuid);
|
||||
+ grub_list_push (GRUB_AS_LIST_P (&kpuber), GRUB_AS_LIST (cur));
|
||||
+ }
|
||||
+
|
||||
+ return GRUB_ERR_NONE;
|
||||
+}
|
||||
+
|
||||
static grub_err_t
|
||||
grub_cmd_crypttab_entry (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char **argv)
|
||||
--- a/grub-core/disk/cryptodisk.c
|
||||
+++ b/grub-core/disk/cryptodisk.c
|
||||
@@ -31,7 +31,7 @@
|
||||
#ifdef GRUB_UTIL
|
||||
#include <grub/emu/hostdisk.h>
|
||||
#else
|
||||
-#include <grub/linux.h>
|
||||
+#include <grub/crypttab.h>
|
||||
#endif
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
--- a/grub-core/loader/linux.c
|
||||
+++ b/grub-core/loader/linux.c
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <grub/mm.h>
|
||||
#include <grub/safemath.h>
|
||||
#include <grub/list.h>
|
||||
+#include <grub/crypttab.h>
|
||||
|
||||
struct newc_head
|
||||
{
|
||||
@@ -40,18 +41,6 @@
|
||||
struct dir *child;
|
||||
};
|
||||
|
||||
-struct grub_key_publisher
|
||||
-{
|
||||
- struct grub_key_publisher *next;
|
||||
- struct grub_key_publisher **prev;
|
||||
- char *name; /* UUID */
|
||||
- char *path;
|
||||
- char *key;
|
||||
- grub_size_t key_len;
|
||||
-};
|
||||
-
|
||||
-static struct grub_key_publisher *kpuber;
|
||||
-
|
||||
static char
|
||||
hex (grub_uint8_t val)
|
||||
{
|
||||
@@ -436,45 +425,3 @@
|
||||
root = 0;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
-
|
||||
-grub_err_t
|
||||
-grub_initrd_publish_key (const char *uuid, const char *key, grub_size_t key_len, const char *path)
|
||||
-{
|
||||
- struct grub_key_publisher *cur = NULL;
|
||||
-
|
||||
- FOR_LIST_ELEMENTS (cur, kpuber)
|
||||
- if (grub_uuidcasecmp (cur->name, uuid, sizeof (cur->name)) == 0)
|
||||
- break;
|
||||
-
|
||||
- if (!cur)
|
||||
- cur = grub_zalloc (sizeof (*cur));
|
||||
- if (!cur)
|
||||
- return grub_errno;
|
||||
-
|
||||
- if (key && key_len)
|
||||
- {
|
||||
- grub_free (cur->key);
|
||||
- cur->key = grub_malloc (key_len);
|
||||
- if (!cur->key)
|
||||
- {
|
||||
- grub_free (cur);
|
||||
- return grub_errno;
|
||||
- }
|
||||
- grub_memcpy (cur->key, key, key_len);
|
||||
- cur->key_len = key_len;
|
||||
- }
|
||||
-
|
||||
- if (path)
|
||||
- {
|
||||
- grub_free (cur->path);
|
||||
- cur->path = grub_strdup (path);
|
||||
- }
|
||||
-
|
||||
- if (!cur->name)
|
||||
- {
|
||||
- cur->name = grub_strdup (uuid);
|
||||
- grub_list_push (GRUB_AS_LIST_P (&kpuber), GRUB_AS_LIST (cur));
|
||||
- }
|
||||
-
|
||||
- return GRUB_ERR_NONE;
|
||||
-}
|
||||
--- /dev/null
|
||||
+++ b/include/grub/crypttab.h
|
||||
@@ -0,0 +1,22 @@
|
||||
+#ifndef GRUB_CRYPTTAB_HEADER
|
||||
+#define GRUB_CRYPTTAB_HEADER 1
|
||||
+
|
||||
+#include <grub/types.h>
|
||||
+#include <grub/err.h>
|
||||
+
|
||||
+struct grub_key_publisher
|
||||
+{
|
||||
+ struct grub_key_publisher *next;
|
||||
+ struct grub_key_publisher **prev;
|
||||
+ char *name; /* UUID */
|
||||
+ char *path;
|
||||
+ char *key;
|
||||
+ grub_size_t key_len;
|
||||
+};
|
||||
+
|
||||
+extern struct grub_key_publisher *EXPORT_VAR (kpuber);
|
||||
+
|
||||
+grub_err_t
|
||||
+grub_initrd_publish_key (const char *uuid, const char *key, grub_size_t key_len, const char *path);
|
||||
+
|
||||
+#endif /* ! GRUB_CRYPTTAB_HEADER */
|
||||
--- a/include/grub/linux.h
|
||||
+++ b/include/grub/linux.h
|
||||
@@ -22,6 +22,3 @@
|
||||
grub_err_t
|
||||
grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
|
||||
void *target);
|
||||
-
|
||||
-grub_err_t
|
||||
-grub_initrd_publish_key (const char *uuid, const char *key, grub_size_t key_len, const char *path);
|
||||
@ -0,0 +1,37 @@
|
||||
From 5846e14a4dbf0c73969a32625d841e4f842ccdea Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Wed, 31 Jan 2024 18:44:27 +0800
|
||||
Subject: [PATCH] disk: Optimize disk iteration by moving memdisk to the end
|
||||
|
||||
When performing file or UUID-based searches, prioritize returning
|
||||
operating system disk devices over the memdisk. The memdisk, typically
|
||||
used for internal grub data, is moved to the last position in the search
|
||||
order. This improves search efficiency and prevents potential unexpected
|
||||
results.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
include/grub/disk.h | 7 ++++++-
|
||||
1 file changed, 6 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/include/grub/disk.h b/include/grub/disk.h
|
||||
index bf0958885..f4fd7a00f 100644
|
||||
--- a/include/grub/disk.h
|
||||
+++ b/include/grub/disk.h
|
||||
@@ -244,7 +244,12 @@ grub_disk_dev_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data)
|
||||
|
||||
for (pull = 0; pull < GRUB_DISK_PULL_MAX; pull++)
|
||||
for (p = grub_disk_dev_list; p; p = p->next)
|
||||
- if (p->disk_iterate && (p->disk_iterate) (hook, hook_data, pull))
|
||||
+ if (p->id != GRUB_DISK_DEVICE_MEMDISK_ID && p->disk_iterate && (p->disk_iterate) (hook, hook_data, pull))
|
||||
+ return 1;
|
||||
+
|
||||
+ for (pull = 0; pull < GRUB_DISK_PULL_MAX; pull++)
|
||||
+ for (p = grub_disk_dev_list; p; p = p->next)
|
||||
+ if (p->id == GRUB_DISK_DEVICE_MEMDISK_ID && p->disk_iterate && (p->disk_iterate) (hook, hook_data, pull))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
--
|
||||
2.43.0
|
||||
|
||||
103
0001-efi-linux-provide-linux-command.patch
Normal file
103
0001-efi-linux-provide-linux-command.patch
Normal file
@ -0,0 +1,103 @@
|
||||
From 987ab0dfbe7ef42bb6386fb7b428d3b965ba6d2b Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Mon, 7 Sep 2020 17:02:57 +0800
|
||||
Subject: [PATCH] efi/linux: provide linux command
|
||||
|
||||
The linux kernel's efi handover entry point is used to boot efistub of
|
||||
the linux kernel. Since then the efistub has been improved with many new
|
||||
features and fixes that ordinary 32-bit entry point cannot provide.
|
||||
|
||||
Besides, nearly every x86 efi kernel is built with efistub enabled so it
|
||||
is of little value to keep 32-bit entry as default to boot kernel
|
||||
without needed kconfig options enabled.
|
||||
|
||||
For all good reasons, making efi handover the default entry point for
|
||||
booting kernel in x86 efi platform so that linux command works in the
|
||||
same way to linuxefi. This can also reduce the complexity of providing
|
||||
general grub configuation for x86 system due to the linux command may
|
||||
not be available in signed image for UEFI Secure Boot and linuxefi is
|
||||
not available for leagcy bios booting.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/Makefile.core.def | 6 ++++--
|
||||
grub-core/gensyminfo.sh.in | 3 +++
|
||||
grub-core/loader/i386/efi/linux.c | 17 +++++++++++++----
|
||||
3 files changed, 20 insertions(+), 6 deletions(-)
|
||||
|
||||
--- a/grub-core/Makefile.core.def
|
||||
+++ b/grub-core/Makefile.core.def
|
||||
@@ -1840,7 +1840,9 @@
|
||||
|
||||
module = {
|
||||
name = linux;
|
||||
- x86 = loader/i386/linux.c;
|
||||
+ i386_pc = loader/i386/linux.c;
|
||||
+ i386_efi = loader/i386/efi/linux.c;
|
||||
+ x86_64_efi = loader/i386/efi/linux.c;
|
||||
i386_xen_pvh = loader/i386/linux.c;
|
||||
xen = loader/i386/xen.c;
|
||||
i386_pc = lib/i386/pc/vesa_modes_table.c;
|
||||
@@ -1856,8 +1858,6 @@
|
||||
loongarch64 = loader/efi/linux.c;
|
||||
riscv32 = loader/efi/linux.c;
|
||||
riscv64 = loader/efi/linux.c;
|
||||
- i386_efi = loader/efi/linux.c;
|
||||
- x86_64_efi = loader/efi/linux.c;
|
||||
emu = loader/emu/linux.c;
|
||||
common = loader/linux.c;
|
||||
};
|
||||
@@ -1922,7 +1922,7 @@
|
||||
|
||||
module = {
|
||||
name = linuxefi;
|
||||
- efi = loader/i386/efi/linux.c;
|
||||
+ efi = lib/fake_module.c;
|
||||
enable = i386_efi;
|
||||
enable = x86_64_efi;
|
||||
};
|
||||
--- a/grub-core/gensyminfo.sh.in
|
||||
+++ b/grub-core/gensyminfo.sh.in
|
||||
@@ -35,3 +35,6 @@
|
||||
|
||||
# Print all undefined symbols used by module
|
||||
@TARGET_NM@ -u @TARGET_NMFLAGS_MINUS_P@ -p $module | sed "s@^\([^ ]*\).*@undefined $modname \1@g"
|
||||
+
|
||||
+# Specify linuxefi module should load default linux
|
||||
+test "$modname" = "linuxefi" && echo "undefined $modname grub_initrd_init" || true
|
||||
--- a/grub-core/loader/i386/efi/linux.c
|
||||
+++ b/grub-core/loader/i386/efi/linux.c
|
||||
@@ -333,20 +333,29 @@
|
||||
}
|
||||
|
||||
static grub_command_t cmd_linux, cmd_initrd;
|
||||
+static grub_command_t cmd_linuxefi, cmd_initrdefi;
|
||||
|
||||
-GRUB_MOD_INIT(linuxefi)
|
||||
+GRUB_MOD_INIT(linux)
|
||||
{
|
||||
- cmd_linux =
|
||||
+ cmd_linuxefi =
|
||||
grub_register_command ("linuxefi", grub_cmd_linux,
|
||||
0, N_("Load Linux."));
|
||||
- cmd_initrd =
|
||||
+ cmd_initrdefi =
|
||||
grub_register_command ("initrdefi", grub_cmd_initrd,
|
||||
0, N_("Load initrd."));
|
||||
+ cmd_linux =
|
||||
+ grub_register_command ("linux", grub_cmd_linux,
|
||||
+ 0, N_("Load Linux."));
|
||||
+ cmd_initrd =
|
||||
+ grub_register_command ("initrd", grub_cmd_initrd,
|
||||
+ 0, N_("Load initrd."));
|
||||
my_mod = mod;
|
||||
}
|
||||
|
||||
-GRUB_MOD_FINI(linuxefi)
|
||||
+GRUB_MOD_FINI(linux)
|
||||
{
|
||||
+ grub_unregister_command (cmd_linuxefi);
|
||||
+ grub_unregister_command (cmd_initrdefi);
|
||||
grub_unregister_command (cmd_linux);
|
||||
grub_unregister_command (cmd_initrd);
|
||||
}
|
||||
39
0001-font-Try-memdisk-fonts-with-the-same-name.patch
Normal file
39
0001-font-Try-memdisk-fonts-with-the-same-name.patch
Normal file
@ -0,0 +1,39 @@
|
||||
From d02304f70b5b9c79761d8084ab9dfc66d84688e2 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Wed, 30 Nov 2022 17:02:50 +0800
|
||||
Subject: [PATCH] font: Try memdisk fonts with the same name
|
||||
|
||||
---
|
||||
grub-core/font/font.c | 16 +++++++++++++++-
|
||||
1 file changed, 15 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/grub-core/font/font.c b/grub-core/font/font.c
|
||||
index 18de52562..92ff415bf 100644
|
||||
--- a/grub-core/font/font.c
|
||||
+++ b/grub-core/font/font.c
|
||||
@@ -451,7 +451,21 @@ grub_font_load (const char *filename)
|
||||
#endif
|
||||
|
||||
if (filename[0] == '(' || filename[0] == '/' || filename[0] == '+')
|
||||
- file = grub_buffile_open (filename, GRUB_FILE_TYPE_FONT, 1024);
|
||||
+ {
|
||||
+ char *n = grub_strdup (filename);
|
||||
+ char *p = grub_strrchr (n, '/');
|
||||
+ if (p)
|
||||
+ {
|
||||
+ char *q = grub_strrchr (p, '.');
|
||||
+ if (q)
|
||||
+ *q = 0;
|
||||
+ p++;
|
||||
+ file = try_open_from_prefix ("(memdisk)", p);
|
||||
+ }
|
||||
+ grub_free (n);
|
||||
+ if (!file)
|
||||
+ file = grub_buffile_open (filename, GRUB_FILE_TYPE_FONT, 1024);
|
||||
+ }
|
||||
else
|
||||
{
|
||||
file = try_open_from_prefix ("(memdisk)", filename);
|
||||
--
|
||||
2.41.0
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
From 045aae8fe7238aabc217700df4d17d83b7d891f3 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Tue, 23 Jan 2024 12:46:16 +0800
|
||||
Subject: [PATCH] fs/xfs: always verify the total number of entries is not zero
|
||||
|
||||
---
|
||||
grub-core/fs/xfs.c | 12 ++++++------
|
||||
1 file changed, 6 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c
|
||||
index bc2224dbb..1ce5fa4fc 100644
|
||||
--- a/grub-core/fs/xfs.c
|
||||
+++ b/grub-core/fs/xfs.c
|
||||
@@ -900,6 +900,8 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
|
||||
{
|
||||
struct grub_xfs_dir2_entry *direntry =
|
||||
grub_xfs_first_de(dir->data, dirblock);
|
||||
+ struct grub_xfs_dirblock_tail *tail = grub_xfs_dir_tail (dir->data, dirblock);
|
||||
+
|
||||
int entries = -1;
|
||||
char *end = dirblock + dirblk_size;
|
||||
|
||||
@@ -918,18 +920,16 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
|
||||
*/
|
||||
if (dir->inode.nextents == grub_cpu_to_be32_compile_time (1))
|
||||
{
|
||||
- struct grub_xfs_dirblock_tail *tail = grub_xfs_dir_tail (dir->data, dirblock);
|
||||
-
|
||||
end = (char *) tail;
|
||||
|
||||
/* Subtract the space used by leaf nodes. */
|
||||
end -= grub_be_to_cpu32 (tail->leaf_count) * sizeof (struct grub_xfs_dir_leaf_entry);
|
||||
+ }
|
||||
|
||||
- entries = grub_be_to_cpu32 (tail->leaf_count) - grub_be_to_cpu32 (tail->leaf_stale);
|
||||
+ entries = grub_be_to_cpu32 (tail->leaf_count) - grub_be_to_cpu32 (tail->leaf_stale);
|
||||
|
||||
- if (!entries)
|
||||
- continue;
|
||||
- }
|
||||
+ if (!entries)
|
||||
+ continue;
|
||||
|
||||
/* Iterate over all entries within this block. */
|
||||
while ((char *) direntry < (char *) end)
|
||||
--
|
||||
2.43.0
|
||||
|
||||
101
0001-grub-install-Add-SUSE-signed-image-support-for-power.patch
Normal file
101
0001-grub-install-Add-SUSE-signed-image-support-for-power.patch
Normal file
@ -0,0 +1,101 @@
|
||||
From 83a6f72e1896bd012b7fbca21317e96c2c22b327 Mon Sep 17 00:00:00 2001
|
||||
From: Michal Suchanek <msuchanek@suse.de>
|
||||
Date: Wed, 12 Jan 2022 19:25:54 +0100
|
||||
Subject: [PATCH] grub-install: Add SUSE signed image support for powerpc.
|
||||
|
||||
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
|
||||
---
|
||||
grub-core/osdep/linux/platform.c | 13 +++++++++++++
|
||||
include/grub/util/install.h | 3 +++
|
||||
util/grub-install.c | 29 ++++++++++++++++++++++++++---
|
||||
3 files changed, 42 insertions(+), 3 deletions(-)
|
||||
|
||||
--- a/grub-core/osdep/linux/platform.c
|
||||
+++ b/grub-core/osdep/linux/platform.c
|
||||
@@ -154,3 +154,16 @@
|
||||
grub_util_info ("... not found");
|
||||
return "i386-pc";
|
||||
}
|
||||
+
|
||||
+int
|
||||
+grub_install_get_powerpc_secure_boot (void)
|
||||
+{
|
||||
+ int32_t ret = -1;
|
||||
+ FILE *fp = grub_util_fopen ("/proc/device-tree/ibm,secure-boot", "rb");
|
||||
+ if (fp) {
|
||||
+ if (fread (&ret , 1, sizeof(ret), fp) > 0)
|
||||
+ ret = grub_be_to_cpu32(ret);
|
||||
+ fclose(fp);
|
||||
+ }
|
||||
+ return ret;
|
||||
+}
|
||||
--- a/include/grub/util/install.h
|
||||
+++ b/include/grub/util/install.h
|
||||
@@ -233,6 +233,9 @@
|
||||
grub_install_get_default_x86_platform (void);
|
||||
|
||||
int
|
||||
+grub_install_get_powerpc_secure_boot (void);
|
||||
+
|
||||
+int
|
||||
grub_install_register_efi (grub_device_t efidir_grub_dev,
|
||||
const char *efifile_path,
|
||||
const char *efi_distributor);
|
||||
--- a/util/grub-install.c
|
||||
+++ b/util/grub-install.c
|
||||
@@ -321,10 +321,10 @@
|
||||
{"suse-enable-tpm", OPTION_SUSE_ENABLE_TPM, 0, 0, N_("install TPM modules"), 0},
|
||||
{"suse-force-signed", OPTION_SUSE_FORCE_SIGNED, 0, 0,
|
||||
N_("force installation of signed grub" "%s."
|
||||
- "This option is only available on ARM64 EFI targets."), 0},
|
||||
+ "This option is only available on ARM64 EFI and powerpc targets."), 0},
|
||||
{"suse-inhibit-signed", OPTION_SUSE_INHIBIT_SIGNED, 0, 0,
|
||||
N_("inhibit installation of signed grub. "
|
||||
- "This option is only available on ARM64 EFI targets."), 0},
|
||||
+ "This option is only available on ARM64 EFI and powerpc targets."), 0},
|
||||
{"debug", OPTION_DEBUG, 0, OPTION_HIDDEN, 0, 2},
|
||||
{"no-floppy", OPTION_NO_FLOPPY, 0, OPTION_HIDDEN, 0, 2},
|
||||
{"debug-image", OPTION_DEBUG_IMAGE, N_("STRING"), OPTION_HIDDEN, 0, 2},
|
||||
@@ -1749,6 +1749,7 @@
|
||||
char mkimage_target[200];
|
||||
const char *core_name = NULL;
|
||||
char *signed_imgfile = NULL;
|
||||
+ int ppc_sb_state = -1;
|
||||
|
||||
switch (platform)
|
||||
{
|
||||
@@ -1796,11 +1797,33 @@
|
||||
grub_install_get_platform_platform (platform));
|
||||
break;
|
||||
|
||||
+
|
||||
+ case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
|
||||
+ ppc_sb_state = grub_install_get_powerpc_secure_boot();
|
||||
+
|
||||
+ if ((signed_grub_mode >= SIGNED_GRUB_FORCE) || ((signed_grub_mode == SIGNED_GRUB_AUTO) && (ppc_sb_state > 0)))
|
||||
+ {
|
||||
+ signed_imgfile = grub_util_path_concat (2, grub_install_source_directory, "grub.elf");
|
||||
+ if (!grub_util_is_regular (signed_imgfile))
|
||||
+ {
|
||||
+ if ((signed_grub_mode >= SIGNED_GRUB_FORCE) || (ppc_sb_state > 1))
|
||||
+ grub_util_error ("signed image `%s' does not exist\n", signed_imgfile);
|
||||
+ else
|
||||
+ {
|
||||
+ free (signed_imgfile);
|
||||
+ signed_imgfile = NULL;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (signed_imgfile)
|
||||
+ fprintf (stderr, _("Use signed file in %s for installation.\n"), signed_imgfile);
|
||||
+
|
||||
+ /* fallthrough. */
|
||||
case GRUB_INSTALL_PLATFORM_I386_COREBOOT:
|
||||
case GRUB_INSTALL_PLATFORM_ARM_COREBOOT:
|
||||
case GRUB_INSTALL_PLATFORM_I386_MULTIBOOT:
|
||||
case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
|
||||
- case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
|
||||
case GRUB_INSTALL_PLATFORM_I386_XEN:
|
||||
case GRUB_INSTALL_PLATFORM_X86_64_XEN:
|
||||
case GRUB_INSTALL_PLATFORM_I386_XEN_PVH:
|
||||
163
0001-grub-install-bailout-root-device-probing.patch
Normal file
163
0001-grub-install-bailout-root-device-probing.patch
Normal file
@ -0,0 +1,163 @@
|
||||
From 58dcf7985b20de876a6fc44a591aa377d0a0302c Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Thu, 10 Feb 2022 22:16:58 +0800
|
||||
Subject: [PATCH] grub-install: bailout root device probing
|
||||
|
||||
The root device is probed to test if the filesystem is btrfs in order to setup
|
||||
boot configs for snapshot booting. However when the root device is a lvm thin
|
||||
volume, due to lack in grub support, the probing will be errored out and entire
|
||||
installation process aborts.
|
||||
|
||||
Here we call out stat to bailout the situation whenever grub fails to probe
|
||||
filesystem in it's own right.
|
||||
|
||||
stat -f -c %T /
|
||||
|
||||
The command is also used by grub-mkconfig for the same purpose.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/osdep/basic/no_platform.c | 5 +++++
|
||||
grub-core/osdep/unix/platform.c | 34 +++++++++++++++++++++++++++++
|
||||
grub-core/osdep/windows/platform.c | 6 +++++
|
||||
include/grub/util/install.h | 3 +++
|
||||
util/grub-install.c | 31 ++++++++++++++++++--------
|
||||
5 files changed, 70 insertions(+), 9 deletions(-)
|
||||
|
||||
--- a/grub-core/osdep/basic/no_platform.c
|
||||
+++ b/grub-core/osdep/basic/no_platform.c
|
||||
@@ -51,3 +51,8 @@
|
||||
grub_util_error ("%s", _("no zIPL routines are available for your platform"));
|
||||
}
|
||||
|
||||
+char *
|
||||
+grub_install_get_filesystem (const char *path)
|
||||
+{
|
||||
+ return NULL;
|
||||
+}
|
||||
--- a/grub-core/osdep/unix/platform.c
|
||||
+++ b/grub-core/osdep/unix/platform.c
|
||||
@@ -250,3 +250,37 @@
|
||||
"-z", dest, NULL }))
|
||||
grub_util_error (_("`%s' failed.\n"), PACKAGE"-zipl-setup");
|
||||
}
|
||||
+
|
||||
+char *
|
||||
+grub_install_get_filesystem (const char *path)
|
||||
+{
|
||||
+ int fd;
|
||||
+ pid_t pid;
|
||||
+ FILE *fp;
|
||||
+ ssize_t len;
|
||||
+ char *buf = NULL;
|
||||
+ size_t bufsz = 0;
|
||||
+
|
||||
+ pid = grub_util_exec_pipe ((const char * []){ "stat", "-f", "-c", "%T", path, NULL }, &fd);
|
||||
+ if (!pid)
|
||||
+ return NULL;
|
||||
+
|
||||
+ fp = fdopen (fd, "r");
|
||||
+ if (!fp)
|
||||
+ return NULL;
|
||||
+
|
||||
+ len = getline (&buf, &bufsz, fp);
|
||||
+ if (len == -1)
|
||||
+ {
|
||||
+ free (buf);
|
||||
+ fclose (fp);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ fclose (fp);
|
||||
+
|
||||
+ if (len > 0 && buf[len - 1] == '\n')
|
||||
+ buf[len - 1] = '\0';
|
||||
+
|
||||
+ return buf;
|
||||
+}
|
||||
--- a/grub-core/osdep/windows/platform.c
|
||||
+++ b/grub-core/osdep/windows/platform.c
|
||||
@@ -440,3 +440,9 @@
|
||||
{
|
||||
grub_util_error ("%s", _("no zIPL routines are available for your platform"));
|
||||
}
|
||||
+
|
||||
+char *
|
||||
+grub_install_get_filesystem (const char *path)
|
||||
+{
|
||||
+ return NULL;
|
||||
+}
|
||||
--- a/include/grub/util/install.h
|
||||
+++ b/include/grub/util/install.h
|
||||
@@ -251,6 +251,9 @@
|
||||
void
|
||||
grub_install_zipl (const char *d, int i, int f);
|
||||
|
||||
+char *
|
||||
+grub_install_get_filesystem (const char *path);
|
||||
+
|
||||
int
|
||||
grub_install_compress_gzip (const char *src, const char *dest);
|
||||
int
|
||||
--- a/util/grub-install.c
|
||||
+++ b/util/grub-install.c
|
||||
@@ -887,7 +887,6 @@
|
||||
const char *efi_file = NULL;
|
||||
char **grub_devices;
|
||||
grub_fs_t grub_fs;
|
||||
- grub_fs_t root_fs;
|
||||
grub_device_t grub_dev = NULL;
|
||||
enum grub_install_plat platform;
|
||||
char *grubdir, *device_map;
|
||||
@@ -1067,8 +1066,10 @@
|
||||
grub_host_init ();
|
||||
|
||||
{
|
||||
- char *rootdir_grub_devname;
|
||||
- grub_device_t rootdir_grub_dev;
|
||||
+ grub_device_t rootdir_grub_dev = NULL;
|
||||
+ char *rootdir_grub_devname = NULL;
|
||||
+ char *root_fs_name = NULL;
|
||||
+
|
||||
char *t = grub_util_path_concat (2, "/", rootdir);
|
||||
|
||||
rootdir_path = grub_canonicalize_file_name (t);
|
||||
@@ -1089,20 +1090,32 @@
|
||||
rootdir_devices[0]);
|
||||
|
||||
rootdir_grub_dev = grub_device_open (rootdir_grub_devname);
|
||||
- if (! rootdir_grub_dev)
|
||||
- grub_util_error ("%s", grub_errmsg);
|
||||
+ if (!rootdir_grub_dev)
|
||||
+ {
|
||||
+ root_fs_name = grub_install_get_filesystem (t);
|
||||
+ if (root_fs_name)
|
||||
+ grub_errno = 0;
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ grub_fs_t root_fs = grub_fs_probe (rootdir_grub_dev);
|
||||
+ if (root_fs)
|
||||
+ root_fs_name = grub_strdup (root_fs->name);
|
||||
+ }
|
||||
|
||||
- root_fs = grub_fs_probe (rootdir_grub_dev);
|
||||
- if (!root_fs)
|
||||
+ if (!root_fs_name)
|
||||
grub_util_error ("%s", grub_errmsg);
|
||||
|
||||
if (config.is_suse_btrfs_snapshot_enabled
|
||||
- && grub_strncmp(root_fs->name, "btrfs", sizeof ("btrfs") - 1) == 0)
|
||||
+ && root_fs_name
|
||||
+ && grub_strncmp(root_fs_name, "btrfs", sizeof ("btrfs") - 1) == 0)
|
||||
use_relative_path_on_btrfs = 1;
|
||||
|
||||
+ free (root_fs_name);
|
||||
free (t);
|
||||
free (rootdir_grub_devname);
|
||||
- grub_device_close (rootdir_grub_dev);
|
||||
+ if (rootdir_grub_dev)
|
||||
+ grub_device_close (rootdir_grub_dev);
|
||||
}
|
||||
|
||||
switch (platform)
|
||||
110
0001-grub-probe-Deduplicate-probed-partmap-output.patch
Normal file
110
0001-grub-probe-Deduplicate-probed-partmap-output.patch
Normal file
@ -0,0 +1,110 @@
|
||||
From ed0ac581ad3866197fc05c7cf48e39419a51f606 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Fri, 18 Mar 2022 13:19:33 +0800
|
||||
Subject: [PATCH] grub-probe: Deduplicate probed partmap output
|
||||
|
||||
If the target device being probed is staked on top of other physical or logical
|
||||
devices, all containing device's partition map type will be printed once if
|
||||
--target=partmap is used. This usually results in duplicated output as same
|
||||
partition map type.
|
||||
|
||||
This in turn may clutter grub.cfg with many duplicated insmod part_[a-z]+ if
|
||||
the /boot is RAIDed because --target=partmap output is used to producing
|
||||
partmap modules required to access disk device.
|
||||
|
||||
Let's deduplicate that to make the grub.cfg looks better and disciplined.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
util/grub-probe.c | 59 +++++++++++++++++++++++++++++++++++++++++++----
|
||||
1 file changed, 55 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/util/grub-probe.c b/util/grub-probe.c
|
||||
index c08e46bbb..fb94f28fd 100644
|
||||
--- a/util/grub-probe.c
|
||||
+++ b/util/grub-probe.c
|
||||
@@ -153,6 +153,50 @@ do_print (const char *x, void *data)
|
||||
grub_printf ("%s%c", x, delim);
|
||||
}
|
||||
|
||||
+static int
|
||||
+check_duplicate_partmap (const char *name)
|
||||
+{
|
||||
+ static int alloc, used;
|
||||
+ static char **partmaps;
|
||||
+ int i;
|
||||
+
|
||||
+ if (!name)
|
||||
+ {
|
||||
+ if (partmaps)
|
||||
+ {
|
||||
+ for (i= 0; i < used; ++i)
|
||||
+ free (partmaps[i]);
|
||||
+ free (partmaps);
|
||||
+ partmaps = NULL;
|
||||
+ alloc = 0;
|
||||
+ used = 0;
|
||||
+ }
|
||||
+ return 1;
|
||||
+ }
|
||||
+
|
||||
+ for (i= 0; i < used; ++i)
|
||||
+ if (strcmp (partmaps[i], name) == 0)
|
||||
+ return 1;
|
||||
+
|
||||
+ if (alloc <= used)
|
||||
+ {
|
||||
+ alloc = (alloc) ? (alloc << 1) : 4;
|
||||
+ partmaps = xrealloc (partmaps, alloc * sizeof (*partmaps));
|
||||
+ }
|
||||
+
|
||||
+ partmaps[used++] = strdup (name);
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static void
|
||||
+do_print_partmap (const char *x, void *data)
|
||||
+{
|
||||
+ char delim = *(const char *) data;
|
||||
+ if (check_duplicate_partmap (x) != 0)
|
||||
+ return;
|
||||
+ grub_printf ("%s%c", x, delim);
|
||||
+}
|
||||
+
|
||||
static void
|
||||
probe_partmap (grub_disk_t disk, char delim)
|
||||
{
|
||||
@@ -165,10 +209,14 @@ probe_partmap (grub_disk_t disk, char delim)
|
||||
}
|
||||
|
||||
for (part = disk->partition; part; part = part->parent)
|
||||
- printf ("%s%c", part->partmap->name, delim);
|
||||
+ {
|
||||
+ if (check_duplicate_partmap (part->partmap->name) != 0)
|
||||
+ continue;
|
||||
+ printf ("%s%c", part->partmap->name, delim);
|
||||
+ }
|
||||
|
||||
if (disk->dev->id == GRUB_DISK_DEVICE_DISKFILTER_ID)
|
||||
- grub_diskfilter_get_partmap (disk, do_print, &delim);
|
||||
+ grub_diskfilter_get_partmap (disk, do_print_partmap, &delim);
|
||||
|
||||
/* In case of LVM/RAID, check the member devices as well. */
|
||||
if (disk->dev->disk_memberlist)
|
||||
@@ -674,8 +722,11 @@ probe (const char *path, char **device_names, char delim)
|
||||
probe_cryptodisk_uuid (dev->disk, delim);
|
||||
|
||||
else if (print == PRINT_PARTMAP)
|
||||
- /* Check if dev->disk itself is contained in a partmap. */
|
||||
- probe_partmap (dev->disk, delim);
|
||||
+ {
|
||||
+ /* Check if dev->disk itself is contained in a partmap. */
|
||||
+ probe_partmap (dev->disk, delim);
|
||||
+ check_duplicate_partmap (NULL);
|
||||
+ }
|
||||
|
||||
else if (print == PRINT_PARTUUID)
|
||||
{
|
||||
--
|
||||
2.35.1
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
From a59b58f6ae327a8f6949991cb5531db01e1ba14d Mon Sep 17 00:00:00 2001
|
||||
From: Wen Xiong <wenxiong@linux.ibm.com>
|
||||
Date: Tue, 7 Feb 2023 15:10:15 -0500
|
||||
Subject: [PATCH] grub2: Can't setup a default boot device correctly on nvme
|
||||
device in Beta3
|
||||
|
||||
The patch in Bug 200486 - SUSE1205666 - SLES15SP5 Beta1: Setup multiple dev path
|
||||
for a nvmf boot device in grub2 caused the issue. That patch didn't consider
|
||||
nvme devices carefully.
|
||||
|
||||
The new patch will check "nvme-of" instead of "nvme" to call
|
||||
build_multi_boot_device().
|
||||
|
||||
Signed-off-by: Wen Xiong<wenxiong@linux.ibm.com>
|
||||
---
|
||||
grub-core/osdep/unix/platform.c | 10 +++++++---
|
||||
1 file changed, 7 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/grub-core/osdep/unix/platform.c b/grub-core/osdep/unix/platform.c
|
||||
index db8fa4b95..fb47c0ffa 100644
|
||||
--- a/grub-core/osdep/unix/platform.c
|
||||
+++ b/grub-core/osdep/unix/platform.c
|
||||
@@ -288,11 +288,15 @@ grub_install_register_ieee1275 (int is_prep, const char *install_device,
|
||||
}
|
||||
*ptr = '\0';
|
||||
}
|
||||
- else if (grub_strstr(install_device, "nvme"))
|
||||
- boot_device = build_multi_boot_device(install_device);
|
||||
- else
|
||||
+ else {
|
||||
boot_device = get_ofpathname (install_device);
|
||||
|
||||
+ if (grub_strstr(boot_device, "nvme-of")) {
|
||||
+ free (boot_device);
|
||||
+ boot_device = build_multi_boot_device(install_device);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
if (grub_util_exec ((const char * []){ "nvsetenv", "boot-device",
|
||||
boot_device, NULL }))
|
||||
{
|
||||
--
|
||||
2.39.1
|
||||
|
||||
164
0001-grub2-Set-multiple-device-path-for-a-nvmf-boot-devic.patch
Normal file
164
0001-grub2-Set-multiple-device-path-for-a-nvmf-boot-devic.patch
Normal file
@ -0,0 +1,164 @@
|
||||
From 3e77c5494fd06f430588ae9c304fea370439d531 Mon Sep 17 00:00:00 2001
|
||||
From: Wen Xiong <Wen Xiong>
|
||||
Date: Thu, 15 Dec 2022 21:33:41 -0500
|
||||
Subject: [PATCH] grub2: Set multiple device path for a nvmf boot device
|
||||
|
||||
nvmf support native multipath(ANA) by default.
|
||||
The patch added the support for setting multiple
|
||||
device path for a nvmf boot device.
|
||||
|
||||
localhost:~ grub2-install -v /dev/nvme1n1p1
|
||||
...
|
||||
...
|
||||
...
|
||||
grub2-install: info: executing nvsetenv boot-device /pci@800000020000132/fibre-channel@0,1/nvme-of/controller@5005076810193675,ffff:nqn=nqn.1986-03.com.ibm:nvme:2145.0000020420006CEA/namespace@ec /pci@800000020000132/fibre-channel@0/nvme-of/controller@5005076810193675,ffff:nqn=nqn.1986-03.com.ibm:nvme:2145.0000020420006CEA/namespace@ec /pci@800000020000132/fibre-channel@0/nvme-of/controller@50050768101935e5,ffff:nqn=nqn.1986-03.com.ibm:nvme:2145.0000020420006CEA/namespace@ec /pci@800000020000132/fibre-channel@0,1/nvme-of/controller@50050768101935e5,ffff:nqn=nqn.1986-03.com.ibm:nvme:2145.0000020420006CEA/namespace@ec.
|
||||
Installation finished. No error reported.
|
||||
|
||||
localhost:~ # bootlist -m normal -o
|
||||
nvme7n1
|
||||
nvme5n1
|
||||
nvme1n1
|
||||
nvme4n1
|
||||
|
||||
localhost:~ # bootlist -m normal -r
|
||||
/pci@800000020000132/fibre-channel@0,1/nvme-of/controller@5005076810193675,ffff:nqn=nqn.1986-03.com.ibm:nvme:2145.0000020420006CEA/namespace@ec
|
||||
/pci@800000020000132/fibre-channel@0/nvme-of/controller@5005076810193675,ffff:nqn=nqn.1986-03.com.ibm:nvme:2145.0000020420006CEA/namespace@ec
|
||||
/pci@800000020000132/fibre-channel@0/nvme-of/controller@50050768101935e5,ffff:nqn=nqn.1986-03.com.ibm:nvme:2145.0000020420006CEA/namespace@ec
|
||||
/pci@800000020000132/fibre-channel@0,1/nvme-of/controller@50050768101935e5,ffff:nqn=nqn.1986-03.com.ibm:nvme:2145.0000020420006CEA/namespace@ec
|
||||
|
||||
Signed-off-by: Wen Xiong <wenxiong@linux.ibm.com>
|
||||
---
|
||||
grub-core/osdep/linux/ofpath.c | 6 ++---
|
||||
grub-core/osdep/unix/platform.c | 48 +++++++++++++++++++++++++++++++++
|
||||
include/grub/util/install.h | 3 +++
|
||||
include/grub/util/ofpath.h | 9 +++++++
|
||||
4 files changed, 63 insertions(+), 3 deletions(-)
|
||||
|
||||
--- a/grub-core/osdep/linux/ofpath.c
|
||||
+++ b/grub-core/osdep/linux/ofpath.c
|
||||
@@ -209,7 +209,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
-static char *
|
||||
+char *
|
||||
xrealpath (const char *in)
|
||||
{
|
||||
char *out;
|
||||
@@ -224,7 +224,7 @@
|
||||
return out;
|
||||
}
|
||||
|
||||
-static char *
|
||||
+char *
|
||||
block_device_get_sysfs_path_and_link(const char *devicenode)
|
||||
{
|
||||
char *rpath;
|
||||
@@ -535,7 +535,7 @@
|
||||
|
||||
}
|
||||
|
||||
-static char *
|
||||
+char *
|
||||
nvme_get_syspath(const char *nvmedev)
|
||||
{
|
||||
char *sysfs_path, *controller_node;
|
||||
--- a/grub-core/osdep/unix/platform.c
|
||||
+++ b/grub-core/osdep/unix/platform.c
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <grub/util/install.h>
|
||||
+#include <grub/util/ofpath.h>
|
||||
#include <grub/emu/hostdisk.h>
|
||||
#include <grub/util/misc.h>
|
||||
#include <grub/misc.h>
|
||||
@@ -131,6 +132,51 @@
|
||||
return rc;
|
||||
}
|
||||
|
||||
+char *
|
||||
+build_multi_boot_device(const char *install_device)
|
||||
+{
|
||||
+ char *sysfs_path;
|
||||
+ char *nvme_ns;
|
||||
+ unsigned int nsid;
|
||||
+ char *ptr;
|
||||
+ char *boot_device_string;
|
||||
+ struct dirent *ep;
|
||||
+ DIR *dp;
|
||||
+
|
||||
+ nvme_ns = strchr(install_device, 'n');
|
||||
+ nsid = of_path_get_nvme_nsid(nvme_ns);
|
||||
+ sysfs_path = nvme_get_syspath(nvme_ns);
|
||||
+ strcat(sysfs_path, "/device");
|
||||
+ sysfs_path = xrealpath(sysfs_path);
|
||||
+
|
||||
+ dp = opendir(sysfs_path);
|
||||
+ ptr = boot_device_string = xmalloc (1000);
|
||||
+
|
||||
+ /* We cannot have a boot list with more than five entries */
|
||||
+ while((ep = readdir(dp)) != NULL){
|
||||
+ char *nvme_device;
|
||||
+
|
||||
+ if (grub_strstr(ep->d_name, "nvme")) {
|
||||
+ nvme_device = xasprintf ("%s%s%x ",
|
||||
+ get_ofpathname(ep->d_name),"/namespace@", nsid);
|
||||
+ if ((strlen(boot_device_string) + strlen(nvme_device)) >= 200*5 - 1) {
|
||||
+ grub_util_warn (_("More than five entries cannot be specified in the bootlist"));
|
||||
+ free(nvme_device);
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ strncpy(ptr, nvme_device, strlen(nvme_device));
|
||||
+ ptr += strlen(nvme_device);
|
||||
+ free(nvme_device);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ *--ptr = '\0';
|
||||
+ closedir(dp);
|
||||
+
|
||||
+ return boot_device_string;
|
||||
+}
|
||||
+
|
||||
int
|
||||
grub_install_register_efi (const grub_disk_t *efidir_grub_disk,
|
||||
const char *efifile_path,
|
||||
@@ -242,6 +288,8 @@
|
||||
}
|
||||
*ptr = '\0';
|
||||
}
|
||||
+ else if (grub_strstr(install_device, "nvme"))
|
||||
+ boot_device = build_multi_boot_device(install_device);
|
||||
else
|
||||
boot_device = get_ofpathname (install_device);
|
||||
|
||||
--- a/include/grub/util/install.h
|
||||
+++ b/include/grub/util/install.h
|
||||
@@ -241,6 +241,9 @@
|
||||
const char *efi_distributor,
|
||||
const char *force_disk);
|
||||
|
||||
+char *
|
||||
+build_multi_boot_device(const char *install_device);
|
||||
+
|
||||
void
|
||||
grub_install_register_ieee1275 (int is_prep, const char *install_device,
|
||||
int partno, const char *relpath);
|
||||
--- a/include/grub/util/ofpath.h
|
||||
+++ b/include/grub/util/ofpath.h
|
||||
@@ -32,4 +32,13 @@
|
||||
|
||||
char* of_find_fc_host(char* host_wwpn);
|
||||
|
||||
+char* nvme_get_syspath(const char *nvmedev);
|
||||
+
|
||||
+char* block_device_get_sysfs_path_and_link(const char *devicenode);
|
||||
+
|
||||
+char* xrealpath (const char *in);
|
||||
+
|
||||
+unsigned int of_path_get_nvme_nsid(const char* devname);
|
||||
+
|
||||
+
|
||||
#endif /* ! GRUB_OFPATH_MACHINE_UTIL_HEADER */
|
||||
@ -1,18 +1,24 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Diego Domingos <diegodo@br.ibm.com>
|
||||
Date: Mon, 14 Dec 2020 17:42:45 +0100
|
||||
From e9d3202d5cffb89223ff61ac93de86a0cac1b50c Mon Sep 17 00:00:00 2001
|
||||
From: Diego Domingos <diegodo@linux.vnet.ibm.com>
|
||||
Date: Thu, 19 Nov 2020 10:47:25 -0300
|
||||
Subject: [PATCH] ieee1275: Avoiding many unecessary open/close
|
||||
|
||||
Signed-off-by: Diego Domingos <diegodo@br.ibm.com>
|
||||
This patch aims to change the grub_ofdisk_open and grub_ofdisk_close behaviors. Since some devices (Fibre Channel and NVMe) can have a long time for shutdown notification, we should avoid open and close the disks as much as we can.
|
||||
|
||||
So, we are changing how those functions works. The grub_ofdisk_close will take care of just changing the disk element status, by doing a soft close, i.e, the firmware will not be called. On the other hand, the grub_ofdisk_open will take care of closing the current disk opened only if the disk requested in the current call is different from the current one. This close will be responsible to request the firmware to actually close the disk.
|
||||
|
||||
Yet, this patch modifies the grub_ofdisk_get_block_size function, avoiding open and close calls inside of it.
|
||||
|
||||
Thank you Michael Chang (mchang@suse.com) for all support.
|
||||
|
||||
Signed-off-by: Diego Domingos <diegodo@linux.vnet.ibm.com>
|
||||
---
|
||||
grub-core/disk/ieee1275/ofdisk.c | 64 ++++++++++++++++++++++------------------
|
||||
grub-core/disk/ieee1275/ofdisk.c | 64 +++++++++++++++++---------------
|
||||
1 file changed, 35 insertions(+), 29 deletions(-)
|
||||
|
||||
diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
|
||||
index 03674cb477e..ea7f78ac7d8 100644
|
||||
--- a/grub-core/disk/ieee1275/ofdisk.c
|
||||
+++ b/grub-core/disk/ieee1275/ofdisk.c
|
||||
@@ -44,7 +44,7 @@ struct ofdisk_hash_ent
|
||||
@@ -44,7 +44,7 @@
|
||||
};
|
||||
|
||||
static grub_err_t
|
||||
@ -21,7 +27,7 @@ index 03674cb477e..ea7f78ac7d8 100644
|
||||
struct ofdisk_hash_ent *op);
|
||||
|
||||
#define OFDISK_HASH_SZ 8
|
||||
@@ -461,6 +461,7 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
|
||||
@@ -461,6 +461,7 @@
|
||||
grub_ssize_t actual;
|
||||
grub_uint32_t block_size = 0;
|
||||
grub_err_t err;
|
||||
@ -29,7 +35,7 @@ index 03674cb477e..ea7f78ac7d8 100644
|
||||
|
||||
if (grub_strncmp (name, "ieee1275/", sizeof ("ieee1275/") - 1) != 0)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
|
||||
@@ -471,6 +472,35 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
|
||||
@@ -471,6 +472,35 @@
|
||||
|
||||
grub_dprintf ("disk", "Opening `%s'.\n", devpath);
|
||||
|
||||
@ -65,7 +71,7 @@ index 03674cb477e..ea7f78ac7d8 100644
|
||||
if (grub_ieee1275_finddevice (devpath, &dev))
|
||||
{
|
||||
grub_free (devpath);
|
||||
@@ -491,25 +521,18 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
|
||||
@@ -491,25 +521,18 @@
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a block device");
|
||||
}
|
||||
|
||||
@ -94,7 +100,7 @@ index 03674cb477e..ea7f78ac7d8 100644
|
||||
if (err)
|
||||
{
|
||||
grub_free (devpath);
|
||||
@@ -532,13 +555,6 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
|
||||
@@ -528,13 +551,6 @@
|
||||
static void
|
||||
grub_ofdisk_close (grub_disk_t disk)
|
||||
{
|
||||
@ -108,7 +114,7 @@ index 03674cb477e..ea7f78ac7d8 100644
|
||||
disk->data = 0;
|
||||
}
|
||||
|
||||
@@ -685,7 +701,7 @@ grub_ofdisk_init (void)
|
||||
@@ -681,7 +697,7 @@
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
@ -117,7 +123,7 @@ index 03674cb477e..ea7f78ac7d8 100644
|
||||
struct ofdisk_hash_ent *op)
|
||||
{
|
||||
struct size_args_ieee1275
|
||||
@@ -698,16 +714,6 @@ grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size,
|
||||
@@ -694,16 +710,6 @@
|
||||
grub_ieee1275_cell_t size2;
|
||||
} args_ieee1275;
|
||||
|
||||
250
0001-ieee1275-add-support-for-NVMeoFC.patch
Normal file
250
0001-ieee1275-add-support-for-NVMeoFC.patch
Normal file
@ -0,0 +1,250 @@
|
||||
From c125cb45a7885d7bf168a05cfa4da3e681244649 Mon Sep 17 00:00:00 2001
|
||||
From: Diego Domingos <diegodo@br.ibm.com>
|
||||
Date: Tue, 15 Feb 2022 13:11:48 -0500
|
||||
Subject: [PATCH 1/4] ieee1275: add support for NVMeoFC
|
||||
|
||||
Implements the functions to scan and discovery of NVMeoFC.
|
||||
---
|
||||
grub-core/disk/ieee1275/ofdisk.c | 217 ++++++++++++++++++++++++++++++-
|
||||
1 file changed, 213 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
|
||||
index 410f4b849..852bb95be 100644
|
||||
--- a/grub-core/disk/ieee1275/ofdisk.c
|
||||
+++ b/grub-core/disk/ieee1275/ofdisk.c
|
||||
@@ -206,12 +206,10 @@ dev_iterate_real (const char *name, const char *path)
|
||||
return;
|
||||
}
|
||||
|
||||
+
|
||||
static void
|
||||
-dev_iterate (const struct grub_ieee1275_devalias *alias)
|
||||
+dev_iterate_fcp_disks(const struct grub_ieee1275_devalias *alias)
|
||||
{
|
||||
- if (grub_strcmp (alias->type, "fcp") == 0)
|
||||
- {
|
||||
-
|
||||
/* If we are dealing with fcp devices, we need
|
||||
* to find the WWPNs and LUNs to iterate them */
|
||||
grub_ieee1275_ihandle_t ihandle;
|
||||
@@ -323,6 +321,217 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
|
||||
grub_free (buf);
|
||||
return;
|
||||
|
||||
+}
|
||||
+
|
||||
+static void
|
||||
+dev_iterate_fcp_nvmeof (const struct grub_ieee1275_devalias *alias)
|
||||
+{
|
||||
+
|
||||
+
|
||||
+ char *bufptr;
|
||||
+ grub_ieee1275_ihandle_t ihandle;
|
||||
+
|
||||
+
|
||||
+ // Create the structs for the parameters passing to PFW
|
||||
+ struct nvme_args_
|
||||
+ {
|
||||
+ struct grub_ieee1275_common_hdr common;
|
||||
+ grub_ieee1275_cell_t method;
|
||||
+ grub_ieee1275_cell_t ihandle;
|
||||
+ grub_ieee1275_cell_t catch_result;
|
||||
+ grub_ieee1275_cell_t nentries;
|
||||
+ grub_ieee1275_cell_t table;
|
||||
+ } nvme_discovery_controllers_args, nvme_controllers_args, nvme_namespaces_args;
|
||||
+
|
||||
+
|
||||
+ // Create the structs for the results from PFW
|
||||
+
|
||||
+ struct discovery_controllers_table_struct_
|
||||
+ {
|
||||
+ grub_uint64_t table[256];
|
||||
+ grub_uint32_t len;
|
||||
+ } discovery_controllers_table;
|
||||
+
|
||||
+ /* struct nvme_controllers_table_entry
|
||||
+ * this the return of nvme-controllers method tables, containing:
|
||||
+ * - 2-byte controller ID
|
||||
+ * - 256-byte transport address string
|
||||
+ * - 256-byte field containing null-terminated NVM subsystem NQN string up to 223 characters
|
||||
+ */
|
||||
+ struct nvme_controllers_table_entry_
|
||||
+ {
|
||||
+ grub_uint16_t id;
|
||||
+ char wwpn[256];
|
||||
+ char nqn[256];
|
||||
+ };
|
||||
+
|
||||
+ struct nvme_controllers_table_entry_* nvme_controllers_table = grub_malloc(sizeof(struct nvme_controllers_table_entry_)*256);
|
||||
+
|
||||
+ grub_uint32_t nvme_controllers_table_entries;
|
||||
+
|
||||
+ struct nvme_controllers_table_entry_real
|
||||
+ {
|
||||
+ grub_uint16_t id;
|
||||
+ char wwpn[256];
|
||||
+ char nqn[256];
|
||||
+ };
|
||||
+
|
||||
+ /* Allocate memory for building the NVMeoF path */
|
||||
+ char *buf = grub_malloc (grub_strlen (alias->path) + 512);
|
||||
+ if (!buf)
|
||||
+ {
|
||||
+ grub_ieee1275_close(ihandle);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ /* Copy the alias->path to buf so we can work with */
|
||||
+ bufptr = grub_stpcpy (buf, alias->path);
|
||||
+ grub_snprintf (bufptr, 32, "/nvme-of");
|
||||
+
|
||||
+ /*
|
||||
+ * Open the nvme-of layer
|
||||
+ * Ex. /pci@bus/fibre-channel@@dev,func/nvme-of
|
||||
+ */
|
||||
+ if(grub_ieee1275_open (buf, &ihandle))
|
||||
+ {
|
||||
+ grub_dprintf("disk", "failed to open the disk while iterating FCP disk path=%s\n", buf);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ /*
|
||||
+ * Call to nvme-discovery-controllers method from the nvme-of layer
|
||||
+ * to get a list of the NVMe discovery controllers per the binding
|
||||
+ */
|
||||
+
|
||||
+ INIT_IEEE1275_COMMON (&nvme_discovery_controllers_args.common, "call-method", 2, 2);
|
||||
+ nvme_discovery_controllers_args.method = (grub_ieee1275_cell_t) "nvme-discovery-controllers";
|
||||
+ nvme_discovery_controllers_args.ihandle = ihandle;
|
||||
+
|
||||
+ if (IEEE1275_CALL_ENTRY_FN (&nvme_discovery_controllers_args) == -1)
|
||||
+ {
|
||||
+ grub_dprintf("disk", "failed to get the targets while iterating FCP disk path=%s\n", buf);
|
||||
+ grub_ieee1275_close(ihandle);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ /* After closing the device, the info is lost. So lets copy each buffer in the buffers table */
|
||||
+
|
||||
+ discovery_controllers_table.len = (grub_uint32_t) nvme_discovery_controllers_args.nentries;
|
||||
+
|
||||
+ unsigned int i=0;
|
||||
+ for(i = 0; i < discovery_controllers_table.len; i++){
|
||||
+ discovery_controllers_table.table[i] = ((grub_uint64_t*)nvme_discovery_controllers_args.table)[i];
|
||||
+ }
|
||||
+
|
||||
+ grub_ieee1275_close(ihandle);
|
||||
+
|
||||
+ grub_dprintf("ofdisk","NVMeoF: Found %d discovery controllers\n",discovery_controllers_table.len);
|
||||
+
|
||||
+ /* For each nvme discovery controller */
|
||||
+ int current_buffer_index;
|
||||
+ for(current_buffer_index = 0; current_buffer_index < (int) discovery_controllers_table.len; current_buffer_index++){
|
||||
+
|
||||
+
|
||||
+ grub_snprintf (bufptr, 64, "/nvme-of/controller@%" PRIxGRUB_UINT64_T ",ffff",
|
||||
+ discovery_controllers_table.table[current_buffer_index]);
|
||||
+
|
||||
+ grub_dprintf("ofdisk","nvmeof controller=%s\n",buf);
|
||||
+
|
||||
+ if(grub_ieee1275_open (buf, &ihandle))
|
||||
+ {
|
||||
+ grub_dprintf("ofdisk", "failed to open the disk while getting nvme-controllers path=%s\n", buf);
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+ INIT_IEEE1275_COMMON (&nvme_controllers_args.common, "call-method", 2, 2);
|
||||
+ nvme_controllers_args.method = (grub_ieee1275_cell_t) "nvme-controllers";
|
||||
+ nvme_controllers_args.ihandle = ihandle;
|
||||
+ nvme_controllers_args.catch_result = 0;
|
||||
+
|
||||
+
|
||||
+ if (IEEE1275_CALL_ENTRY_FN (&nvme_controllers_args) == -1)
|
||||
+ {
|
||||
+ grub_dprintf("ofdisk", "failed to get the nvme-controllers while iterating FCP disk path\n");
|
||||
+ grub_ieee1275_close(ihandle);
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+ /* Copy the buffer list to nvme_controllers_table */
|
||||
+ nvme_controllers_table_entries = ((grub_uint32_t) nvme_controllers_args.nentries);
|
||||
+ struct nvme_controllers_table_entry_* nvme_controllers_table_ = (struct nvme_controllers_table_entry_*) nvme_controllers_args.table;
|
||||
+
|
||||
+ for(i = 0; i < nvme_controllers_table_entries; i++){
|
||||
+ nvme_controllers_table[i].id = (grub_uint16_t) nvme_controllers_table_[i].id;
|
||||
+ grub_strcpy(nvme_controllers_table[i].wwpn, nvme_controllers_table_[i].wwpn);
|
||||
+ grub_strcpy(nvme_controllers_table[i].nqn, nvme_controllers_table_[i].nqn);
|
||||
+ }
|
||||
+
|
||||
+ grub_ieee1275_close(ihandle);
|
||||
+
|
||||
+ int nvme_controller_index;
|
||||
+ int bufptr_pos2;
|
||||
+ grub_dprintf("ofdisk","NVMeoF: found %d nvme controllers\n",(int) nvme_controllers_args.nentries);
|
||||
+
|
||||
+ /* For each nvme controller */
|
||||
+ for(nvme_controller_index = 0; nvme_controller_index < (int) nvme_controllers_args.nentries; nvme_controller_index++){
|
||||
+ /* Open the nvme controller
|
||||
+ * /pci@bus/fibre-channel@dev,func/nvme-of/controller@transport-addr,ctlr-id:nqn=tgt-subsystem-nqn
|
||||
+ */
|
||||
+
|
||||
+ bufptr_pos2 = grub_snprintf (bufptr, 512, "/nvme-of/controller@%s,ffff:nqn=%s",
|
||||
+ nvme_controllers_table[nvme_controller_index].wwpn, nvme_controllers_table[nvme_controller_index].nqn);
|
||||
+
|
||||
+ grub_dprintf("ofdisk","NVMeoF: nvmeof controller=%s\n",buf);
|
||||
+
|
||||
+ if(grub_ieee1275_open (buf, &ihandle)){
|
||||
+ grub_dprintf("ofdisk","failed to open the path=%s\n",buf);
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ INIT_IEEE1275_COMMON (&nvme_namespaces_args.common, "call-method", 2, 2);
|
||||
+ nvme_namespaces_args.method = (grub_ieee1275_cell_t) "get-namespace-list";
|
||||
+ nvme_namespaces_args.ihandle = ihandle;
|
||||
+ nvme_namespaces_args.catch_result = 0;
|
||||
+
|
||||
+ if (IEEE1275_CALL_ENTRY_FN (&nvme_namespaces_args) == -1)
|
||||
+ {
|
||||
+ grub_dprintf("ofdisk", "failed to get the nvme-namespace-list while iterating FCP disk path\n");
|
||||
+ grub_ieee1275_close(ihandle);
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ grub_uint32_t *namespaces = (grub_uint32_t*) nvme_namespaces_args.table;
|
||||
+ grub_dprintf("ofdisk","NVMeoF: found %d namespaces\n",(int)nvme_namespaces_args.nentries);
|
||||
+
|
||||
+ grub_ieee1275_close(ihandle);
|
||||
+
|
||||
+ grub_uint32_t namespace_index = 0;
|
||||
+ for(namespace_index=0; namespace_index < nvme_namespaces_args.nentries; namespace_index++){
|
||||
+ grub_snprintf (bufptr+bufptr_pos2, 512, "/namespace@%"PRIxGRUB_UINT32_T,namespaces[namespace_index]);
|
||||
+ grub_dprintf("ofdisk","NVMeoF: namespace=%s\n",buf);
|
||||
+ dev_iterate_real(buf,buf);
|
||||
+ }
|
||||
+
|
||||
+ dev_iterate_real(buf,buf);
|
||||
+ }
|
||||
+ }
|
||||
+ grub_free(buf);
|
||||
+ return;
|
||||
+}
|
||||
+
|
||||
+static void
|
||||
+dev_iterate (const struct grub_ieee1275_devalias *alias)
|
||||
+{
|
||||
+ if (grub_strcmp (alias->type, "fcp") == 0)
|
||||
+ {
|
||||
+ // Iterate disks
|
||||
+ dev_iterate_fcp_disks(alias);
|
||||
+
|
||||
+ // Iterate NVMeoF
|
||||
+ dev_iterate_fcp_nvmeof(alias);
|
||||
+
|
||||
}
|
||||
else if (grub_strcmp (alias->type, "vscsi") == 0)
|
||||
{
|
||||
--
|
||||
2.35.3
|
||||
|
||||
146
0001-ieee1275-implement-FCP-methods-for-WWPN-and-LUNs.patch
Normal file
146
0001-ieee1275-implement-FCP-methods-for-WWPN-and-LUNs.patch
Normal file
@ -0,0 +1,146 @@
|
||||
From a37d0cc089edd66ab35f1a27b0da09dd2f02deb3 Mon Sep 17 00:00:00 2001
|
||||
From: Diego Domingos <diegodo@br.ibm.com>
|
||||
Date: Mon, 24 Jun 2019 10:15:56 -0400
|
||||
Subject: [PATCH] ieee1275: implement FCP methods for WWPN and LUNs
|
||||
|
||||
This patch enables the fcp-targets and fcp-luns methods which are
|
||||
responsible to get WWPNs and LUNs for fibre channel devices.
|
||||
|
||||
Those methods are specially necessary if the boot directory and grub
|
||||
installation are in different FCP disks, allowing the dev_iterate()
|
||||
to find the WWPNs and LUNs when called by searchfs.uuid tool.
|
||||
---
|
||||
grub-core/disk/ieee1275/ofdisk.c | 117 ++++++++++++++++++++++++++++++-
|
||||
1 file changed, 116 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
|
||||
index ea7f78ac7..258a6e389 100644
|
||||
--- a/grub-core/disk/ieee1275/ofdisk.c
|
||||
+++ b/grub-core/disk/ieee1275/ofdisk.c
|
||||
@@ -209,7 +209,122 @@ dev_iterate_real (const char *name, const char *path)
|
||||
static void
|
||||
dev_iterate (const struct grub_ieee1275_devalias *alias)
|
||||
{
|
||||
- if (grub_strcmp (alias->type, "vscsi") == 0)
|
||||
+ if (grub_strcmp (alias->type, "fcp") == 0)
|
||||
+ {
|
||||
+
|
||||
+ /* If we are dealing with fcp devices, we need
|
||||
+ * to find the WWPNs and LUNs to iterate them */
|
||||
+ grub_ieee1275_ihandle_t ihandle;
|
||||
+ grub_uint64_t *ptr_targets, *ptr_luns, k, l;
|
||||
+ unsigned int i, j, pos;
|
||||
+ char *buf, *bufptr;
|
||||
+
|
||||
+ struct set_fcp_targets_args
|
||||
+ {
|
||||
+ struct grub_ieee1275_common_hdr common;
|
||||
+ grub_ieee1275_cell_t method;
|
||||
+ grub_ieee1275_cell_t ihandle;
|
||||
+ grub_ieee1275_cell_t catch_result;
|
||||
+ grub_ieee1275_cell_t nentries;
|
||||
+ grub_ieee1275_cell_t table;
|
||||
+ } args_targets;
|
||||
+
|
||||
+ struct set_fcp_luns_args
|
||||
+ {
|
||||
+ struct grub_ieee1275_common_hdr common;
|
||||
+ grub_ieee1275_cell_t method;
|
||||
+ grub_ieee1275_cell_t ihandle;
|
||||
+ grub_ieee1275_cell_t wwpn_h;
|
||||
+ grub_ieee1275_cell_t wwpn_l;
|
||||
+ grub_ieee1275_cell_t catch_result;
|
||||
+ grub_ieee1275_cell_t nentries;
|
||||
+ grub_ieee1275_cell_t table;
|
||||
+ } args_luns;
|
||||
+
|
||||
+ struct args_ret
|
||||
+ {
|
||||
+ grub_uint64_t addr;
|
||||
+ grub_uint64_t len;
|
||||
+ };
|
||||
+
|
||||
+ if(grub_ieee1275_open (alias->path, &ihandle))
|
||||
+ {
|
||||
+ grub_dprintf("disk", "failed to open the disk while iterating FCP disk path=%s\n", alias->path);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ /* Setup the fcp-targets method to call via pfw*/
|
||||
+ INIT_IEEE1275_COMMON (&args_targets.common, "call-method", 2, 3);
|
||||
+ args_targets.method = (grub_ieee1275_cell_t) "fcp-targets";
|
||||
+ args_targets.ihandle = ihandle;
|
||||
+
|
||||
+ /* Setup the fcp-luns method to call via pfw */
|
||||
+ INIT_IEEE1275_COMMON (&args_luns.common, "call-method", 4, 3);
|
||||
+ args_luns.method = (grub_ieee1275_cell_t) "fcp-luns";
|
||||
+ args_luns.ihandle = ihandle;
|
||||
+
|
||||
+ if (IEEE1275_CALL_ENTRY_FN (&args_targets) == -1)
|
||||
+ {
|
||||
+ grub_dprintf("disk", "failed to get the targets while iterating FCP disk path=%s\n", alias->path);
|
||||
+ grub_ieee1275_close(ihandle);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ buf = grub_malloc (grub_strlen (alias->path) + 32 + 32);
|
||||
+
|
||||
+ if (!buf)
|
||||
+ {
|
||||
+ grub_ieee1275_close(ihandle);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ bufptr = grub_stpcpy (buf, alias->path);
|
||||
+
|
||||
+ /* Iterate over entries returned by pfw. Each entry contains a
|
||||
+ * pointer to wwpn table and his length. */
|
||||
+ struct args_ret *targets_table = (struct args_ret *)(args_targets.table);
|
||||
+ for (i=0; i< args_targets.nentries; i++)
|
||||
+ {
|
||||
+ ptr_targets = (grub_uint64_t*)(grub_uint32_t) targets_table[i].addr;
|
||||
+ /* Iterate over all wwpns in given table */
|
||||
+ for(k=0;k<targets_table[i].len;k++)
|
||||
+ {
|
||||
+ args_luns.wwpn_l = (grub_ieee1275_cell_t) (*ptr_targets);
|
||||
+ args_luns.wwpn_h = (grub_ieee1275_cell_t) (*ptr_targets >> 32);
|
||||
+ pos=grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T,
|
||||
+ *ptr_targets++);
|
||||
+ /* Get the luns for given wwpn target */
|
||||
+ if (IEEE1275_CALL_ENTRY_FN (&args_luns) == -1)
|
||||
+ {
|
||||
+ grub_dprintf("disk", "failed to get the LUNS while iterating FCP disk path=%s\n", buf);
|
||||
+ grub_ieee1275_close (ihandle);
|
||||
+ grub_free (buf);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ struct args_ret *luns_table = (struct args_ret *)(args_luns.table);
|
||||
+
|
||||
+ /* Iterate over all LUNs */
|
||||
+ for(j=0;j<args_luns.nentries; j++)
|
||||
+ {
|
||||
+ ptr_luns = (grub_uint64_t*) (grub_uint32_t) luns_table[j].addr;
|
||||
+ for(l=0;l<luns_table[j].len;l++)
|
||||
+ {
|
||||
+ grub_snprintf (&bufptr[pos], 30, ",%" PRIxGRUB_UINT64_T,
|
||||
+ *ptr_luns++);
|
||||
+ dev_iterate_real(buf,buf);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ grub_ieee1275_close (ihandle);
|
||||
+ grub_free (buf);
|
||||
+ return;
|
||||
+
|
||||
+ }
|
||||
+ else if (grub_strcmp (alias->type, "vscsi") == 0)
|
||||
{
|
||||
static grub_ieee1275_ihandle_t ihandle;
|
||||
struct set_color_args
|
||||
--
|
||||
2.31.1
|
||||
|
||||
172
0001-ieee1275-ofdisk-retry-on-open-and-read-failure.patch
Normal file
172
0001-ieee1275-ofdisk-retry-on-open-and-read-failure.patch
Normal file
@ -0,0 +1,172 @@
|
||||
From f4728ed5307b6be6377b7bdafcab55fd3676a761 Mon Sep 17 00:00:00 2001
|
||||
From: Mukesh Kumar Chaurasiya <mchauras@linux.ibm.com>
|
||||
Date: Mon, 17 Jul 2023 16:02:34 +0530
|
||||
Subject: [PATCH] ieee1275/ofdisk: retry on open and read failure
|
||||
|
||||
Sometimes, when booting from a very busy SAN, the access to the
|
||||
disk can fail and then grub will eventually drop to grub prompt.
|
||||
This scenario is more frequent when deploying many machines at
|
||||
the same time using the same SAN.
|
||||
This patch aims to force the ofdisk module to retry the open or
|
||||
read function for network disks excluding after it fails. We use
|
||||
DEFAULT_RETRY_TIMEOUT, which is 15 seconds to specify the time it'll
|
||||
retry to access the disk before it definitely fails. The timeout can be
|
||||
changed by setting the environment variable ofdisk_retry_timeout.
|
||||
If the environment variable fails to read, grub will consider the
|
||||
default value of 15 seconds.
|
||||
|
||||
Signed-off-by: Diego Domingos <diegodo@linux.vnet.ibm.com>
|
||||
Signed-off-by: Mukesh Kumar Chaurasiya <mchauras@linux.ibm.com>
|
||||
---
|
||||
docs/grub.texi | 8 ++++
|
||||
grub-core/disk/ieee1275/ofdisk.c | 80 +++++++++++++++++++++++++++++++-
|
||||
2 files changed, 86 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/docs/grub.texi b/docs/grub.texi
|
||||
index d3f0f6577..c8ebc083d 100644
|
||||
--- a/docs/grub.texi
|
||||
+++ b/docs/grub.texi
|
||||
@@ -3315,6 +3315,7 @@ These variables have special meaning to GRUB.
|
||||
* net_default_ip::
|
||||
* net_default_mac::
|
||||
* net_default_server::
|
||||
+* ofdisk_retry_timeout::
|
||||
* pager::
|
||||
* prefix::
|
||||
* pxe_blksize::
|
||||
@@ -3744,6 +3745,13 @@ The default is the value of @samp{color_normal} (@pxref{color_normal}).
|
||||
@xref{Network}.
|
||||
|
||||
|
||||
+@node ofdisk_retry_timeout
|
||||
+@subsection ofdisk_retry_timeout
|
||||
+
|
||||
+The time in seconds till which the grub will retry to open or read a disk in
|
||||
+case of failure to do so. This value defaults to 15 seconds.
|
||||
+
|
||||
+
|
||||
@node pager
|
||||
@subsection pager
|
||||
|
||||
diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
|
||||
index 7197d5401..f96bbb58c 100644
|
||||
--- a/grub-core/disk/ieee1275/ofdisk.c
|
||||
+++ b/grub-core/disk/ieee1275/ofdisk.c
|
||||
@@ -24,6 +24,9 @@
|
||||
#include <grub/ieee1275/ofdisk.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/time.h>
|
||||
+#include <grub/env.h>
|
||||
+
|
||||
+#define RETRY_DEFAULT_TIMEOUT 15
|
||||
|
||||
static char *last_devpath;
|
||||
static grub_ieee1275_ihandle_t last_ihandle;
|
||||
@@ -783,7 +786,7 @@ compute_dev_path (const char *name)
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
-grub_ofdisk_open (const char *name, grub_disk_t disk)
|
||||
+grub_ofdisk_open_real (const char *name, grub_disk_t disk)
|
||||
{
|
||||
grub_ieee1275_phandle_t dev;
|
||||
char *devpath;
|
||||
@@ -879,6 +882,56 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
|
||||
return 0;
|
||||
}
|
||||
|
||||
+static grub_uint64_t
|
||||
+grub_ofdisk_disk_timeout (grub_disk_t disk)
|
||||
+{
|
||||
+ grub_uint64_t retry;
|
||||
+ const char *timeout = grub_env_get ("ofdisk_retry_timeout");
|
||||
+
|
||||
+ if (!(grub_strstr (disk->name, "fibre-channel@") ||
|
||||
+ grub_strstr (disk->name, "vfc-client")) ||
|
||||
+ grub_strstr(disk->name, "nvme-of"))
|
||||
+ {
|
||||
+ /* Do not retry in case of non network drives */
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ if (timeout != NULL)
|
||||
+ {
|
||||
+ retry = grub_strtoul (timeout, 0, 10);
|
||||
+ if (grub_errno != GRUB_ERR_NONE)
|
||||
+ {
|
||||
+ grub_errno = GRUB_ERR_NONE;
|
||||
+ return RETRY_DEFAULT_TIMEOUT;
|
||||
+ }
|
||||
+ if (retry)
|
||||
+ return retry;
|
||||
+ }
|
||||
+ return RETRY_DEFAULT_TIMEOUT;
|
||||
+}
|
||||
+
|
||||
+static grub_err_t
|
||||
+grub_ofdisk_open (const char *name, grub_disk_t disk)
|
||||
+{
|
||||
+ grub_err_t err;
|
||||
+ grub_uint64_t timeout = grub_get_time_ms () + (grub_ofdisk_disk_timeout (disk) * 1000);
|
||||
+ _Bool cont;
|
||||
+ do
|
||||
+ {
|
||||
+ err = grub_ofdisk_open_real (name, disk);
|
||||
+ cont = grub_get_time_ms () < timeout;
|
||||
+ if (err == GRUB_ERR_UNKNOWN_DEVICE && cont)
|
||||
+ {
|
||||
+ grub_dprintf ("ofdisk","Failed to open disk %s. Retrying...\n", name);
|
||||
+ grub_errno = GRUB_ERR_NONE;
|
||||
+ }
|
||||
+ else
|
||||
+ break;
|
||||
+ grub_millisleep (1000);
|
||||
+ } while (cont);
|
||||
+ return err;
|
||||
+}
|
||||
+
|
||||
static void
|
||||
grub_ofdisk_close (grub_disk_t disk)
|
||||
{
|
||||
@@ -915,7 +968,7 @@ grub_ofdisk_prepare (grub_disk_t disk, grub_disk_addr_t sector)
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
-grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
|
||||
+grub_ofdisk_read_real (grub_disk_t disk, grub_disk_addr_t sector,
|
||||
grub_size_t size, char *buf)
|
||||
{
|
||||
grub_err_t err;
|
||||
@@ -934,6 +987,29 @@ grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
|
||||
return 0;
|
||||
}
|
||||
|
||||
+static grub_err_t
|
||||
+grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
|
||||
+ grub_size_t size, char *buf)
|
||||
+{
|
||||
+ grub_err_t err;
|
||||
+ grub_uint64_t timeout = grub_get_time_ms () + (grub_ofdisk_disk_timeout (disk) * 1000);
|
||||
+ _Bool cont;
|
||||
+ do
|
||||
+ {
|
||||
+ err = grub_ofdisk_read_real (disk, sector, size, buf);
|
||||
+ cont = grub_get_time_ms () < timeout;
|
||||
+ if (err == GRUB_ERR_UNKNOWN_DEVICE && cont)
|
||||
+ {
|
||||
+ grub_dprintf ("ofdisk","Failed to read disk %s. Retrying...\n", (char*)disk->data);
|
||||
+ grub_errno = GRUB_ERR_NONE;
|
||||
+ }
|
||||
+ else
|
||||
+ break;
|
||||
+ grub_millisleep (1000);
|
||||
+ } while (cont);
|
||||
+ return err;
|
||||
+}
|
||||
+
|
||||
static grub_err_t
|
||||
grub_ofdisk_write (grub_disk_t disk, grub_disk_addr_t sector,
|
||||
grub_size_t size, const char *buf)
|
||||
--
|
||||
2.41.0
|
||||
|
||||
@ -1,28 +1,25 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From ca30b3c6fd8c848f510445316d0c4a8fca6061ba Mon Sep 17 00:00:00 2001
|
||||
From: Diego Domingos <diegodo@br.ibm.com>
|
||||
Date: Mon, 14 Dec 2020 17:45:28 +0100
|
||||
Subject: [PATCH] ieee1275/powerpc: implements fibre channel discovery for
|
||||
Date: Wed, 24 Jun 2020 08:17:18 -0400
|
||||
Subject: [PATCH 1/2] ieee1275/powerpc: implements fibre channel discovery for
|
||||
ofpathname
|
||||
|
||||
grub-ofpathname doesn't work with fibre channel because there is no
|
||||
function currently implemented for it.
|
||||
This patch enables it by prividing a function that looks for the port
|
||||
name, building the entire path for OF devices.
|
||||
|
||||
Signed-off-by: Diego Domingos <diegodo@br.ibm.com>
|
||||
---
|
||||
grub-core/osdep/linux/ofpath.c | 49 ++++++++++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 49 insertions(+)
|
||||
grub-core/osdep/linux/ofpath.c | 48 ++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 48 insertions(+)
|
||||
|
||||
diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
|
||||
index a6153d35954..0f5d54e9f2d 100644
|
||||
index a6153d359..f2bc9fc5c 100644
|
||||
--- a/grub-core/osdep/linux/ofpath.c
|
||||
+++ b/grub-core/osdep/linux/ofpath.c
|
||||
@@ -350,6 +350,38 @@ of_path_of_ide(const char *sys_devname __attribute__((unused)), const char *devi
|
||||
return ret;
|
||||
@@ -399,6 +399,37 @@ of_path_of_nvme(const char *sys_devname __attribute__((unused)),
|
||||
}
|
||||
#endif
|
||||
|
||||
+
|
||||
+static void
|
||||
+of_fc_port_name(const char *path, const char *subpath, char *port_name)
|
||||
+{
|
||||
@ -54,10 +51,10 @@ index a6153d35954..0f5d54e9f2d 100644
|
||||
+ free(basepath);
|
||||
+}
|
||||
+
|
||||
#ifdef __sparc__
|
||||
static char *
|
||||
of_path_of_nvme(const char *sys_devname __attribute__((unused)),
|
||||
@@ -577,6 +609,16 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
|
||||
static int
|
||||
vendor_is_ATA(const char *path)
|
||||
{
|
||||
@@ -577,6 +608,16 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
|
||||
digit_string = trailing_digits (device);
|
||||
if (strncmp (of_path, "/vdevice/", sizeof ("/vdevice/") - 1) == 0)
|
||||
{
|
||||
@ -74,7 +71,7 @@ index a6153d35954..0f5d54e9f2d 100644
|
||||
unsigned long id = 0x8000 | (tgt << 8) | (bus << 5) | lun;
|
||||
if (*digit_string == '\0')
|
||||
{
|
||||
@@ -590,6 +632,13 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
|
||||
@@ -590,6 +631,13 @@ of_path_of_scsi(const char *sys_devname __attribute__((unused)), const char *dev
|
||||
snprintf(disk, sizeof (disk),
|
||||
"/%s@%04lx000000000000:%c", disk_name, id, 'a' + (part - 1));
|
||||
}
|
||||
@ -88,3 +85,6 @@ index a6153d35954..0f5d54e9f2d 100644
|
||||
}
|
||||
else
|
||||
{
|
||||
--
|
||||
2.26.2
|
||||
|
||||
396
0001-install-fix-software-raid1-on-esp.patch
Normal file
396
0001-install-fix-software-raid1-on-esp.patch
Normal file
@ -0,0 +1,396 @@
|
||||
From 6444774dae24f439dae3b4bc8d73449d50f06240 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Thu, 31 Dec 2020 21:54:07 +0800
|
||||
Subject: [PATCH] install: fix software raid1 on esp
|
||||
|
||||
While running grub-install on an efi system where efi system partition
|
||||
is configured as mdadm software raid1, it fails with errors like this:
|
||||
|
||||
grub2-install: info: copying `/boot/grub2/x86_64-efi/core.efi' -> `/boot/efi/EFI/opensuse/grubx64.efi'.
|
||||
grub2-install: info: Registering with EFI: distributor = `opensuse', path = `\EFI\opensuse\grubx64.efi', ESP at mduuid/9182c46b9d469f79b48850b68f3371a5.
|
||||
grub2-install: info: executing efibootmgr --version </dev/null >/dev/null.
|
||||
grub2-install: info: executing modprobe -q efivars.
|
||||
grub2-install: info: executing efibootmgr -c -d.
|
||||
efibootmgr: option requires an argument -- 'd'
|
||||
efibootmgr version 14
|
||||
usage: efibootmgr [options]
|
||||
|
||||
This should work with mdadm raid1 with metadata 0.9 and 1.0 whose
|
||||
superblocks are at the end of device. However
|
||||
grub_install_register_efi() doesn't seem to work if the target is
|
||||
multiple devices so that it errors out.
|
||||
|
||||
The patch changes grub_install_register_efi() to accept multiple devices
|
||||
that can be used to creating efi boot entries for probed raid1 member
|
||||
devices on mounted efi system partition.
|
||||
|
||||
This patch also adds check for metadata 0.9 or 1.0 or the validation
|
||||
will fail to continue the install.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/disk/diskfilter.c | 27 +++----
|
||||
grub-core/disk/mdraid1x_linux.c | 3 +
|
||||
grub-core/osdep/basic/no_platform.c | 3 +-
|
||||
grub-core/osdep/unix/platform.c | 57 +++++++++++----
|
||||
grub-core/osdep/windows/platform.c | 3 +-
|
||||
include/grub/diskfilter.h | 3 +-
|
||||
include/grub/util/install.h | 5 +-
|
||||
util/grub-install.c | 107 ++++++++++++++++++++++++++--
|
||||
8 files changed, 171 insertions(+), 37 deletions(-)
|
||||
|
||||
--- a/grub-core/disk/diskfilter.c
|
||||
+++ b/grub-core/disk/diskfilter.c
|
||||
@@ -159,8 +159,8 @@
|
||||
for (m = arr->pvs; m; m = m->next)
|
||||
if (m->disk && m->disk->id == disk->id
|
||||
&& m->disk->dev->id == disk->dev->id
|
||||
- && m->part_start == grub_partition_get_start (disk->partition)
|
||||
- && m->part_size == grub_disk_native_sectors (disk))
|
||||
+ && grub_partition_get_start (m->disk->partition) == grub_partition_get_start (disk->partition)
|
||||
+ && grub_disk_native_sectors (m->disk) == grub_disk_native_sectors (disk))
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1340,19 +1340,23 @@
|
||||
? (grub_memcmp (pv->id.uuid, id->uuid, id->uuidlen) == 0)
|
||||
: (pv->id.id == id->id))
|
||||
{
|
||||
+ char *part_name = NULL;
|
||||
struct grub_diskfilter_lv *lv;
|
||||
/* FIXME: Check whether the update time of the superblocks are
|
||||
the same. */
|
||||
- if (pv->disk && grub_disk_native_sectors (disk) >= pv->part_size)
|
||||
+ if (pv->disk && grub_disk_native_sectors (disk) >= grub_disk_native_sectors (pv->disk))
|
||||
return GRUB_ERR_NONE;
|
||||
- pv->disk = grub_disk_open (disk->name);
|
||||
+ if (disk->partition)
|
||||
+ {
|
||||
+ char *p = grub_partition_get_name (disk->partition);
|
||||
+ if (p)
|
||||
+ part_name = grub_xasprintf ("%s,%s", disk->name, p);
|
||||
+ grub_free (p);
|
||||
+ }
|
||||
+ pv->disk = grub_disk_open (part_name ? : disk->name);
|
||||
+ grub_free (part_name);
|
||||
if (!pv->disk)
|
||||
return grub_errno;
|
||||
- /* This could happen to LVM on RAID, pv->disk points to the
|
||||
- raid device, we shouldn't change it. */
|
||||
- pv->start_sector -= pv->part_start;
|
||||
- pv->part_start = grub_partition_get_start (disk->partition);
|
||||
- pv->part_size = grub_disk_native_sectors (disk);
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
{
|
||||
@@ -1369,7 +1373,6 @@
|
||||
#endif
|
||||
if (start_sector != (grub_uint64_t)-1)
|
||||
pv->start_sector = start_sector;
|
||||
- pv->start_sector += pv->part_start;
|
||||
/* Add the device to the array. */
|
||||
for (lv = array->lvs; lv; lv = lv->next)
|
||||
if (!lv->became_readable_at && lv->fullname && is_lv_readable (lv, 0))
|
||||
@@ -1457,8 +1460,8 @@
|
||||
{
|
||||
if (pv->disk && pv->disk->id == disk->id
|
||||
&& pv->disk->dev->id == disk->dev->id
|
||||
- && pv->part_start == grub_partition_get_start (disk->partition)
|
||||
- && pv->part_size == grub_disk_native_sectors (disk))
|
||||
+ && grub_partition_get_start (pv->disk->partition) == grub_partition_get_start (disk->partition)
|
||||
+ && grub_disk_native_sectors (pv->disk) == grub_disk_native_sectors (disk))
|
||||
{
|
||||
if (vg_out)
|
||||
*vg_out = vg;
|
||||
--- a/grub-core/disk/mdraid1x_linux.c
|
||||
+++ b/grub-core/disk/mdraid1x_linux.c
|
||||
@@ -208,6 +208,9 @@
|
||||
grub_le_to_cpu32 (sb.chunksize),
|
||||
grub_le_to_cpu32 (sb.layout),
|
||||
grub_le_to_cpu32 (sb.level));
|
||||
+#ifdef GRUB_UTIL
|
||||
+ array->mdraid1x_minor_version = minor_version;
|
||||
+#endif
|
||||
|
||||
return array;
|
||||
}
|
||||
--- a/grub-core/osdep/basic/no_platform.c
|
||||
+++ b/grub-core/osdep/basic/no_platform.c
|
||||
@@ -33,7 +33,8 @@
|
||||
void
|
||||
grub_install_register_efi (grub_device_t efidir_grub_dev,
|
||||
const char *efifile_path,
|
||||
- const char *efi_distributor)
|
||||
+ const char *efi_distributor,
|
||||
+ const char *force_disk)
|
||||
{
|
||||
grub_util_error ("%s", _("no EFI routines are available for your platform"));
|
||||
}
|
||||
--- a/grub-core/osdep/unix/platform.c
|
||||
+++ b/grub-core/osdep/unix/platform.c
|
||||
@@ -132,15 +132,14 @@
|
||||
}
|
||||
|
||||
int
|
||||
-grub_install_register_efi (grub_device_t efidir_grub_dev,
|
||||
+grub_install_register_efi (const grub_disk_t *efidir_grub_disk,
|
||||
const char *efifile_path,
|
||||
- const char *efi_distributor)
|
||||
+ const char *efi_distributor,
|
||||
+ const char *force_disk)
|
||||
{
|
||||
- const char * efidir_disk;
|
||||
- int efidir_part;
|
||||
int ret;
|
||||
- efidir_disk = grub_util_biosdisk_get_osdev (efidir_grub_dev->disk);
|
||||
- efidir_part = efidir_grub_dev->disk->partition ? efidir_grub_dev->disk->partition->number + 1 : 1;
|
||||
+ const grub_disk_t *curdisk;
|
||||
+ int ndev = 0;
|
||||
|
||||
if (grub_util_exec_redirect_null ((const char * []){ "efibootmgr", "--version", NULL }))
|
||||
{
|
||||
@@ -158,22 +157,50 @@
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
- char *efidir_part_str = xasprintf ("%d", efidir_part);
|
||||
+ for (curdisk = efidir_grub_disk; *curdisk; curdisk++)
|
||||
+ ndev++;
|
||||
|
||||
- if (!verbosity)
|
||||
- ret = grub_util_exec ((const char * []){ "efibootmgr", "-q",
|
||||
+ for (curdisk = efidir_grub_disk; *curdisk; curdisk++)
|
||||
+ {
|
||||
+ const char * efidir_disk;
|
||||
+ int efidir_part;
|
||||
+ char *efidir_part_str;
|
||||
+ char *new_efi_distributor = NULL;
|
||||
+ grub_disk_t disk = *curdisk;
|
||||
+
|
||||
+ efidir_disk = force_disk ? : grub_util_biosdisk_get_osdev (disk);
|
||||
+ if (!efidir_disk)
|
||||
+ grub_util_error (_("%s: no device for efi"), disk->name);
|
||||
+
|
||||
+ efidir_part = disk->partition ? disk->partition->number + 1 : 1;
|
||||
+ efidir_part_str = xasprintf ("%d", efidir_part);
|
||||
+ if (ndev > 1)
|
||||
+ {
|
||||
+ const char *p = grub_strrchr (efidir_disk, '/');
|
||||
+ new_efi_distributor = xasprintf ("%s (%s%d)\n",
|
||||
+ efi_distributor,
|
||||
+ p ? p + 1: efidir_disk,
|
||||
+ efidir_part);
|
||||
+ }
|
||||
+
|
||||
+ if (!verbosity)
|
||||
+ ret = grub_util_exec ((const char * []){ "efibootmgr", "-q",
|
||||
"-c", "-d", efidir_disk,
|
||||
"-p", efidir_part_str, "-w",
|
||||
- "-L", efi_distributor, "-l",
|
||||
+ "-L", new_efi_distributor ? : efi_distributor, "-l",
|
||||
efifile_path, NULL });
|
||||
- else
|
||||
- ret = grub_util_exec ((const char * []){ "efibootmgr",
|
||||
+ else
|
||||
+ ret = grub_util_exec ((const char * []){ "efibootmgr",
|
||||
"-c", "-d", efidir_disk,
|
||||
"-p", efidir_part_str, "-w",
|
||||
- "-L", efi_distributor, "-l",
|
||||
+ "-L", new_efi_distributor ? : efi_distributor, "-l",
|
||||
efifile_path, NULL });
|
||||
- free (efidir_part_str);
|
||||
- return ret;
|
||||
+ free (efidir_part_str);
|
||||
+ free (new_efi_distributor);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+ }
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
void
|
||||
--- a/grub-core/osdep/windows/platform.c
|
||||
+++ b/grub-core/osdep/windows/platform.c
|
||||
@@ -204,7 +204,8 @@
|
||||
int
|
||||
grub_install_register_efi (grub_device_t efidir_grub_dev,
|
||||
const char *efifile_path,
|
||||
- const char *efi_distributor)
|
||||
+ const char *efi_distributor,
|
||||
+ const char *force_disk)
|
||||
{
|
||||
grub_uint16_t *boot_order, *new_boot_order;
|
||||
grub_uint16_t *distributor16;
|
||||
--- a/include/grub/diskfilter.h
|
||||
+++ b/include/grub/diskfilter.h
|
||||
@@ -49,6 +49,7 @@
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
struct grub_diskfilter *driver;
|
||||
+ grub_uint8_t mdraid1x_minor_version;
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -66,8 +67,6 @@
|
||||
/* Optional. */
|
||||
char *name;
|
||||
grub_disk_t disk;
|
||||
- grub_disk_addr_t part_start;
|
||||
- grub_disk_addr_t part_size;
|
||||
grub_disk_addr_t start_sector; /* Sector number where the data area starts. */
|
||||
struct grub_diskfilter_pv *next;
|
||||
/* Optional. */
|
||||
--- a/include/grub/util/install.h
|
||||
+++ b/include/grub/util/install.h
|
||||
@@ -236,9 +236,10 @@
|
||||
grub_install_get_powerpc_secure_boot (void);
|
||||
|
||||
int
|
||||
-grub_install_register_efi (grub_device_t efidir_grub_dev,
|
||||
+grub_install_register_efi (const grub_disk_t *efidir_grub_disk,
|
||||
const char *efifile_path,
|
||||
- const char *efi_distributor);
|
||||
+ const char *efi_distributor,
|
||||
+ const char *force_disk);
|
||||
|
||||
void
|
||||
grub_install_register_ieee1275 (int is_prep, const char *install_device,
|
||||
--- a/util/grub-install.c
|
||||
+++ b/util/grub-install.c
|
||||
@@ -1719,6 +1719,40 @@
|
||||
}
|
||||
}
|
||||
prefix_drive = xasprintf ("(%s)", grub_drives[0]);
|
||||
+
|
||||
+ if (platform == GRUB_INSTALL_PLATFORM_X86_64_EFI
|
||||
+ && grub_dev->disk
|
||||
+ && grub_dev->disk->partition
|
||||
+ && grub_fs->fs_uuid)
|
||||
+ {
|
||||
+ int raid_level;
|
||||
+ char *uuid = NULL;
|
||||
+ char *escaped_relpath = NULL;
|
||||
+
|
||||
+ raid_level = probe_raid_level (grub_dev->disk);
|
||||
+ if (raid_level != 1)
|
||||
+ goto out;
|
||||
+
|
||||
+ escaped_relpath = escape (relative_grubdir);
|
||||
+ if (!escaped_relpath)
|
||||
+ goto out;
|
||||
+
|
||||
+ if (grub_fs->fs_uuid (grub_dev, &uuid) || !uuid)
|
||||
+ {
|
||||
+ grub_print_error ();
|
||||
+ grub_errno = 0;
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ if (!load_cfg_f)
|
||||
+ load_cfg_f = grub_util_fopen (load_cfg, "wb");
|
||||
+ have_load_cfg = 1;
|
||||
+ fprintf (load_cfg_f, "search --no-floppy --fs-uuid --set=root --hint='%s' %s\n", grub_drives[0], uuid);
|
||||
+ fprintf (load_cfg_f, "set prefix=($root)'%s'\n", escaped_relpath);
|
||||
+ grub_install_push_module ("search");
|
||||
+ out:
|
||||
+ grub_free (escaped_relpath);
|
||||
+ }
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
@@ -2258,9 +2292,13 @@
|
||||
{
|
||||
/* Try to make this image bootable using the EFI Boot Manager, if available. */
|
||||
int ret;
|
||||
- ret = grub_install_register_efi (efidir_grub_dev,
|
||||
+ grub_disk_t efidir_grub_disk[2];
|
||||
+ efidir_grub_disk[0] = efidir_grub_dev->disk;
|
||||
+ efidir_grub_disk[1] = NULL;
|
||||
+ ret = grub_install_register_efi (efidir_grub_disk,
|
||||
"\\System\\Library\\CoreServices",
|
||||
- efi_distributor);
|
||||
+ efi_distributor,
|
||||
+ NULL);
|
||||
if (ret)
|
||||
grub_util_error (_("efibootmgr failed to register the boot entry: %s"),
|
||||
strerror (ret));
|
||||
@@ -2314,7 +2352,11 @@
|
||||
{
|
||||
char * efifile_path;
|
||||
char * part;
|
||||
+ int raid_level;
|
||||
int ret;
|
||||
+ grub_disk_t *efidir_grub_disk;
|
||||
+ grub_disk_memberlist_t list = NULL, cur;
|
||||
+ char * force_disk = NULL;
|
||||
|
||||
/* Try to make this image bootable using the EFI Boot Manager, if available. */
|
||||
if (!efi_distributor || efi_distributor[0] == '\0')
|
||||
@@ -2331,8 +2373,65 @@
|
||||
efidir_grub_dev->disk->name,
|
||||
(part ? ",": ""), (part ? : ""));
|
||||
grub_free (part);
|
||||
- ret = grub_install_register_efi (efidir_grub_dev,
|
||||
- efifile_path, efi_distributor);
|
||||
+
|
||||
+ raid_level = probe_raid_level (efidir_grub_dev->disk);
|
||||
+ if (raid_level >= 0 && raid_level != 1)
|
||||
+ grub_util_warn (_("unsupported raid level %d detected for efi system partition"), raid_level);
|
||||
+ if (raid_level == 1 && !efidir_grub_dev->disk->partition)
|
||||
+ {
|
||||
+ const char *raidname = NULL;
|
||||
+
|
||||
+ if (efidir_grub_dev->disk->dev->disk_raidname)
|
||||
+ raidname = efidir_grub_dev->disk->dev->disk_raidname (efidir_grub_dev->disk);
|
||||
+ if (raidname
|
||||
+ && (grub_strncmp (raidname, "mdraid09", sizeof ("mdraid09")) == 0
|
||||
+ || (grub_strcmp (raidname, "mdraid1x") == 0
|
||||
+ && ((struct grub_diskfilter_lv *) efidir_grub_dev->disk->data)->vg->mdraid1x_minor_version == 0)))
|
||||
+ {
|
||||
+ if (efidir_grub_dev->disk->dev->disk_memberlist)
|
||||
+ list = efidir_grub_dev->disk->dev->disk_memberlist (efidir_grub_dev->disk);
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ grub_util_warn (_("this array has metadata at the start and may not be suitable as a efi system partition."
|
||||
+ " please ensure that your firmware understands md/v1.x metadata, or use --metadata=0.90"
|
||||
+ " to create the array."));
|
||||
+ /* Try to continue regardless metadata, nothing to lose here */
|
||||
+ if (efidir_grub_dev->disk->dev->disk_memberlist)
|
||||
+ list = efidir_grub_dev->disk->dev->disk_memberlist (efidir_grub_dev->disk);
|
||||
+ }
|
||||
+ }
|
||||
+ else if (raid_level == 1)
|
||||
+ force_disk = grub_util_get_os_disk (install_device);
|
||||
+ if (list)
|
||||
+ {
|
||||
+ int i;
|
||||
+ int ndisk = 0;
|
||||
+
|
||||
+ for (cur = list; cur; cur = cur->next)
|
||||
+ ++ndisk;
|
||||
+ efidir_grub_disk = xcalloc (ndisk + 1, sizeof (*efidir_grub_disk));
|
||||
+ for (cur = list, i = 0; i < ndisk; cur = cur->next, i++)
|
||||
+ efidir_grub_disk[i] = cur->disk;
|
||||
+ efidir_grub_disk[ndisk] = NULL;
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ efidir_grub_disk = xcalloc (2, sizeof (*efidir_grub_disk));
|
||||
+ efidir_grub_disk[0] = efidir_grub_dev->disk;
|
||||
+ efidir_grub_disk[1] = NULL;
|
||||
+ }
|
||||
+ ret = grub_install_register_efi (efidir_grub_disk,
|
||||
+ efifile_path, efi_distributor,
|
||||
+ force_disk);
|
||||
+ while (list)
|
||||
+ {
|
||||
+ cur = list;
|
||||
+ list = list->next;
|
||||
+ grub_free (cur);
|
||||
+ }
|
||||
+ grub_free (force_disk);
|
||||
+ grub_free (efidir_grub_disk);
|
||||
if (ret)
|
||||
grub_util_error (_("efibootmgr failed to register the boot entry: %s"),
|
||||
strerror (ret));
|
||||
109
0001-kern-mm.c-Make-grub_calloc-inline.patch
Normal file
109
0001-kern-mm.c-Make-grub_calloc-inline.patch
Normal file
@ -0,0 +1,109 @@
|
||||
From c2475f1337dff2e2a3e45514119d5186e55753c1 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Thu, 13 Aug 2020 09:36:45 +0800
|
||||
Subject: [PATCH] kern/mm.c : Make grub_calloc inline
|
||||
|
||||
To circumvent the situation that symbol 'grub_calloc' not found would
|
||||
happen if system is using stray grub (ie not managed by system update)
|
||||
as stage1 that can be too old to load updated modules.
|
||||
---
|
||||
grub-core/kern/mm.c | 28 ----------------------------
|
||||
include/grub/mm.h | 32 +++++++++++++++++++++++++++++++-
|
||||
2 files changed, 31 insertions(+), 29 deletions(-)
|
||||
|
||||
--- a/grub-core/kern/mm.c
|
||||
+++ b/grub-core/kern/mm.c
|
||||
@@ -63,14 +63,10 @@
|
||||
|
||||
#include <config.h>
|
||||
#include <grub/mm.h>
|
||||
-#include <grub/misc.h>
|
||||
-#include <grub/err.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/dl.h>
|
||||
-#include <grub/i18n.h>
|
||||
#include <grub/mm_private.h>
|
||||
-#include <grub/safemath.h>
|
||||
|
||||
#ifdef MM_DEBUG
|
||||
# undef grub_calloc
|
||||
@@ -553,30 +549,6 @@
|
||||
return 0;
|
||||
}
|
||||
|
||||
-/*
|
||||
- * Allocate NMEMB instances of SIZE bytes and return the pointer, or error on
|
||||
- * integer overflow.
|
||||
- */
|
||||
-void *
|
||||
-grub_calloc (grub_size_t nmemb, grub_size_t size)
|
||||
-{
|
||||
- void *ret;
|
||||
- grub_size_t sz = 0;
|
||||
-
|
||||
- if (grub_mul (nmemb, size, &sz))
|
||||
- {
|
||||
- grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected"));
|
||||
- return NULL;
|
||||
- }
|
||||
-
|
||||
- ret = grub_memalign (0, sz);
|
||||
- if (!ret)
|
||||
- return NULL;
|
||||
-
|
||||
- grub_memset (ret, 0, sz);
|
||||
- return ret;
|
||||
-}
|
||||
-
|
||||
/* Allocate SIZE bytes and return the pointer. */
|
||||
void *
|
||||
grub_malloc (grub_size_t size)
|
||||
--- a/include/grub/mm.h
|
||||
+++ b/include/grub/mm.h
|
||||
@@ -47,7 +47,6 @@
|
||||
#endif
|
||||
|
||||
void grub_mm_init_region (void *addr, grub_size_t size);
|
||||
-void *EXPORT_FUNC(grub_calloc) (grub_size_t nmemb, grub_size_t size);
|
||||
void *EXPORT_FUNC(grub_malloc) (grub_size_t size);
|
||||
void *EXPORT_FUNC(grub_zalloc) (grub_size_t size);
|
||||
void EXPORT_FUNC(grub_free) (void *ptr);
|
||||
@@ -55,6 +54,37 @@
|
||||
#ifndef GRUB_MACHINE_EMU
|
||||
void *EXPORT_FUNC(grub_memalign) (grub_size_t align, grub_size_t size);
|
||||
#endif
|
||||
+#if !defined(GRUB_UTIL) && !defined (GRUB_MACHINE_EMU)
|
||||
+#include <grub/misc.h>
|
||||
+#include <grub/err.h>
|
||||
+#include <grub/i18n.h>
|
||||
+#include <grub/safemath.h>
|
||||
+/*
|
||||
+ * Allocate NMEMB instances of SIZE bytes and return the pointer, or error on
|
||||
+ * integer overflow.
|
||||
+ */
|
||||
+static inline void *
|
||||
+grub_calloc (grub_size_t nmemb, grub_size_t size)
|
||||
+{
|
||||
+ void *ret;
|
||||
+ grub_size_t sz = 0;
|
||||
+
|
||||
+ if (grub_mul (nmemb, size, &sz))
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected"));
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ ret = grub_memalign (0, sz);
|
||||
+ if (!ret)
|
||||
+ return NULL;
|
||||
+
|
||||
+ grub_memset (ret, 0, sz);
|
||||
+ return ret;
|
||||
+}
|
||||
+#else
|
||||
+void *EXPORT_FUNC(grub_calloc) (grub_size_t nmemb, grub_size_t size);
|
||||
+#endif
|
||||
|
||||
void grub_mm_check_real (const char *file, int line);
|
||||
#define grub_mm_check() grub_mm_check_real (GRUB_FILE, __LINE__);
|
||||
@ -1,7 +1,8 @@
|
||||
From 69edb31205602c29293a8c6e67363bba2a4a1e66 Mon Sep 17 00:00:00 2001
|
||||
From d683bed5c76c54e6bc5c26eef2f8d7136a3c75c4 Mon Sep 17 00:00:00 2001
|
||||
From: Ard Biesheuvel <ardb@kernel.org>
|
||||
Date: Thu, 11 Aug 2022 16:51:57 +0200
|
||||
Subject: loader/arm64/linux: Remove magic number header field check
|
||||
Subject: [PATCH] loader/arm64/efi/linux: Remove magic number header field
|
||||
check
|
||||
|
||||
The "ARM\x64" magic number in the file header identifies an image as one
|
||||
that implements the bare metal boot protocol, allowing the loader to
|
||||
@ -17,21 +18,18 @@ bare metal boot protocol.
|
||||
|
||||
So drop the magic number check.
|
||||
|
||||
Reference:https://git.savannah.gnu.org/cgit/grub.git/commit?id=69edb31205602c29293a8c6e67363bba2a4a1e66
|
||||
Conflict:NA
|
||||
|
||||
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
|
||||
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
||||
---
|
||||
grub-core/loader/arm64/linux.c | 3 ---
|
||||
grub-core/loader/arm64/efi/linux.c | 3 ---
|
||||
1 file changed, 3 deletions(-)
|
||||
|
||||
diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
|
||||
index d2af47c..c6db843 100644
|
||||
--- a/grub-core/loader/arm64/linux.c
|
||||
+++ b/grub-core/loader/arm64/linux.c
|
||||
@@ -55,9 +55,6 @@ static grub_addr_t initrd_end;
|
||||
grub_err_t
|
||||
diff --git a/grub-core/loader/arm64/efi/linux.c b/grub-core/loader/arm64/efi/linux.c
|
||||
index 33df0e1fd..a9f5e05e4 100644
|
||||
--- a/grub-core/loader/arm64/efi/linux.c
|
||||
+++ b/grub-core/loader/arm64/efi/linux.c
|
||||
@@ -57,9 +57,6 @@ static grub_addr_t initrd_end;
|
||||
static grub_err_t
|
||||
grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh)
|
||||
{
|
||||
- if (lh->magic != GRUB_LINUX_ARMXX_MAGIC_SIGNATURE)
|
||||
@ -41,5 +39,5 @@ index d2af47c..c6db843 100644
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
N_("plain image kernel not supported - rebuild with CONFIG_(U)EFI_STUB enabled"));
|
||||
--
|
||||
2.19.1
|
||||
2.43.0
|
||||
|
||||
142
0001-luks2-Use-grub-tpm2-token-for-TPM2-protected-volume-.patch
Normal file
142
0001-luks2-Use-grub-tpm2-token-for-TPM2-protected-volume-.patch
Normal file
@ -0,0 +1,142 @@
|
||||
From 06af22d6c893b0249712e9a486e0cbae15160e5c Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Mon, 23 Oct 2023 16:11:53 +0800
|
||||
Subject: [PATCH] luks2: Use grub-tpm2 token for TPM2-protected volume unlock
|
||||
|
||||
This commit enables the use of the grub-tpm2 token for unlocking LUKS2
|
||||
volumes protected by TPM2. The token tracks keyslots associated with a
|
||||
sealed key, making the unsealing process more efficient and secure.
|
||||
|
||||
Signed-Off-by Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/disk/luks2.c | 81 ++++++++++++++++++++++++++++++++++++++++--
|
||||
1 file changed, 79 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c
|
||||
index d5106402f..fe5ba777a 100644
|
||||
--- a/grub-core/disk/luks2.c
|
||||
+++ b/grub-core/disk/luks2.c
|
||||
@@ -124,6 +124,14 @@ struct grub_luks2_digest
|
||||
};
|
||||
typedef struct grub_luks2_digest grub_luks2_digest_t;
|
||||
|
||||
+struct grub_luks2_token_tpm
|
||||
+{
|
||||
+ grub_uint64_t idx;
|
||||
+ grub_uint64_t keyslots;
|
||||
+ const char *timestamp;
|
||||
+};
|
||||
+typedef struct grub_luks2_token_tpm grub_luks2_token_tpm_t;
|
||||
+
|
||||
gcry_err_code_t AF_merge (const gcry_md_spec_t * hash, grub_uint8_t * src,
|
||||
grub_uint8_t * dst, grub_size_t blocksize,
|
||||
grub_size_t blocknumbers);
|
||||
@@ -257,6 +265,39 @@ luks2_parse_digest (grub_luks2_digest_t *out, const grub_json_t *digest)
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
+static grub_err_t
|
||||
+luks2_parse_token_tpm (grub_luks2_token_tpm_t *out, const grub_json_t *token)
|
||||
+{
|
||||
+ grub_json_t keyslots, o;
|
||||
+ grub_size_t i, size;
|
||||
+ grub_uint64_t bit;
|
||||
+ const char *type;
|
||||
+
|
||||
+ if (grub_json_getstring (&type, token, "type"))
|
||||
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid token type");
|
||||
+ else if (grub_strcmp (type, "grub-tpm2"))
|
||||
+ return GRUB_ERR_NONE;
|
||||
+
|
||||
+ if (grub_json_getvalue (&keyslots, token, "keyslots") ||
|
||||
+ grub_json_getstring (&out->timestamp, token, "timestamp"))
|
||||
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "Missing token parameters");
|
||||
+
|
||||
+ if (grub_json_getsize (&size, &keyslots))
|
||||
+ return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
+ "Token references no keyslots");
|
||||
+
|
||||
+ out->keyslots = 0;
|
||||
+ for (i = 0; i < size; i++)
|
||||
+ {
|
||||
+ if (grub_json_getchild (&o, &keyslots, i) ||
|
||||
+ grub_json_getuint64 (&bit, &o, NULL))
|
||||
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid keyslot");
|
||||
+ out->keyslots |= (1 << bit);
|
||||
+ }
|
||||
+
|
||||
+ return GRUB_ERR_NONE;
|
||||
+}
|
||||
+
|
||||
static grub_err_t
|
||||
luks2_get_keyslot (grub_luks2_keyslot_t *k, grub_luks2_digest_t *d, grub_luks2_segment_t *s,
|
||||
const grub_json_t *root, grub_size_t keyslot_json_idx)
|
||||
@@ -561,13 +602,14 @@ luks2_recover_key (grub_disk_t source,
|
||||
{
|
||||
grub_uint8_t candidate_key[GRUB_CRYPTODISK_MAX_KEYLEN];
|
||||
char cipher[32], *json_header = NULL, *ptr;
|
||||
- grub_size_t candidate_key_len = 0, json_idx, size;
|
||||
+ grub_size_t candidate_key_len = 0, json_idx, size, tsize;
|
||||
grub_luks2_header_t header;
|
||||
grub_luks2_keyslot_t keyslot;
|
||||
grub_luks2_digest_t digest;
|
||||
grub_luks2_segment_t segment;
|
||||
+ grub_luks2_token_tpm_t token_tpm;
|
||||
gcry_err_code_t gcry_ret;
|
||||
- grub_json_t *json = NULL, keyslots;
|
||||
+ grub_json_t *json = NULL, keyslots, tokens;
|
||||
grub_err_t ret;
|
||||
|
||||
if (cargs->key_data == NULL || cargs->key_len == 0)
|
||||
@@ -605,6 +647,37 @@ luks2_recover_key (grub_disk_t source,
|
||||
goto err;
|
||||
}
|
||||
|
||||
+ token_tpm.keyslots = 0;
|
||||
+ tsize = 0;
|
||||
+ if (cargs->protectors)
|
||||
+ {
|
||||
+ int i;
|
||||
+ for (i = 0; cargs->protectors[i]; i++)
|
||||
+ if (grub_strcmp(cargs->protectors[i], "tpm2") == 0)
|
||||
+ break;
|
||||
+
|
||||
+ if (!cargs->protectors[i] ||
|
||||
+ cargs->key_cache[i].invalid ||
|
||||
+ grub_json_getvalue (&tokens, json, "tokens") ||
|
||||
+ grub_json_getsize (&tsize, &tokens))
|
||||
+ grub_dprintf ("luks2", "No valid token or not a tpm2 protector\n");
|
||||
+ }
|
||||
+
|
||||
+ for (json_idx = 0; json_idx < tsize; json_idx++)
|
||||
+ {
|
||||
+ grub_json_t token;
|
||||
+
|
||||
+ if (grub_json_getchild (&token, &tokens, json_idx) ||
|
||||
+ grub_json_getuint64 (&token_tpm.idx, &token, NULL) ||
|
||||
+ grub_json_getchild (&token, &token, 0) ||
|
||||
+ luks2_parse_token_tpm (&token_tpm, &token))
|
||||
+ {
|
||||
+ grub_dprintf ("luks2", "Could not parse token index %" PRIuGRUB_SIZE "\n", json_idx);
|
||||
+ grub_errno = GRUB_ERR_NONE;
|
||||
+ continue;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
if (grub_disk_native_sectors (source) == GRUB_DISK_SIZE_UNKNOWN)
|
||||
{
|
||||
/* FIXME: Allow use of source disk, and maybe cause errors in read. */
|
||||
@@ -641,6 +714,10 @@ luks2_recover_key (grub_disk_t source,
|
||||
continue;
|
||||
}
|
||||
|
||||
+ if (token_tpm.keyslots &&
|
||||
+ !(token_tpm.keyslots & (1 << keyslot.idx)))
|
||||
+ continue;
|
||||
+
|
||||
grub_dprintf ("luks2", "Trying keyslot \"%" PRIuGRUB_UINT64_T "\"\n", keyslot.idx);
|
||||
|
||||
/* Sector size should be one of 512, 1024, 2048, or 4096. */
|
||||
--
|
||||
2.42.0
|
||||
|
||||
238
0001-ofdisk-enhance-boot-time-by-focusing-on-boot-disk-re.patch
Normal file
238
0001-ofdisk-enhance-boot-time-by-focusing-on-boot-disk-re.patch
Normal file
@ -0,0 +1,238 @@
|
||||
From b353ca96bf002a9262fdf74637f39615d003d069 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Fri, 8 Dec 2023 11:51:57 +0800
|
||||
Subject: [PATCH 1/2] ofdisk: enhance boot time by focusing on boot disk
|
||||
relevance
|
||||
|
||||
After a historical review, it's clear that a boot delay regression
|
||||
coincided with the introduction of the fcp iterating patch. Reverting
|
||||
this patch has shown promising signs in mitigating the issue. In order
|
||||
to improve the efficiency, a more refined discovery process is proposed,
|
||||
aiming to exclude device types differing from the boot disk to curtail
|
||||
unnecessary iterations.
|
||||
|
||||
This patch extends prior efforts by exclusively targeting root device
|
||||
discovery linked to the boot disk, verifying device types to prevent
|
||||
process elongation.
|
||||
|
||||
It is worth noting that grub's opportunistic approach to assembling the
|
||||
root device, seeking accessible results in parallel during iteration,
|
||||
sometimes allows even a partially assembled RAID, albeit in a degraded
|
||||
mode. However, delays stem from unrelated devices appearing before the
|
||||
actual boot device.
|
||||
|
||||
To streamline the boot process, the patch utilizes parent nodes in
|
||||
conjunction with block device nodes to extract essential boot-related
|
||||
information. This refined identification method efficiently limits the
|
||||
application's scope to devices connected to the chosen boot device,
|
||||
notably optimizing subsequent device iteration. By adeptly filtering out
|
||||
devices not linked to the same FCP (Fibre Channel Protocol) device, it
|
||||
significantly enhances boot efficiency, ensuring a more streamlined and
|
||||
efficient boot process.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/disk/ieee1275/ofdisk.c | 136 +++++++++++++++++++++++++++++--
|
||||
1 file changed, 131 insertions(+), 5 deletions(-)
|
||||
|
||||
--- a/grub-core/disk/ieee1275/ofdisk.c
|
||||
+++ b/grub-core/disk/ieee1275/ofdisk.c
|
||||
@@ -31,6 +31,13 @@
|
||||
static char *last_devpath;
|
||||
static grub_ieee1275_ihandle_t last_ihandle;
|
||||
|
||||
+#define IEEE1275_DISK_ALIAS "/disk@"
|
||||
+#define IEEE1275_NVMEOF_DISK_ALIAS "/nvme-of/controller@"
|
||||
+
|
||||
+static char *boot_type;
|
||||
+static char *boot_parent;
|
||||
+static int is_boot_nvmeof;
|
||||
+
|
||||
struct ofdisk_hash_ent
|
||||
{
|
||||
char *devpath;
|
||||
@@ -529,12 +536,21 @@
|
||||
{
|
||||
if (grub_strcmp (alias->type, "fcp") == 0)
|
||||
{
|
||||
- // Iterate disks
|
||||
- dev_iterate_fcp_disks(alias);
|
||||
-
|
||||
- // Iterate NVMeoF
|
||||
- dev_iterate_fcp_nvmeof(alias);
|
||||
+ if (boot_type &&
|
||||
+ grub_strcmp (boot_type, alias->type) != 0)
|
||||
+ {
|
||||
+ grub_dprintf ("ofdisk", "Skipped device: %s, type %s did not match boot_type %s\n",
|
||||
+ alias->path, alias->type, boot_type);
|
||||
+ goto iter_children;
|
||||
+ }
|
||||
|
||||
+ if (grub_strcmp (boot_parent, alias->path) == 0)
|
||||
+ {
|
||||
+ if (is_boot_nvmeof)
|
||||
+ dev_iterate_fcp_nvmeof(alias);
|
||||
+ else
|
||||
+ dev_iterate_fcp_disks(alias);
|
||||
+ }
|
||||
}
|
||||
else if (grub_strcmp (alias->type, "vscsi") == 0)
|
||||
{
|
||||
@@ -552,6 +568,14 @@
|
||||
char *buf, *bufptr;
|
||||
unsigned i;
|
||||
|
||||
+ if (boot_type &&
|
||||
+ grub_strcmp (boot_type, alias->type) != 0)
|
||||
+ {
|
||||
+ grub_dprintf ("ofdisk", "Skipped device: %s, type %s did not match boot_type %s\n",
|
||||
+ alias->path, alias->type, boot_type);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
if (grub_ieee1275_open (alias->path, &ihandle))
|
||||
return;
|
||||
|
||||
@@ -615,6 +639,14 @@
|
||||
grub_uint16_t table_size;
|
||||
grub_ieee1275_ihandle_t ihandle;
|
||||
|
||||
+ if (boot_type &&
|
||||
+ grub_strcmp (boot_type, alias->type) != 0)
|
||||
+ {
|
||||
+ grub_dprintf ("ofdisk", "Skipped device: %s, type %s did not match boot_type %s\n",
|
||||
+ alias->path, alias->type, boot_type);
|
||||
+ goto iter_children;
|
||||
+ }
|
||||
+
|
||||
buf = grub_malloc (grub_strlen (alias->path) +
|
||||
sizeof ("/disk@7766554433221100"));
|
||||
if (!buf)
|
||||
@@ -674,6 +706,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
+ iter_children:
|
||||
{
|
||||
struct grub_ieee1275_devalias child;
|
||||
|
||||
@@ -1046,6 +1079,68 @@
|
||||
.next = 0
|
||||
};
|
||||
|
||||
+static char *
|
||||
+get_parent_devname (const char *devname, int *is_nvmeof)
|
||||
+{
|
||||
+ char *parent, *pptr;
|
||||
+
|
||||
+ if (is_nvmeof)
|
||||
+ *is_nvmeof = 0;
|
||||
+
|
||||
+ parent = grub_strdup (devname);
|
||||
+
|
||||
+ if (parent == NULL)
|
||||
+ {
|
||||
+ grub_print_error ();
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ pptr = grub_strstr (parent, IEEE1275_DISK_ALIAS);
|
||||
+
|
||||
+ if (pptr != NULL)
|
||||
+ {
|
||||
+ *pptr = '\0';
|
||||
+ return parent;
|
||||
+ }
|
||||
+
|
||||
+ pptr = grub_strstr (parent, IEEE1275_NVMEOF_DISK_ALIAS);
|
||||
+
|
||||
+ if (pptr != NULL)
|
||||
+ {
|
||||
+ *pptr = '\0';
|
||||
+ if (is_nvmeof)
|
||||
+ *is_nvmeof = 1;
|
||||
+ return parent;
|
||||
+ }
|
||||
+
|
||||
+ return parent;
|
||||
+}
|
||||
+
|
||||
+static char *
|
||||
+get_boot_device_parent (const char *bootpath, int *is_nvmeof)
|
||||
+{
|
||||
+ char *dev, *canon, *parent;
|
||||
+
|
||||
+ dev = grub_ieee1275_get_aliasdevname (bootpath);
|
||||
+ canon = grub_ieee1275_canonicalise_devname (dev);
|
||||
+
|
||||
+ if (!canon)
|
||||
+ {
|
||||
+ /* This should not happen. */
|
||||
+ grub_error (GRUB_ERR_BAD_DEVICE, "canonicalise devname failed");
|
||||
+ grub_print_error ();
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ else
|
||||
+ grub_dprintf ("ofdisk", "%s is canonical %s\n", bootpath, canon);
|
||||
+
|
||||
+ parent = get_parent_devname (canon, is_nvmeof);
|
||||
+ grub_dprintf ("ofdisk", "%s is parent of %s\n", parent, canon);
|
||||
+
|
||||
+ grub_free (canon);
|
||||
+ return parent;
|
||||
+}
|
||||
+
|
||||
static void
|
||||
insert_bootpath (void)
|
||||
{
|
||||
@@ -1081,6 +1176,12 @@
|
||||
char *device = grub_ieee1275_get_devname (bootpath);
|
||||
op = ofdisk_hash_add (device, NULL);
|
||||
op->is_boot = 1;
|
||||
+ boot_parent = get_boot_device_parent (bootpath, &is_boot_nvmeof);
|
||||
+ boot_type = grub_ieee1275_get_device_type (boot_parent);
|
||||
+ if (boot_type)
|
||||
+ grub_dprintf ("ofdisk", "the boot device type %s is used for root device discovery, others excluded\n", boot_type);
|
||||
+ else
|
||||
+ grub_dprintf ("ofdisk", "unknown boot device type, will use all devices to discover root and may be slow\n");
|
||||
}
|
||||
grub_free (type);
|
||||
grub_free (bootpath);
|
||||
@@ -1097,12 +1198,37 @@
|
||||
grub_disk_dev_unregister (&grub_ofdisk_dev);
|
||||
}
|
||||
|
||||
+static const char *
|
||||
+grub_env_get_boot_type (struct grub_env_var *var __attribute__ ((unused)),
|
||||
+ const char *val __attribute__ ((unused)))
|
||||
+{
|
||||
+ static char *ret;
|
||||
+
|
||||
+ if (!ret)
|
||||
+ ret = grub_xasprintf("boot: %s type: %s is_nvmeof: %d",
|
||||
+ boot_parent,
|
||||
+ boot_type ? : "unknown",
|
||||
+ is_boot_nvmeof);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static char *
|
||||
+grub_env_set_boot_type (struct grub_env_var *var __attribute__ ((unused)),
|
||||
+ const char *val __attribute__ ((unused)))
|
||||
+{
|
||||
+ /* READ ONLY */
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
void
|
||||
grub_ofdisk_init (void)
|
||||
{
|
||||
grub_disk_firmware_fini = grub_ofdisk_fini;
|
||||
|
||||
insert_bootpath ();
|
||||
+ grub_register_variable_hook ("ofdisk_boot_type", grub_env_get_boot_type,
|
||||
+ grub_env_set_boot_type );
|
||||
|
||||
grub_disk_dev_register (&grub_ofdisk_dev);
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
From b0f9dcabe96e5689ecfba9b6abcd27e685eabd48 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Wed, 11 May 2022 09:56:11 -0400
|
||||
Subject: [PATCH] ofdisk: improve boot time by lookup boot disk first
|
||||
|
||||
While booting lvm, grub will try to build up logical volumes via hooks
|
||||
to disk iteration where on-disk metadata can be read and parsed. However
|
||||
the process can become very slow on multipath as reachable disks are
|
||||
duplicated by multiple I/O paths and they all get inspected.
|
||||
|
||||
Fortunately grub allows lvm to be lazy binding and opportunistic that
|
||||
root volume can be created when it's needed using a smaller set of
|
||||
discovered disks. The disk iteration can also be controlled by pull
|
||||
methods to only returning specified disks. That said we may be able to
|
||||
take advantage of existing design to cause less overhead in lvm
|
||||
construction.
|
||||
|
||||
This patch will return boot disks in OpenFirmware so they can be used
|
||||
first. If lvm managed to create root volume out of those boot disks then
|
||||
it is all very nice as they are readily available. Otherwise disk
|
||||
scanning will be performed to present all discoverable disks to grub as
|
||||
what it was done in the past. The result maybe again time consuming but
|
||||
we have nothing to lose here.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/disk/ieee1275/ofdisk.c | 11 +++++++++--
|
||||
1 file changed, 9 insertions(+), 2 deletions(-)
|
||||
|
||||
--- a/grub-core/disk/ieee1275/ofdisk.c
|
||||
+++ b/grub-core/disk/ieee1275/ofdisk.c
|
||||
@@ -491,10 +491,11 @@
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
- if (pull != GRUB_DISK_PULL_NONE)
|
||||
+ if (pull > GRUB_DISK_PULL_REMOVABLE)
|
||||
return 0;
|
||||
|
||||
- scan ();
|
||||
+ if (pull == GRUB_DISK_PULL_REMOVABLE)
|
||||
+ scan ();
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE (ofdisk_hash); i++)
|
||||
{
|
||||
@@ -532,6 +533,12 @@
|
||||
if (!ent->is_boot && ent->is_removable)
|
||||
continue;
|
||||
|
||||
+ if (pull == GRUB_DISK_PULL_NONE && !ent->is_boot)
|
||||
+ continue;
|
||||
+
|
||||
+ if (pull == GRUB_DISK_PULL_REMOVABLE && ent->is_boot)
|
||||
+ continue;
|
||||
+
|
||||
if (hook (ent->grub_shortest, hook_data))
|
||||
return 1;
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
From 468628bdc39800341e7aa6ff7795cc0d93cfaf3f Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Tue, 11 Apr 2023 10:59:34 +0800
|
||||
Subject: [PATCH 1/2] openfw: Ensure get_devargs and get_devname functions are
|
||||
consistent
|
||||
|
||||
Commit 165c9b234 changed the logic of ieee1275_get_devargs() to use the
|
||||
first or second occurrence of a colon as a separator between device name
|
||||
and arguments. However, this didn't align with the complementary
|
||||
function ieee1275_get_devname, which uses the first occurrence of a
|
||||
colon after the namespace keyword as arguments for the nvme-of device.
|
||||
|
||||
This commit addresses the inconsistency by ensuring that both functions
|
||||
follow a common logic. Now, get_devargs and get_devname functions are
|
||||
consistent with each other, making it easier to understand and maintain
|
||||
the codebase.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/kern/ieee1275/openfw.c | 15 +++++++++------
|
||||
1 file changed, 9 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c
|
||||
index e2ffec32d..3bbd07d95 100644
|
||||
--- a/grub-core/kern/ieee1275/openfw.c
|
||||
+++ b/grub-core/kern/ieee1275/openfw.c
|
||||
@@ -354,13 +354,16 @@ static char *
|
||||
grub_ieee1275_get_devargs (const char *path)
|
||||
{
|
||||
char *colon = grub_strchr (path, ':');
|
||||
- char *colon_check = colon;
|
||||
|
||||
- /* Find the last occurence of colon */
|
||||
- while(colon_check){
|
||||
- colon = colon_check;
|
||||
- colon_check = grub_strchr (colon+1, ':');
|
||||
- }
|
||||
+ /* Use the same logic in grub_ieee1275_get_devname for nvme-of arguments */
|
||||
+ if (grub_strstr(path, "nvme-of"))
|
||||
+ {
|
||||
+ char *namespace_split = grub_strstr(path,"/namespace@");
|
||||
+ if (namespace_split)
|
||||
+ colon = grub_strchr (namespace_split, ':');
|
||||
+ else
|
||||
+ colon = NULL;
|
||||
+ }
|
||||
|
||||
if (! colon)
|
||||
return 0;
|
||||
--
|
||||
2.39.2
|
||||
|
||||
177
0001-protectors-Add-key-protectors-framework.patch
Normal file
177
0001-protectors-Add-key-protectors-framework.patch
Normal file
@ -0,0 +1,177 @@
|
||||
From 5affde982dea827580e36ccc658e439397f51ce8 Mon Sep 17 00:00:00 2001
|
||||
From: Hernan Gatta <hegatta@linux.microsoft.com>
|
||||
Date: Tue, 1 Feb 2022 05:02:53 -0800
|
||||
Subject: [PATCH 1/5] protectors: Add key protectors framework
|
||||
|
||||
A key protector encapsulates functionality to retrieve an unlocking key
|
||||
for a fully-encrypted disk from a specific source. A key protector
|
||||
module registers itself with the key protectors framework when it is
|
||||
loaded and unregisters when unloaded. Additionally, a key protector may
|
||||
accept parameters that describe how it should operate.
|
||||
|
||||
The key protectors framework, besides offering registration and
|
||||
unregistration functions, also offers a one-stop routine for finding and
|
||||
invoking a key protector by name. If a key protector with the specified
|
||||
name exists and if an unlocking key is successfully retrieved by it, the
|
||||
function returns to the caller the retrieved key and its length.
|
||||
|
||||
Signed-off-by: Hernan Gatta <hegatta@linux.microsoft.com>
|
||||
Signed-off-by: Gary Lin <glin@suse.com>
|
||||
---
|
||||
grub-core/Makefile.am | 1 +
|
||||
grub-core/Makefile.core.def | 1 +
|
||||
grub-core/kern/protectors.c | 75 +++++++++++++++++++++++++++++++++++++
|
||||
include/grub/protector.h | 48 ++++++++++++++++++++++++
|
||||
4 files changed, 125 insertions(+)
|
||||
create mode 100644 grub-core/kern/protectors.c
|
||||
create mode 100644 include/grub/protector.h
|
||||
|
||||
--- a/grub-core/Makefile.am
|
||||
+++ b/grub-core/Makefile.am
|
||||
@@ -90,6 +90,7 @@
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/parser.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/partition.h
|
||||
+KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/protector.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/stack_protector.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h
|
||||
--- a/grub-core/Makefile.core.def
|
||||
+++ b/grub-core/Makefile.core.def
|
||||
@@ -149,6 +149,7 @@
|
||||
common = kern/misc.c;
|
||||
common = kern/parser.c;
|
||||
common = kern/partition.c;
|
||||
+ common = kern/protectors.c;
|
||||
common = kern/rescue_parser.c;
|
||||
common = kern/rescue_reader.c;
|
||||
common = kern/term.c;
|
||||
--- /dev/null
|
||||
+++ b/grub-core/kern/protectors.c
|
||||
@@ -0,0 +1,75 @@
|
||||
+/*
|
||||
+ * GRUB -- GRand Unified Bootloader
|
||||
+ * Copyright (C) 2022 Microsoft Corporation
|
||||
+ *
|
||||
+ * GRUB 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 3 of the License, or
|
||||
+ * (at your option) any later version.
|
||||
+ *
|
||||
+ * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
+ */
|
||||
+
|
||||
+#include <grub/list.h>
|
||||
+#include <grub/misc.h>
|
||||
+#include <grub/mm.h>
|
||||
+#include <grub/protector.h>
|
||||
+
|
||||
+struct grub_key_protector *grub_key_protectors = NULL;
|
||||
+
|
||||
+grub_err_t
|
||||
+grub_key_protector_register (struct grub_key_protector *protector)
|
||||
+{
|
||||
+ if (protector == NULL || protector->name == NULL || grub_strlen(protector->name) == 0)
|
||||
+ return GRUB_ERR_BAD_ARGUMENT;
|
||||
+
|
||||
+ if (grub_key_protectors &&
|
||||
+ grub_named_list_find (GRUB_AS_NAMED_LIST (grub_key_protectors),
|
||||
+ protector->name))
|
||||
+ return GRUB_ERR_BAD_ARGUMENT;
|
||||
+
|
||||
+ grub_list_push (GRUB_AS_LIST_P (&grub_key_protectors),
|
||||
+ GRUB_AS_LIST (protector));
|
||||
+
|
||||
+ return GRUB_ERR_NONE;
|
||||
+}
|
||||
+
|
||||
+grub_err_t
|
||||
+grub_key_protector_unregister (struct grub_key_protector *protector)
|
||||
+{
|
||||
+ if (protector == NULL)
|
||||
+ return GRUB_ERR_BAD_ARGUMENT;
|
||||
+
|
||||
+ grub_list_remove (GRUB_AS_LIST (protector));
|
||||
+
|
||||
+ return GRUB_ERR_NONE;
|
||||
+}
|
||||
+
|
||||
+grub_err_t
|
||||
+grub_key_protector_recover_key (const char *protector, grub_uint8_t **key,
|
||||
+ grub_size_t *key_size)
|
||||
+{
|
||||
+ struct grub_key_protector *kp = NULL;
|
||||
+
|
||||
+ if (grub_key_protectors == NULL)
|
||||
+ return GRUB_ERR_OUT_OF_RANGE;
|
||||
+
|
||||
+ if (protector == NULL || grub_strlen (protector) == 0)
|
||||
+ return GRUB_ERR_BAD_ARGUMENT;
|
||||
+
|
||||
+ kp = grub_named_list_find (GRUB_AS_NAMED_LIST (grub_key_protectors),
|
||||
+ protector);
|
||||
+ if (kp == NULL)
|
||||
+ return grub_error (GRUB_ERR_OUT_OF_RANGE,
|
||||
+ N_("A key protector with name '%s' could not be found. "
|
||||
+ "Is the name spelled correctly and is the "
|
||||
+ "corresponding module loaded?"), protector);
|
||||
+
|
||||
+ return kp->recover_key (key, key_size);
|
||||
+}
|
||||
--- /dev/null
|
||||
+++ b/include/grub/protector.h
|
||||
@@ -0,0 +1,48 @@
|
||||
+/*
|
||||
+ * GRUB -- GRand Unified Bootloader
|
||||
+ * Copyright (C) 2022 Microsoft Corporation
|
||||
+ *
|
||||
+ * GRUB 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 3 of the License, or
|
||||
+ * (at your option) any later version.
|
||||
+ *
|
||||
+ * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
+ */
|
||||
+
|
||||
+#ifndef GRUB_PROTECTOR_HEADER
|
||||
+#define GRUB_PROTECTOR_HEADER 1
|
||||
+
|
||||
+#include <grub/err.h>
|
||||
+#include <grub/types.h>
|
||||
+
|
||||
+struct grub_key_protector
|
||||
+{
|
||||
+ struct grub_key_protector *next;
|
||||
+ struct grub_key_protector **prev;
|
||||
+
|
||||
+ const char *name;
|
||||
+
|
||||
+ grub_err_t (*recover_key) (grub_uint8_t **key, grub_size_t *key_size);
|
||||
+};
|
||||
+
|
||||
+extern struct grub_key_protector *EXPORT_VAR (grub_key_protectors);
|
||||
+
|
||||
+grub_err_t
|
||||
+EXPORT_FUNC (grub_key_protector_register) (struct grub_key_protector *protector);
|
||||
+
|
||||
+grub_err_t
|
||||
+EXPORT_FUNC (grub_key_protector_unregister) (struct grub_key_protector *protector);
|
||||
+
|
||||
+grub_err_t
|
||||
+EXPORT_FUNC (grub_key_protector_recover_key) (const char *protector,
|
||||
+ grub_uint8_t **key,
|
||||
+ grub_size_t *key_size);
|
||||
+
|
||||
+#endif /* ! GRUB_PROTECTOR_HEADER */
|
||||
80
0001-protectors-Implement-NV-index.patch
Normal file
80
0001-protectors-Implement-NV-index.patch
Normal file
@ -0,0 +1,80 @@
|
||||
From c3efb4ecbe91b63c127b92122dad3fa53d4efc69 Mon Sep 17 00:00:00 2001
|
||||
From: Patrick Colp <patrick.colp@oracle.com>
|
||||
Date: Mon, 31 Jul 2023 07:01:45 -0700
|
||||
Subject: [PATCH 1/4] protectors: Implement NV index
|
||||
|
||||
Currently with the TPM2 protector, only SRK mode is supported and
|
||||
NV index support is just a stub. Implement the NV index option.
|
||||
|
||||
Note: This only extends support on the unseal path. grub2_protect
|
||||
has not been updated. tpm2-tools can be used to insert a key into
|
||||
the NV index.
|
||||
|
||||
An example of inserting a key using tpm2-tools:
|
||||
|
||||
# Get random key.
|
||||
tpm2_getrandom 32 > key.dat
|
||||
|
||||
# Create primary object.
|
||||
tpm2_createprimary -C o -g sha256 -G rsa -c primary.ctx
|
||||
|
||||
# Create policy object. `pcrs.dat` contains the PCR values to seal against.
|
||||
tpm2_startauthsession -S session.dat
|
||||
tpm2_policypcr -S session.dat -l sha256:7,11 -f pcrs.dat -L policy.dat
|
||||
tpm2_flushcontext session.dat
|
||||
|
||||
# Seal key into TPM.
|
||||
cat key.dat | tpm2_create -C primary.ctx -u key.pub -r key.priv -L policy.dat -i-
|
||||
tpm2_load -C primary.ctx -u key.pub -r key.priv -n sealing.name -c sealing.ctx
|
||||
tpm2_evictcontrol -C o -c sealing.ctx 0x81000000
|
||||
|
||||
Then to unseal the key in grub, add this to grub.cfg:
|
||||
|
||||
tpm2_key_protector_init --mode=nv --nvindex=0x81000000 --pcrs=7,11
|
||||
cryptomount -u <UUID> --protector tpm2
|
||||
|
||||
Signed-off-by: Patrick Colp <patrick.colp@oracle.com>
|
||||
---
|
||||
grub-core/tpm2/module.c | 25 ++++++++++++++++++++-----
|
||||
1 file changed, 20 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/grub-core/tpm2/module.c b/grub-core/tpm2/module.c
|
||||
index 5274296b7..d3a64187a 100644
|
||||
--- a/grub-core/tpm2/module.c
|
||||
+++ b/grub-core/tpm2/module.c
|
||||
@@ -757,12 +757,27 @@ static grub_err_t
|
||||
grub_tpm2_protector_nv_recover (const struct grub_tpm2_protector_context *ctx,
|
||||
grub_uint8_t **key, grub_size_t *key_size)
|
||||
{
|
||||
- (void)ctx;
|
||||
- (void)key;
|
||||
- (void)key_size;
|
||||
+ TPM_HANDLE sealed_handle = ctx->nv;
|
||||
+ tpm2key_policy_t policy_seq = NULL;
|
||||
+ grub_err_t err;
|
||||
+
|
||||
+ /* Create a basic policy sequence based on the given PCR selection */
|
||||
+ err = grub_tpm2_protector_simple_policy_seq (ctx, &policy_seq);
|
||||
+ if (err != GRUB_ERR_NONE)
|
||||
+ goto exit;
|
||||
+
|
||||
+ err = grub_tpm2_protector_unseal (policy_seq, sealed_handle, key, key_size);
|
||||
+
|
||||
+ /* Pop error messages on success */
|
||||
+ if (err == GRUB_ERR_NONE)
|
||||
+ while (grub_error_pop ());
|
||||
+
|
||||
+exit:
|
||||
+ TPM2_FlushContext (sealed_handle);
|
||||
|
||||
- return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
- N_("NV Index mode is not implemented yet"));
|
||||
+ grub_tpm2key_free_policy_seq (policy_seq);
|
||||
+
|
||||
+ return err;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
--
|
||||
2.35.3
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
From 72a582b1c3954f9b917a4d687c95fc94faf551c6 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Wed, 24 Jan 2024 18:03:51 +0800
|
||||
Subject: [PATCH] squash! ieee1275/ofpath: enable NVMeoF logical device
|
||||
translation
|
||||
|
||||
Fixes build error on gcc-14:
|
||||
|
||||
[ 73s] In file included from ../grub-core/osdep/ofpath.c:2:
|
||||
[ 73s] ../grub-core/osdep/linux/ofpath.c: In function 'of_find_fc_host':
|
||||
[ 73s] ../grub-core/osdep/linux/ofpath.c:427:22: error: allocation of insufficient size '8' for type 'struct ofpath_files_list_root' with size '16' [-Werror=alloc-size]
|
||||
[ 73s] 427 | portnames_file_list=malloc(sizeof(portnames_file_list));
|
||||
[ 73s] | ^
|
||||
[ 73s] ../grub-core/osdep/linux/ofpath.c: In function 'of_path_of_nvme':
|
||||
[ 73s] ../grub-core/osdep/linux/ofpath.c:589:21: error: allocation of insufficient size '8' for type 'struct ofpath_nvmeof_info' with size '32' [-Werror=alloc-size]
|
||||
[ 73s] 589 | nvmeof_info = malloc(sizeof(nvmeof_info));
|
||||
[ 73s] | ^
|
||||
[ 73s] ../grub-core/osdep/linux/ofpath.c:618:21: error: allocation of insufficient size '8' for type 'struct ofpath_nvmeof_info' with size '32' [-Werror=alloc-size]
|
||||
[ 73s] 618 | nvmeof_info = malloc(sizeof(nvmeof_info));
|
||||
[ 73s] | ^
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/osdep/linux/ofpath.c | 6 +++---
|
||||
1 file changed, 3 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
|
||||
index 7129099db..55ed7ddf2 100644
|
||||
--- a/grub-core/osdep/linux/ofpath.c
|
||||
+++ b/grub-core/osdep/linux/ofpath.c
|
||||
@@ -424,7 +424,7 @@ of_find_fc_host(char* host_wwpn){
|
||||
|
||||
struct ofpath_files_list_root* portnames_file_list;
|
||||
|
||||
- portnames_file_list=malloc(sizeof(portnames_file_list));
|
||||
+ portnames_file_list=malloc(sizeof(*portnames_file_list));
|
||||
portnames_file_list->items=0;
|
||||
portnames_file_list->first=NULL;
|
||||
|
||||
@@ -586,7 +586,7 @@ of_path_of_nvme(const char *sys_devname __attribute__((unused)),
|
||||
/* If is a NVMeoF */
|
||||
if(strstr(sysfs_path,"nvme-fabrics")){
|
||||
struct ofpath_nvmeof_info* nvmeof_info;
|
||||
- nvmeof_info = malloc(sizeof(nvmeof_info));
|
||||
+ nvmeof_info = malloc(sizeof(*nvmeof_info));
|
||||
|
||||
of_path_get_nvmeof_adapter_info(sysfs_path, nvmeof_info);
|
||||
|
||||
@@ -615,7 +615,7 @@ of_path_of_nvme(const char *sys_devname __attribute__((unused)),
|
||||
sysfs_path = nvme_get_syspath (device);
|
||||
if(strstr(sysfs_path,"nvme-fabrics")){
|
||||
struct ofpath_nvmeof_info* nvmeof_info;
|
||||
- nvmeof_info = malloc(sizeof(nvmeof_info));
|
||||
+ nvmeof_info = malloc(sizeof(*nvmeof_info));
|
||||
|
||||
of_path_get_nvmeof_adapter_info(sysfs_path, nvmeof_info);
|
||||
|
||||
--
|
||||
2.43.0
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
From 60d1d3b959e72c2cbd014be311c350a9b11b1289 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Tue, 7 Sep 2021 10:06:50 +0800
|
||||
Subject: [PATCH] templates: Follow the path of usr merged kernel config
|
||||
|
||||
The background for usr merge can be found at:
|
||||
|
||||
https://www.freedesktop.org/wiki/Software/systemd/TheCaseForTheUsrMerge/
|
||||
|
||||
This patch adapts related mkconfig scripts to follow the usr merge for
|
||||
looking up kernel configs.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
util/grub.d/10_linux.in | 2 +-
|
||||
util/grub.d/20_linux_xen.in | 2 +-
|
||||
2 files changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
--- a/util/grub.d/10_linux.in
|
||||
+++ b/util/grub.d/10_linux.in
|
||||
@@ -351,7 +351,7 @@
|
||||
fi
|
||||
|
||||
config=
|
||||
- for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
|
||||
+ for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" "/usr/lib/modules/${version}/config" ; do
|
||||
if test -e "${i}" ; then
|
||||
config="${i}"
|
||||
break
|
||||
--- a/util/grub.d/20_linux_xen.in
|
||||
+++ b/util/grub.d/20_linux_xen.in
|
||||
@@ -307,7 +307,7 @@
|
||||
version=$(echo $basename | sed -e "s,^[^0-9]*-,,g")
|
||||
dirname=$(dirname $i)
|
||||
config=
|
||||
- for j in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
|
||||
+ for j in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" "/usr/lib/modules/${version}/config" ; do
|
||||
if test -e "${j}" ; then
|
||||
config="${j}"
|
||||
break
|
||||
204
0001-tpm2-Add-TPM2-types-structures-and-command-constants.patch
Normal file
204
0001-tpm2-Add-TPM2-types-structures-and-command-constants.patch
Normal file
@ -0,0 +1,204 @@
|
||||
From 5a417f32f1afe0ffca7f5cbff67145a157b1589b Mon Sep 17 00:00:00 2001
|
||||
From: Gary Lin <glin@suse.com>
|
||||
Date: Tue, 7 Feb 2023 18:31:12 +0800
|
||||
Subject: [PATCH 1/4] tpm2: Add TPM2 types, structures, and command constants
|
||||
|
||||
Add new TPM2 types and structures as the preparation to support
|
||||
authorized policy.
|
||||
|
||||
* New types:
|
||||
TPM_ALG_ECDAA, TPM_ALG_ECDSA, TPM_ALG_ECSCHNORR, TPM_ALG_RSASSA,
|
||||
TPM_ALG_RSAPSS, TPM_ALG_SM2, and TPMI_ALG_SIG_SCHEME
|
||||
|
||||
* New structures:
|
||||
TPMS_EMPTY, TPMS_SIGNATURE_RSA, TPMS_SIGNATURE_ECC,
|
||||
TPMS_SIGNATURE_ECDSA, TPMS_SIGNATURE_ECDAA, TPMS_SIGNATURE_SM2,
|
||||
TPMS_SIGNATURE_ECSCHNORR, TPMU_SIGNATURE, and TPMT_TK_VERIFIED
|
||||
|
||||
* New command constants:
|
||||
TPM_CC_LoadExternal, TPM_CC_HashSequenceStart, TPM_CC_SequenceUpdate,
|
||||
TPM_CC_SequenceComplete, TPM_CC_Hash, TPM_CC_VerifySignature,
|
||||
TPM_CC_PolicyAuthorize
|
||||
|
||||
Signed-off-by: Gary Lin <glin@suse.com>
|
||||
---
|
||||
include/grub/tpm2/internal/structs.h | 86 ++++++++++++++++++++++++++++
|
||||
include/grub/tpm2/internal/types.h | 42 +++++++++-----
|
||||
2 files changed, 114 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/include/grub/tpm2/internal/structs.h b/include/grub/tpm2/internal/structs.h
|
||||
index 72d71eb70..db9eb6cf6 100644
|
||||
--- a/include/grub/tpm2/internal/structs.h
|
||||
+++ b/include/grub/tpm2/internal/structs.h
|
||||
@@ -672,4 +672,90 @@ struct TPMT_TK_CREATION
|
||||
};
|
||||
typedef struct TPMT_TK_CREATION TPMT_TK_CREATION;
|
||||
|
||||
+/* TPMS_EMPTY Structure */
|
||||
+struct TPMS_EMPTY {
|
||||
+ grub_uint8_t empty[1]; /* a structure with no member */
|
||||
+};
|
||||
+typedef struct TPMS_EMPTY TPMS_EMPTY;
|
||||
+
|
||||
+/* TPMS_SIGNATURE_RSA Structure */
|
||||
+struct TPMS_SIGNATURE_RSA {
|
||||
+ TPMI_ALG_HASH hash;
|
||||
+ TPM2B_PUBLIC_KEY_RSA sig;
|
||||
+};
|
||||
+typedef struct TPMS_SIGNATURE_RSA TPMS_SIGNATURE_RSA;
|
||||
+
|
||||
+/* Definition of Types for RSA Signature */
|
||||
+typedef TPMS_SIGNATURE_RSA TPMS_SIGNATURE_RSASSA;
|
||||
+typedef TPMS_SIGNATURE_RSA TPMS_SIGNATURE_RSAPSS;
|
||||
+
|
||||
+/* TPMS_SIGNATURE_ECC Structure */
|
||||
+struct TPMS_SIGNATURE_ECC {
|
||||
+ TPMI_ALG_HASH hash;
|
||||
+ TPM2B_ECC_PARAMETER signatureR;
|
||||
+ TPM2B_ECC_PARAMETER signatureS;
|
||||
+};
|
||||
+typedef struct TPMS_SIGNATURE_ECC TPMS_SIGNATURE_ECC;
|
||||
+
|
||||
+/* Definition of Types for ECC TPMS_SIGNATURE_ECC */
|
||||
+typedef TPMS_SIGNATURE_ECC TPMS_SIGNATURE_ECDSA;
|
||||
+typedef TPMS_SIGNATURE_ECC TPMS_SIGNATURE_ECDAA;
|
||||
+typedef TPMS_SIGNATURE_ECC TPMS_SIGNATURE_SM2;
|
||||
+typedef TPMS_SIGNATURE_ECC TPMS_SIGNATURE_ECSCHNORR;
|
||||
+
|
||||
+/* TPMU_SIGNATURE Structure */
|
||||
+union TPMU_SIGNATURE {
|
||||
+ TPMS_SIGNATURE_RSASSA rsassa;
|
||||
+ TPMS_SIGNATURE_RSAPSS rsapss;
|
||||
+ TPMS_SIGNATURE_ECDSA ecdsa;
|
||||
+ TPMS_SIGNATURE_ECDAA ecdaa;
|
||||
+ TPMS_SIGNATURE_SM2 sm2;
|
||||
+ TPMS_SIGNATURE_ECSCHNORR ecschnorr;
|
||||
+ TPMT_HA hmac;
|
||||
+ TPMS_SCHEME_HASH any;
|
||||
+ TPMS_EMPTY null;
|
||||
+};
|
||||
+typedef union TPMU_SIGNATURE TPMU_SIGNATURE;
|
||||
+
|
||||
+/* TPMT_SIGNATURE Structure */
|
||||
+struct TPMT_SIGNATURE {
|
||||
+ TPMI_ALG_SIG_SCHEME sigAlg;
|
||||
+ TPMU_SIGNATURE signature;
|
||||
+};
|
||||
+typedef struct TPMT_SIGNATURE TPMT_SIGNATURE;
|
||||
+
|
||||
+static inline TPMI_ALG_HASH
|
||||
+TPMT_SIGNATURE_get_hash_alg (TPMT_SIGNATURE *sig)
|
||||
+{
|
||||
+ switch (sig->sigAlg)
|
||||
+ {
|
||||
+ case TPM_ALG_RSASSA:
|
||||
+ return sig->signature.rsassa.hash;
|
||||
+ case TPM_ALG_RSAPSS:
|
||||
+ return sig->signature.rsapss.hash;
|
||||
+ case TPM_ALG_ECDSA:
|
||||
+ return sig->signature.ecdsa.hash;
|
||||
+ case TPM_ALG_ECDAA:
|
||||
+ return sig->signature.ecdaa.hash;
|
||||
+ case TPM_ALG_SM2:
|
||||
+ return sig->signature.sm2.hash;
|
||||
+ case TPM_ALG_ECSCHNORR:
|
||||
+ return sig->signature.ecschnorr.hash;
|
||||
+ case TPM_ALG_HMAC:
|
||||
+ return sig->signature.hmac.hashAlg;
|
||||
+ default:
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ return TPM_ALG_NULL;
|
||||
+}
|
||||
+
|
||||
+/* TPMT_TK_VERIFIED Structure */
|
||||
+struct TPMT_TK_VERIFIED {
|
||||
+ TPM_ST tag;
|
||||
+ TPMI_RH_HIERARCHY hierarchy;
|
||||
+ TPM2B_DIGEST digest;
|
||||
+};
|
||||
+typedef struct TPMT_TK_VERIFIED TPMT_TK_VERIFIED;
|
||||
+
|
||||
#endif /* ! GRUB_TPM2_INTERNAL_STRUCTS_HEADER */
|
||||
diff --git a/include/grub/tpm2/internal/types.h b/include/grub/tpm2/internal/types.h
|
||||
index 9714f75d4..a1902ef0c 100644
|
||||
--- a/include/grub/tpm2/internal/types.h
|
||||
+++ b/include/grub/tpm2/internal/types.h
|
||||
@@ -181,6 +181,9 @@ typedef grub_uint16_t TPM_ALG_ID;
|
||||
#define TPM_ALG_CFB ((TPM_ALG_ID) 0x0043)
|
||||
#define TPM_ALG_ECB ((TPM_ALG_ID) 0x0044)
|
||||
#define TPM_ALG_ECC ((TPM_ALG_ID) 0x0023)
|
||||
+#define TPM_ALG_ECDAA ((TPM_ALG_ID) 0x001A)
|
||||
+#define TPM_ALG_ECDSA ((TPM_ALG_ID) 0x0018)
|
||||
+#define TPM_ALG_ECSCHNORR ((TPM_ALG_ID) 0x001C)
|
||||
#define TPM_ALG_HMAC ((TPM_ALG_ID) 0x0005)
|
||||
#define TPM_ALG_KDF1_SP800_108 ((TPM_ALG_ID) 0x0022)
|
||||
#define TPM_ALG_KDF1_SP800_56A ((TPM_ALG_ID) 0x0020)
|
||||
@@ -189,10 +192,13 @@ typedef grub_uint16_t TPM_ALG_ID;
|
||||
#define TPM_ALG_MGF1 ((TPM_ALG_ID) 0x0007)
|
||||
#define TPM_ALG_NULL ((TPM_ALG_ID) 0x0010)
|
||||
#define TPM_ALG_RSA ((TPM_ALG_ID) 0x0001)
|
||||
+#define TPM_ALG_RSASSA ((TPM_ALG_ID) 0x0014)
|
||||
+#define TPM_ALG_RSAPSS ((TPM_ALG_ID) 0x0016)
|
||||
#define TPM_ALG_SHA1 ((TPM_ALG_ID) 0x0004)
|
||||
#define TPM_ALG_SHA256 ((TPM_ALG_ID) 0x000B)
|
||||
#define TPM_ALG_SHA384 ((TPM_ALG_ID) 0x000C)
|
||||
#define TPM_ALG_SHA512 ((TPM_ALG_ID) 0x000D)
|
||||
+#define TPM_ALG_SM2 ((TPM_ALG_ID) 0x001B)
|
||||
#define TPM_ALG_SM3_256 ((TPM_ALG_ID) 0x0012)
|
||||
#define TPM_ALG_SM4 ((TPM_ALG_ID) 0x0013)
|
||||
#define TPM_ALG_SYMCIPHER ((TPM_ALG_ID) 0x0025)
|
||||
@@ -299,20 +305,27 @@ typedef grub_uint16_t TPM2_ECC_CURVE;
|
||||
/* TPM_CC Constants */
|
||||
typedef grub_uint32_t TPM_CC;
|
||||
|
||||
-#define TPM_CC_EvictControl ((TPM_CC) 0x00000120)
|
||||
-#define TPM_CC_CreatePrimary ((TPM_CC) 0x00000131)
|
||||
-#define TPM_CC_Create ((TPM_CC) 0x00000153)
|
||||
-#define TPM_CC_FlushContext ((TPM_CC) 0x00000165)
|
||||
-#define TPM_CC_ReadPublic ((TPM_CC) 0x00000173)
|
||||
-#define TPM_CC_StartAuthSession ((TPM_CC) 0x00000176)
|
||||
-#define TPM_CC_PolicyPCR ((TPM_CC) 0x0000017f)
|
||||
-#define TPM_CC_NV_Read ((TPM_CC) 0x0000014e)
|
||||
-#define TPM_CC_NV_ReadPublic ((TPM_CC) 0x00000169)
|
||||
-#define TPM_CC_GetCapability ((TPM_CC) 0x0000017a)
|
||||
-#define TPM_CC_PCR_Read ((TPM_CC) 0x0000017e)
|
||||
-#define TPM_CC_Load ((TPM_CC) 0x00000157)
|
||||
-#define TPM_CC_Unseal ((TPM_CC) 0x0000015e)
|
||||
-#define TPM_CC_PolicyGetDigest ((TPM_CC) 0x00000189)
|
||||
+#define TPM_CC_EvictControl ((TPM_CC) 0x00000120)
|
||||
+#define TPM_CC_CreatePrimary ((TPM_CC) 0x00000131)
|
||||
+#define TPM_CC_Create ((TPM_CC) 0x00000153)
|
||||
+#define TPM_CC_FlushContext ((TPM_CC) 0x00000165)
|
||||
+#define TPM_CC_ReadPublic ((TPM_CC) 0x00000173)
|
||||
+#define TPM_CC_StartAuthSession ((TPM_CC) 0x00000176)
|
||||
+#define TPM_CC_PolicyPCR ((TPM_CC) 0x0000017f)
|
||||
+#define TPM_CC_NV_Read ((TPM_CC) 0x0000014e)
|
||||
+#define TPM_CC_NV_ReadPublic ((TPM_CC) 0x00000169)
|
||||
+#define TPM_CC_GetCapability ((TPM_CC) 0x0000017a)
|
||||
+#define TPM_CC_PCR_Read ((TPM_CC) 0x0000017e)
|
||||
+#define TPM_CC_Load ((TPM_CC) 0x00000157)
|
||||
+#define TPM_CC_LoadExternal ((TPM_CC) 0x00000167)
|
||||
+#define TPM_CC_Unseal ((TPM_CC) 0x0000015e)
|
||||
+#define TPM_CC_PolicyGetDigest ((TPM_CC) 0x00000189)
|
||||
+#define TPM_CC_HashSequenceStart ((TPM_CC) 0x00000186)
|
||||
+#define TPM_CC_SequenceUpdate ((TPM_CC) 0x0000015c)
|
||||
+#define TPM_CC_SequenceComplete ((TPM_CC) 0x0000013e)
|
||||
+#define TPM_CC_Hash ((TPM_CC) 0x0000017d)
|
||||
+#define TPM_CC_VerifySignature ((TPM_CC) 0x00000177)
|
||||
+#define TPM_CC_PolicyAuthorize ((TPM_CC) 0x0000016a)
|
||||
|
||||
/* Hash algorithm sizes */
|
||||
#define TPM_SHA1_DIGEST_SIZE 20
|
||||
@@ -354,6 +367,7 @@ typedef TPM_ALG_ID TPMI_ALG_ECC_SCHEME;
|
||||
typedef TPM_ALG_ID TPMI_ALG_ASYM_SCHEME;
|
||||
typedef TPM_ALG_ID TPMI_ALG_RSA_SCHEME;
|
||||
typedef TPM_ALG_ID TPMI_ALG_SYM;
|
||||
+typedef TPM_ALG_ID TPMI_ALG_SIG_SCHEME;
|
||||
|
||||
/* TPM_KEY_BITS Type */
|
||||
typedef grub_uint16_t TPM_KEY_BITS;
|
||||
--
|
||||
2.35.3
|
||||
|
||||
@ -0,0 +1,83 @@
|
||||
From 6c06378c1bf6ae21788427e62ab0011b7f1bc2f0 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Fri, 25 Nov 2022 16:11:24 +0800
|
||||
Subject: [PATCH] xen_boot: add missing grub_arch_efi_linux_load_image_header
|
||||
|
||||
The new xen_boot module has used grub_arch_efi_linux_load_image_header
|
||||
exported by grub-core/loader/arm64/linux.c. It is not a problem for
|
||||
upstream but many downstream projects may not use it and take
|
||||
grub-core/loader/arm64/efi/linux.c as a replacement as PE entry is the
|
||||
preferred way in combination with shim loader.
|
||||
|
||||
This patch did a trivial workaround just adding back the dropped
|
||||
defintion to the xen_boot itself.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/loader/arm64/xen_boot.c | 50 +++++++++++++++++++++++++++++++
|
||||
1 file changed, 50 insertions(+)
|
||||
|
||||
diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c
|
||||
index 26e1472c9..b82a2db89 100644
|
||||
--- a/grub-core/loader/arm64/xen_boot.c
|
||||
+++ b/grub-core/loader/arm64/xen_boot.c
|
||||
@@ -84,6 +84,56 @@ static int loaded;
|
||||
static struct xen_boot_binary *xen_hypervisor;
|
||||
static struct xen_boot_binary *module_head;
|
||||
|
||||
+/* The function is exported by grub-core/loader/arm64/linux.c that is not built
|
||||
+ * because we use PE entry provided by grub-core/loader/arm64/efi/linux.c
|
||||
+ */
|
||||
+static bool initrd_use_loadfile2 = false;
|
||||
+
|
||||
+grub_err_t
|
||||
+grub_arch_efi_linux_load_image_header (grub_file_t file,
|
||||
+ struct linux_arch_kernel_header * lh)
|
||||
+{
|
||||
+ grub_file_seek (file, 0);
|
||||
+ if (grub_file_read (file, lh, sizeof (*lh)) < (grub_ssize_t) sizeof (*lh))
|
||||
+ return grub_error(GRUB_ERR_FILE_READ_ERROR, "failed to read Linux image header");
|
||||
+
|
||||
+ if ((lh->code0 & 0xffff) != GRUB_PE32_MAGIC)
|
||||
+ return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
+ N_("plain image kernel not supported - rebuild with CONFIG_(U)EFI_STUB enabled"));
|
||||
+
|
||||
+ grub_dprintf ("linux", "UEFI stub kernel:\n");
|
||||
+ grub_dprintf ("linux", "PE/COFF header @ %08x\n", lh->hdr_offset);
|
||||
+
|
||||
+ /*
|
||||
+ * The PE/COFF spec permits the COFF header to appear anywhere in the file, so
|
||||
+ * we need to double check whether it was where we expected it, and if not, we
|
||||
+ * must load it from the correct offset into the pe_image_header field of
|
||||
+ * struct linux_arch_kernel_header.
|
||||
+ */
|
||||
+ if ((grub_uint8_t *) lh + lh->hdr_offset != (grub_uint8_t *) &lh->pe_image_header)
|
||||
+ {
|
||||
+ if (grub_file_seek (file, lh->hdr_offset) == (grub_off_t) -1
|
||||
+ || grub_file_read (file, &lh->pe_image_header,
|
||||
+ sizeof (struct grub_pe_image_header))
|
||||
+ != sizeof (struct grub_pe_image_header))
|
||||
+ return grub_error (GRUB_ERR_FILE_READ_ERROR, "failed to read COFF image header");
|
||||
+ }
|
||||
+
|
||||
+ /*
|
||||
+ * Linux kernels built for any architecture are guaranteed to support the
|
||||
+ * LoadFile2 based initrd loading protocol if the image version is >= 1.
|
||||
+ */
|
||||
+ if (lh->pe_image_header.optional_header.major_image_version >= 1)
|
||||
+ initrd_use_loadfile2 = true;
|
||||
+ else
|
||||
+ initrd_use_loadfile2 = false;
|
||||
+
|
||||
+ grub_dprintf ("linux", "LoadFile2 initrd loading %sabled\n",
|
||||
+ initrd_use_loadfile2 ? "en" : "dis");
|
||||
+
|
||||
+ return GRUB_ERR_NONE;
|
||||
+}
|
||||
+
|
||||
static __inline grub_addr_t
|
||||
xen_boot_address_align (grub_addr_t start, grub_size_t align)
|
||||
{
|
||||
--
|
||||
2.41.0
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From b5c3492f31a98f5ef0f9bec2c0665ad0b71ad5cb Mon Sep 17 00:00:00 2001
|
||||
From: Sebastian Krahmer <krahmer@suse.com>
|
||||
Date: Tue, 28 Nov 2017 17:24:38 +0800
|
||||
Subject: [PATCH] AUDIT-0: http boot tracker bug
|
||||
@ -15,17 +15,17 @@ This is no big issue for pure http boot, since its going to execute an
|
||||
untrusted kernel anyway, but it will break trusted boot scenarios, where only
|
||||
signed code is allowed to be executed.
|
||||
|
||||
v2: Fix GCC 13 build failure (bsc#1201089)
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/net/efi/net.c | 4 +++-
|
||||
grub-core/net/http.c | 5 ++++-
|
||||
2 files changed, 7 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/grub-core/net/efi/net.c b/grub-core/net/efi/net.c
|
||||
index 86bce6535d3..4bb308026ce 100644
|
||||
--- a/grub-core/net/efi/net.c
|
||||
+++ b/grub-core/net/efi/net.c
|
||||
@@ -645,8 +645,10 @@ grub_efihttp_chunk_read (grub_file_t file, char *buf,
|
||||
@@ -654,8 +654,10 @@
|
||||
|
||||
rd = efi_net_interface (read, file, chunk, sz);
|
||||
|
||||
@ -37,21 +37,17 @@ index 86bce6535d3..4bb308026ce 100644
|
||||
|
||||
if (buf)
|
||||
{
|
||||
diff --git a/grub-core/net/http.c b/grub-core/net/http.c
|
||||
index 12a2632ea55..b52b558d631 100644
|
||||
--- a/grub-core/net/http.c
|
||||
+++ b/grub-core/net/http.c
|
||||
@@ -31,7 +31,8 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
||||
@@ -30,6 +30,7 @@
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
enum
|
||||
{
|
||||
- HTTP_PORT = 80
|
||||
+ HTTP_PORT = 80,
|
||||
+ HTTP_MAX_CHUNK_SIZE = 0x80000000
|
||||
};
|
||||
#define HTTP_PORT ((grub_uint16_t) 80)
|
||||
+#define HTTP_MAX_CHUNK_SIZE GRUB_INT_MAX
|
||||
|
||||
|
||||
@@ -78,6 +79,8 @@ parse_line (grub_file_t file, http_data_t data, char *ptr, grub_size_t len)
|
||||
typedef struct http_data
|
||||
{
|
||||
@@ -82,6 +83,8 @@
|
||||
if (data->in_chunk_len == 2)
|
||||
{
|
||||
data->chunk_rem = grub_strtoul (ptr, 0, 16);
|
||||
53
0002-Add-grub_disk_write_tail-helper-function.patch
Normal file
53
0002-Add-grub_disk_write_tail-helper-function.patch
Normal file
@ -0,0 +1,53 @@
|
||||
From c0d00403a297d6023eab6189ba87dc8a3f6d1e85 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Mon, 7 Feb 2022 20:44:40 +0800
|
||||
Subject: [PATCH 2/5] Add grub_disk_write_tail helper function
|
||||
|
||||
This helps in writing data to partition where the end of buffer is
|
||||
aligned to end of partition.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/lib/disk.c | 18 ++++++++++++++++++
|
||||
include/grub/disk.h | 3 +++
|
||||
2 files changed, 21 insertions(+)
|
||||
|
||||
--- a/grub-core/lib/disk.c
|
||||
+++ b/grub-core/lib/disk.c
|
||||
@@ -52,6 +52,24 @@
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
+grub_disk_write_tail (grub_disk_t disk, grub_size_t size, const void *buf)
|
||||
+{
|
||||
+ grub_partition_t part;
|
||||
+ grub_disk_addr_t sector;
|
||||
+ grub_off_t offset;
|
||||
+
|
||||
+ if (!disk->partition)
|
||||
+ return GRUB_ERR_NONE;
|
||||
+
|
||||
+ part = disk->partition;
|
||||
+ sector = part->len;
|
||||
+ sector -= (size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS;
|
||||
+ offset = size & (GRUB_DISK_SECTOR_SIZE - 1);
|
||||
+
|
||||
+ return grub_disk_write (disk, sector, offset, size, buf);
|
||||
+}
|
||||
+
|
||||
+grub_err_t
|
||||
grub_disk_write (grub_disk_t disk, grub_disk_addr_t sector,
|
||||
grub_off_t offset, grub_size_t size, const void *buf)
|
||||
{
|
||||
--- a/include/grub/disk.h
|
||||
+++ b/include/grub/disk.h
|
||||
@@ -252,6 +252,9 @@
|
||||
grub_off_t offset,
|
||||
grub_size_t size,
|
||||
void *buf);
|
||||
+grub_err_t grub_disk_write_tail (grub_disk_t disk,
|
||||
+ grub_size_t size,
|
||||
+ const void *buf);
|
||||
grub_err_t grub_disk_write (grub_disk_t disk,
|
||||
grub_disk_addr_t sector,
|
||||
grub_off_t offset,
|
||||
57
0002-Arm-check-for-the-PE-magic-for-the-compiled-arch.patch
Normal file
57
0002-Arm-check-for-the-PE-magic-for-the-compiled-arch.patch
Normal file
@ -0,0 +1,57 @@
|
||||
From 337b3d963d28b3544e8817428fb68ca559613a39 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Jones <pjones@redhat.com>
|
||||
Date: Thu, 9 Sep 2021 10:59:28 -0400
|
||||
Subject: [PATCH 2/2] Arm: check for the PE magic for the compiled arch
|
||||
|
||||
In "arm64: Fix EFI loader kernel image allocation", Ben fixed the kernel
|
||||
alignment to match the alignment given in the PE header. In doing so, a
|
||||
check for valid PE magic was added, which was hard-coded to the value
|
||||
seen on Aarch64 (GRUB_PE32_PE64_MAGIC).
|
||||
|
||||
Unfortunately, this code is shared between 64-bit and 32-bit, and so
|
||||
that value broke 32-bit Arm systems.
|
||||
|
||||
This patch adds a constant definition for GRUB_PE32_PEXX_MAGIC, which is
|
||||
either GRUB_PE32_PE64_MAGIC or GRUB_PE32_PE32_MAGIC, depending on which
|
||||
platform is being built, and uses it in the header magic check.
|
||||
|
||||
Resolves: rhbz#2000756
|
||||
|
||||
Signed-off-by: Peter Jones <pjones@redhat.com>
|
||||
---
|
||||
grub-core/loader/arm64/efi/linux.c | 2 +-
|
||||
include/grub/arm/linux.h | 1 +
|
||||
include/grub/arm64/linux.h | 1 +
|
||||
3 files changed, 3 insertions(+), 1 deletion(-)
|
||||
|
||||
--- a/grub-core/loader/arm64/efi/linux.c
|
||||
+++ b/grub-core/loader/arm64/efi/linux.c
|
||||
@@ -376,7 +376,7 @@
|
||||
|
||||
pe = (void *)((unsigned long)kernel + lh->hdr_offset);
|
||||
|
||||
- if (pe->opt.magic != GRUB_PE32_PE64_MAGIC)
|
||||
+ if (pe->opt.magic != GRUB_PE32_PEXX_MAGIC)
|
||||
return grub_error(GRUB_ERR_BAD_OS, "Invalid PE optional header magic");
|
||||
|
||||
*total_size = pe->opt.image_size;
|
||||
--- a/include/grub/arm/linux.h
|
||||
+++ b/include/grub/arm/linux.h
|
||||
@@ -33,6 +33,7 @@
|
||||
};
|
||||
|
||||
#if defined(__arm__)
|
||||
+# define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE32_MAGIC
|
||||
# define grub_armxx_linux_pe_header grub_arm_linux_pe_header
|
||||
#endif
|
||||
|
||||
--- a/include/grub/arm64/linux.h
|
||||
+++ b/include/grub/arm64/linux.h
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#if defined(__aarch64__)
|
||||
# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE
|
||||
+# define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE64_MAGIC
|
||||
# define grub_armxx_linux_pe_header grub_arm64_linux_pe_header
|
||||
#endif
|
||||
|
||||
92
0002-Fix-race-in-EFI-validation.patch
Normal file
92
0002-Fix-race-in-EFI-validation.patch
Normal file
@ -0,0 +1,92 @@
|
||||
From e72dcb40356f56efd86ab88c2f5cb7411d1e898b Mon Sep 17 00:00:00 2001
|
||||
From: Matthew Garrett <mjg59@coreos.com>
|
||||
Date: Tue, 14 Jul 2015 16:58:51 -0700
|
||||
Subject: [PATCH 02/11] Fix race in EFI validation
|
||||
|
||||
---
|
||||
grub-core/loader/i386/efi/linux.c | 40 +++++++------------------------
|
||||
1 file changed, 9 insertions(+), 31 deletions(-)
|
||||
|
||||
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
|
||||
index 06814cae3..1e09c88ab 100644
|
||||
--- a/grub-core/loader/i386/efi/linux.c
|
||||
+++ b/grub-core/loader/i386/efi/linux.c
|
||||
@@ -154,7 +154,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
grub_file_t file = 0;
|
||||
struct linux_i386_kernel_header lh;
|
||||
grub_ssize_t len, start, filelen;
|
||||
- void *kernel;
|
||||
+ void *kernel = NULL;
|
||||
grub_err_t err;
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
@@ -185,10 +185,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
goto fail;
|
||||
}
|
||||
|
||||
- grub_file_seek (file, 0);
|
||||
-
|
||||
- grub_free(kernel);
|
||||
-
|
||||
params = grub_efi_allocate_pages_max (0x3fffffff, BYTES_TO_PAGES(16384));
|
||||
|
||||
if (! params)
|
||||
@@ -199,13 +195,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
grub_memset (params, 0, 16384);
|
||||
|
||||
- if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
|
||||
- {
|
||||
- if (!grub_errno)
|
||||
- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
||||
- argv[0]);
|
||||
- goto fail;
|
||||
- }
|
||||
+ grub_memcpy (&lh, kernel, sizeof (lh));
|
||||
|
||||
if (lh.boot_flag != grub_cpu_to_le16 (0xaa55))
|
||||
{
|
||||
@@ -271,26 +261,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
goto fail;
|
||||
}
|
||||
|
||||
- if (grub_file_seek (file, start) == (grub_off_t) -1)
|
||||
- {
|
||||
- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
||||
- argv[0]);
|
||||
- goto fail;
|
||||
- }
|
||||
-
|
||||
- if (grub_file_read (file, kernel_mem, len) != len && !grub_errno)
|
||||
- {
|
||||
- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
||||
- argv[0]);
|
||||
- }
|
||||
-
|
||||
- if (grub_errno == GRUB_ERR_NONE)
|
||||
- {
|
||||
- grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0);
|
||||
- loaded = 1;
|
||||
- lh.code32_start = (grub_uint32_t)(grub_addr_t) kernel_mem;
|
||||
- }
|
||||
+ grub_memcpy (kernel_mem, (char *)kernel + start, len);
|
||||
+ grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0);
|
||||
+ loaded=1;
|
||||
|
||||
+ lh.code32_start = (grub_uint32_t)(grub_uint64_t) kernel_mem;
|
||||
/* Grub linuxefi erroneously initialize linux's boot_params with non-zero values. (bsc#1025563)
|
||||
|
||||
From https://www.kernel.org/doc/Documentation/x86/boot.txt:
|
||||
@@ -307,6 +282,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (file)
|
||||
grub_file_close (file);
|
||||
|
||||
+ if (kernel)
|
||||
+ grub_free (kernel);
|
||||
+
|
||||
if (grub_errno != GRUB_ERR_NONE)
|
||||
{
|
||||
grub_dl_unref (my_mod);
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
From f01314a822dbe9ad39b2f7d0f3717ef6e4c24f4a Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Fri, 15 Apr 2022 21:45:04 +0800
|
||||
Subject: [PATCH 2/2] Mark environmet blocks as used for image embedding.
|
||||
|
||||
Now that grub will attempt to use full btrfs bootloader area, the
|
||||
embedded image could have overlapped with environment blocks if it's
|
||||
size grows too much. Let's define a dedicated area for environment
|
||||
blocks to the used block mappings for the embedding process so it can be
|
||||
skipped.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/fs/btrfs.c | 3 ++-
|
||||
include/grub/fs.h | 2 ++
|
||||
util/grub-editenv.c | 2 +-
|
||||
3 files changed, 5 insertions(+), 2 deletions(-)
|
||||
|
||||
--- a/grub-core/fs/btrfs.c
|
||||
+++ b/grub-core/fs/btrfs.c
|
||||
@@ -2637,7 +2637,7 @@
|
||||
|
||||
static const struct {
|
||||
struct embed_region available;
|
||||
- struct embed_region used[6];
|
||||
+ struct embed_region used[7];
|
||||
} btrfs_head = {
|
||||
.available = {0, GRUB_DISK_KiB_TO_SECTORS (1024)}, /* The first 1 MiB. */
|
||||
.used = {
|
||||
@@ -2645,6 +2645,7 @@
|
||||
{GRUB_DISK_KiB_TO_SECTORS (64) - 1, 1}, /* Overflow guard. */
|
||||
{GRUB_DISK_KiB_TO_SECTORS (64), GRUB_DISK_KiB_TO_SECTORS (4)}, /* 4 KiB superblock. */
|
||||
{GRUB_DISK_KiB_TO_SECTORS (68), 1}, /* Overflow guard. */
|
||||
+ {GRUB_DISK_KiB_TO_SECTORS (ENV_BTRFS_OFFSET) - 1, 3}, /* Environment Block. */
|
||||
{GRUB_DISK_KiB_TO_SECTORS (1024) - 1, 1}, /* Overflow guard. */
|
||||
{0, 0} /* Array terminator. */
|
||||
}
|
||||
--- a/include/grub/fs.h
|
||||
+++ b/include/grub/fs.h
|
||||
@@ -128,4 +128,6 @@
|
||||
|
||||
grub_fs_t EXPORT_FUNC(grub_fs_probe) (grub_device_t device);
|
||||
|
||||
+#define ENV_BTRFS_OFFSET (256)
|
||||
+
|
||||
#endif /* ! GRUB_FS_HEADER */
|
||||
--- a/util/grub-editenv.c
|
||||
+++ b/util/grub-editenv.c
|
||||
@@ -128,7 +128,7 @@
|
||||
int offset;
|
||||
int size;
|
||||
} fs_envblk_spec[] = {
|
||||
- { "btrfs", 256 * 1024, GRUB_DISK_SECTOR_SIZE },
|
||||
+ { "btrfs", ENV_BTRFS_OFFSET * 1024, GRUB_DISK_SECTOR_SIZE },
|
||||
{ NULL, 0, 0 }
|
||||
};
|
||||
|
||||
@ -0,0 +1,59 @@
|
||||
From 9f18541245858f53fea72d8d60304f9015d88b5f Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Fri, 17 Mar 2023 22:00:23 +0800
|
||||
Subject: [PATCH 2/2] Restrict cryptsetup key file permission for better
|
||||
security
|
||||
|
||||
GRUB's default permission 777 for concatenated initrd files was too
|
||||
permissive for the cryptsetup key file, causing a complaint from
|
||||
systemd-cryptsetup during boot. This commit replaces the 0777 permission
|
||||
with a more secure 0400 permission for the key file.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/loader/linux.c | 6 +++++-
|
||||
1 file changed, 5 insertions(+), 1 deletion(-)
|
||||
|
||||
--- a/grub-core/loader/linux.c
|
||||
+++ b/grub-core/loader/linux.c
|
||||
@@ -32,6 +32,7 @@
|
||||
char *buf;
|
||||
char *newc_name;
|
||||
grub_off_t size;
|
||||
+ grub_uint32_t mode;
|
||||
};
|
||||
|
||||
struct dir
|
||||
@@ -203,6 +204,7 @@
|
||||
grub_memcpy (comp->buf, buf, bufsz);
|
||||
initrd_ctx->nfiles++;
|
||||
comp->size = bufsz;
|
||||
+ comp->mode = 0100400;
|
||||
if (grub_add (initrd_ctx->size, comp->size,
|
||||
&initrd_ctx->size))
|
||||
goto overflow;
|
||||
@@ -272,6 +274,7 @@
|
||||
grub_initrd_close (initrd_ctx);
|
||||
return grub_errno;
|
||||
}
|
||||
+ initrd_ctx->components[i].mode = 0100777;
|
||||
name_len = grub_strlen (initrd_ctx->components[i].newc_name) + 1;
|
||||
if (grub_add (initrd_ctx->size,
|
||||
ALIGN_UP (sizeof (struct newc_head) + name_len, 4),
|
||||
@@ -374,6 +377,7 @@
|
||||
if (initrd_ctx->components[i].newc_name)
|
||||
{
|
||||
grub_size_t dir_size;
|
||||
+ grub_uint32_t mode = initrd_ctx->components[i].mode;
|
||||
|
||||
if (insert_dir (initrd_ctx->components[i].newc_name, &root, ptr,
|
||||
&dir_size))
|
||||
@@ -385,7 +389,7 @@
|
||||
ptr += dir_size;
|
||||
ptr = make_header (ptr, initrd_ctx->components[i].newc_name,
|
||||
grub_strlen (initrd_ctx->components[i].newc_name) + 1,
|
||||
- 0100777,
|
||||
+ mode,
|
||||
initrd_ctx->components[i].size);
|
||||
newc = 1;
|
||||
}
|
||||
197
0002-Restrict-file-access-on-cryptodisk-print.patch
Normal file
197
0002-Restrict-file-access-on-cryptodisk-print.patch
Normal file
@ -0,0 +1,197 @@
|
||||
From 912384e63c1e3b6aa9d90effb71cd535a17da1e2 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Sat, 18 Nov 2023 19:02:31 +0800
|
||||
Subject: [PATCH 2/4] Restrict file access on cryptodisk print
|
||||
|
||||
When the encrypted partition is automatically unlocked by TPM, granting
|
||||
access to the system upon validation of its known good state, there's a
|
||||
potential vulnerability. Grub gains access to file systems that were
|
||||
previously inaccessible to the public, enabling certain commands from
|
||||
the grub console to print content. This arises due to grub lacking
|
||||
restrictions similar to those imposed by password authentication, which
|
||||
typically occurs before privileged access is granted.
|
||||
|
||||
Although the automatic unlocking process ensures system integrity and a
|
||||
secure environment for grub to operate in, it doesn't directly address
|
||||
the issue of authentication for viewing encrypted partition content.
|
||||
|
||||
This commit addresses this security loophole by implementing a file
|
||||
filter upon adding a TPM key. The newly added file filter will
|
||||
specifically verify if the disk is encrypted, denying access and
|
||||
returning an "Access Denied: prohibited to view encrypted data" error
|
||||
message to alert the user.
|
||||
|
||||
Since the policy to filter out unwanted commands from leaking encrypted
|
||||
content is irreversible, it is advisable to make the loaded module
|
||||
persistent to prevent its removal.
|
||||
|
||||
This enhancement aims to bolster security measures and prevent
|
||||
unauthorized access to encrypted data.
|
||||
|
||||
Signed-Off-by Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/commands/crypttab.c | 35 ++++++++++++++++++++++++++++++++++-
|
||||
grub-core/disk/diskfilter.c | 35 +++++++++++++++++++++++++++++++++++
|
||||
include/grub/disk.h | 10 ++++++++++
|
||||
include/grub/file.h | 1 +
|
||||
4 files changed, 80 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/grub-core/commands/crypttab.c b/grub-core/commands/crypttab.c
|
||||
index 9397bede9..d3acc4b59 100644
|
||||
--- a/grub-core/commands/crypttab.c
|
||||
+++ b/grub-core/commands/crypttab.c
|
||||
@@ -6,11 +6,39 @@
|
||||
#include <grub/mm.h>
|
||||
#include <grub/list.h>
|
||||
#include <grub/crypttab.h>
|
||||
+#include <grub/file.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
grub_crypto_key_list_t *cryptokey_lst;
|
||||
|
||||
+static grub_file_t
|
||||
+grub_nocat_open (grub_file_t io, enum grub_file_type type)
|
||||
+{
|
||||
+ grub_disk_t disk;
|
||||
+
|
||||
+ /* Network device */
|
||||
+ if (!io->device->disk)
|
||||
+ return io;
|
||||
+
|
||||
+ disk = io->device->disk;
|
||||
+
|
||||
+ if (grub_disk_is_crypto (disk))
|
||||
+ {
|
||||
+ switch (type & GRUB_FILE_TYPE_MASK)
|
||||
+ {
|
||||
+ case GRUB_FILE_TYPE_CAT:
|
||||
+ case GRUB_FILE_TYPE_HEXCAT:
|
||||
+ grub_error (GRUB_ERR_ACCESS_DENIED, N_("prohibited to view encrypted data"));
|
||||
+ return NULL;
|
||||
+ default:
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return io;
|
||||
+}
|
||||
+
|
||||
grub_err_t
|
||||
grub_cryptokey_add_or_update (const char *uuid, const char *key, grub_size_t key_len, const char *path, int is_tpmkey)
|
||||
{
|
||||
@@ -48,7 +76,11 @@ grub_cryptokey_add_or_update (const char *uuid, const char *key, grub_size_t key
|
||||
}
|
||||
|
||||
if (is_tpmkey >= 0)
|
||||
- cur->is_tpmkey = is_tpmkey;
|
||||
+ {
|
||||
+ cur->is_tpmkey = is_tpmkey;
|
||||
+ if (is_tpmkey)
|
||||
+ grub_file_filter_register (GRUB_FILE_FILTER_NOCAT, grub_nocat_open);
|
||||
+ }
|
||||
|
||||
if (!cur->name)
|
||||
{
|
||||
@@ -121,6 +153,7 @@ GRUB_MOD_INIT(crypttab)
|
||||
{
|
||||
cmd = grub_register_command ("crypttab_entry", grub_cmd_crypttab_entry,
|
||||
N_("VOLUME-NAME ENCRYPTED-DEVICE KEY-FILE") , N_("No description"));
|
||||
+ grub_dl_set_persistent (mod);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(crypttab)
|
||||
diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c
|
||||
index 5c5fabe1a..b0c1c880d 100644
|
||||
--- a/grub-core/disk/diskfilter.c
|
||||
+++ b/grub-core/disk/diskfilter.c
|
||||
@@ -558,6 +558,39 @@ find_lv (const char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+static int
|
||||
+grub_diskfilter_has_cryptodisk (const struct grub_diskfilter_lv *lv)
|
||||
+{
|
||||
+ struct grub_diskfilter_pv *pv;
|
||||
+
|
||||
+ if (!lv)
|
||||
+ return 0;
|
||||
+
|
||||
+ if (lv->vg->pvs)
|
||||
+ for (pv = lv->vg->pvs; pv; pv = pv->next)
|
||||
+ {
|
||||
+ if (!pv->disk)
|
||||
+ {
|
||||
+ grub_dprintf ("diskfilter", _("Couldn't find physical volume `%s'."
|
||||
+ " Some modules may be missing from core image."),
|
||||
+ pv->name);
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ switch (pv->disk->dev->id)
|
||||
+ {
|
||||
+ case GRUB_DISK_DEVICE_CRYPTODISK_ID:
|
||||
+ return 1;
|
||||
+ case GRUB_DISK_DEVICE_DISKFILTER_ID:
|
||||
+ return grub_diskfilter_has_cryptodisk (pv->disk->data);
|
||||
+ default:
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
static grub_err_t
|
||||
grub_diskfilter_open (const char *name, grub_disk_t disk)
|
||||
{
|
||||
@@ -589,6 +622,8 @@ grub_diskfilter_open (const char *name, grub_disk_t disk)
|
||||
|
||||
disk->total_sectors = lv->size;
|
||||
disk->max_agglomerate = GRUB_DISK_MAX_MAX_AGGLOMERATE;
|
||||
+ disk->is_crypto_diskfilter = grub_diskfilter_has_cryptodisk (lv);
|
||||
+
|
||||
return 0;
|
||||
}
|
||||
|
||||
diff --git a/include/grub/disk.h b/include/grub/disk.h
|
||||
index 3b3db6222..63982f16c 100644
|
||||
--- a/include/grub/disk.h
|
||||
+++ b/include/grub/disk.h
|
||||
@@ -147,6 +147,8 @@ struct grub_disk
|
||||
|
||||
/* Device-specific data. */
|
||||
void *data;
|
||||
+
|
||||
+ int is_crypto_diskfilter;
|
||||
};
|
||||
typedef struct grub_disk *grub_disk_t;
|
||||
|
||||
@@ -314,4 +316,12 @@ void grub_mdraid1x_fini (void);
|
||||
void grub_diskfilter_fini (void);
|
||||
#endif
|
||||
|
||||
+static inline int
|
||||
+grub_disk_is_crypto (grub_disk_t disk)
|
||||
+{
|
||||
+ return ((disk->is_crypto_diskfilter ||
|
||||
+ disk->dev->id == GRUB_DISK_DEVICE_CRYPTODISK_ID) ?
|
||||
+ 1 : 0);
|
||||
+}
|
||||
+
|
||||
#endif /* ! GRUB_DISK_HEADER */
|
||||
diff --git a/include/grub/file.h b/include/grub/file.h
|
||||
index fde58f0fa..fcfd32ce2 100644
|
||||
--- a/include/grub/file.h
|
||||
+++ b/include/grub/file.h
|
||||
@@ -185,6 +185,7 @@ extern grub_disk_read_hook_t EXPORT_VAR(grub_file_progress_hook);
|
||||
/* Filters with lower ID are executed first. */
|
||||
typedef enum grub_file_filter_id
|
||||
{
|
||||
+ GRUB_FILE_FILTER_NOCAT,
|
||||
GRUB_FILE_FILTER_VERIFY,
|
||||
GRUB_FILE_FILTER_GZIO,
|
||||
GRUB_FILE_FILTER_XZIO,
|
||||
--
|
||||
2.42.1
|
||||
|
||||
@ -1,71 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Javier Martinez Canillas <javierm@redhat.com>
|
||||
Date: Fri, 11 Jun 2021 12:10:54 +0200
|
||||
Subject: [PATCH] Revert "templates: Properly disable the os-prober by default"
|
||||
|
||||
This reverts commit 54e0a1bbf1e9106901a557195bb35e5e20fb3925.
|
||||
---
|
||||
util/grub-mkconfig.in | 5 +----
|
||||
util/grub.d/30_os-prober.in | 8 ++++----
|
||||
2 files changed, 5 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
|
||||
index f8cbb8d7a2b..d3e879b8e5c 100644
|
||||
--- a/util/grub-mkconfig.in
|
||||
+++ b/util/grub-mkconfig.in
|
||||
@@ -140,9 +140,6 @@ GRUB_DEVICE_PARTUUID="`${grub_probe} --device ${GRUB_DEVICE} --target=partuuid 2
|
||||
GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
|
||||
GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true
|
||||
|
||||
-# Disable os-prober by default due to security reasons.
|
||||
-GRUB_DISABLE_OS_PROBER="true"
|
||||
-
|
||||
# Filesystem for the device containing our userland. Used for stuff like
|
||||
# choosing Hurd filesystem module.
|
||||
GRUB_FS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2> /dev/null || echo unknown`"
|
||||
@@ -204,7 +201,6 @@ export GRUB_DEVICE \
|
||||
GRUB_DEVICE_PARTUUID \
|
||||
GRUB_DEVICE_BOOT \
|
||||
GRUB_DEVICE_BOOT_UUID \
|
||||
- GRUB_DISABLE_OS_PROBER \
|
||||
GRUB_FS \
|
||||
GRUB_FONT \
|
||||
GRUB_PRELOAD_MODULES \
|
||||
@@ -246,6 +242,7 @@ export GRUB_DEFAULT \
|
||||
GRUB_BACKGROUND \
|
||||
GRUB_THEME \
|
||||
GRUB_GFXPAYLOAD_LINUX \
|
||||
+ GRUB_DISABLE_OS_PROBER \
|
||||
GRUB_INIT_TUNE \
|
||||
GRUB_SAVEDEFAULT \
|
||||
GRUB_ENABLE_CRYPTODISK \
|
||||
diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in
|
||||
index 94622481284..80685b15f4d 100644
|
||||
--- a/util/grub.d/30_os-prober.in
|
||||
+++ b/util/grub.d/30_os-prober.in
|
||||
@@ -26,8 +26,8 @@ export TEXTDOMAINDIR="@localedir@"
|
||||
|
||||
. "$pkgdatadir/grub-mkconfig_lib"
|
||||
|
||||
-if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then
|
||||
- grub_warn "$(gettext_printf "os-prober will not be executed to detect other bootable partitions.\nSystems on them will not be added to the GRUB boot configuration.\nCheck GRUB_DISABLE_OS_PROBER documentation entry.")"
|
||||
+if [ "x${GRUB_DISABLE_OS_PROBER}" = "xfalse" ]; then
|
||||
+ gettext_printf "os-prober will not be executed to detect other bootable partitions.\nSystems on them will not be added to the GRUB boot configuration.\nCheck GRUB_DISABLE_OS_PROBER documentation entry.\n"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@@ -36,12 +36,12 @@ if ! command -v os-prober > /dev/null || ! command -v linux-boot-prober > /dev/n
|
||||
exit 0
|
||||
fi
|
||||
|
||||
-grub_warn "$(gettext_printf "os-prober will be executed to detect other bootable partitions.\nIt's output will be used to detect bootable binaries on them and create new boot entries.")"
|
||||
-
|
||||
OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`"
|
||||
if [ -z "${OSPROBED}" ] ; then
|
||||
# empty os-prober output, nothing doing
|
||||
exit 0
|
||||
+else
|
||||
+ grub_warn "$(gettext_printf "os-prober was executed to detect other bootable partitions.\nIt's output will be used to detect bootable binaries on them and create new boot entries.")"
|
||||
fi
|
||||
|
||||
osx_entry() {
|
||||
@ -0,0 +1,40 @@
|
||||
From e27acddebd30175587155613042abffd2e9a5de8 Mon Sep 17 00:00:00 2001
|
||||
From: Mark Salter <msalter@redhat.com>
|
||||
Date: Mon, 17 Apr 2017 08:44:29 -0400
|
||||
Subject: [PATCH 2/9] arm64: make sure fdt has #address-cells and #size-cells
|
||||
properties
|
||||
|
||||
Recent upstream changes to kexec-tools relies on #address-cells
|
||||
and #size-cells properties in the FDT. If grub2 needs to create
|
||||
a chosen node, it is likely because firmware did not provide one.
|
||||
In that case, set #address-cells and #size-cells properties to
|
||||
make sure they exist.
|
||||
---
|
||||
grub-core/loader/arm64/efi/linux.c | 16 +++++++++++++++-
|
||||
1 file changed, 15 insertions(+), 1 deletion(-)
|
||||
|
||||
--- a/grub-core/loader/arm64/efi/linux.c
|
||||
+++ b/grub-core/loader/arm64/efi/linux.c
|
||||
@@ -99,7 +99,21 @@
|
||||
|
||||
node = grub_fdt_find_subnode (fdt, 0, "chosen");
|
||||
if (node < 0)
|
||||
- node = grub_fdt_add_subnode (fdt, 0, "chosen");
|
||||
+ {
|
||||
+ /*
|
||||
+ * If we have to create a chosen node, Make sure we
|
||||
+ * have #address-cells and #size-cells properties.
|
||||
+ */
|
||||
+ retval = grub_fdt_set_prop32(fdt, 0, "#address-cells", 2);
|
||||
+ if (retval)
|
||||
+ goto failure;
|
||||
+
|
||||
+ retval = grub_fdt_set_prop32(fdt, 0, "#size-cells", 2);
|
||||
+ if (retval)
|
||||
+ goto failure;
|
||||
+
|
||||
+ node = grub_fdt_add_subnode (fdt, 0, "chosen");
|
||||
+ }
|
||||
|
||||
if (node < 1)
|
||||
goto failure;
|
||||
47
0002-cmdline-Provide-cmdline-functions-as-module.patch
Normal file
47
0002-cmdline-Provide-cmdline-functions-as-module.patch
Normal file
@ -0,0 +1,47 @@
|
||||
From 42cb0ebbffd660608612f9e32150a6596c6933c4 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Mon, 17 Aug 2020 17:25:56 +0800
|
||||
Subject: [PATCH 2/2] cmdline: Provide cmdline functions as module
|
||||
|
||||
The command line processing is needed by many loader modules, hence we should
|
||||
make it a sharable one rather than belonging to linux loader. This can cut the
|
||||
dependency to linux module among multiple loaders like multiboot linuxefi and
|
||||
so on to make custom boot image much more flexible to compose.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/Makefile.core.def | 6 +++++-
|
||||
grub-core/lib/cmdline.c | 3 +++
|
||||
2 files changed, 8 insertions(+), 1 deletion(-)
|
||||
|
||||
--- a/grub-core/Makefile.core.def
|
||||
+++ b/grub-core/Makefile.core.def
|
||||
@@ -1860,7 +1860,6 @@
|
||||
x86_64_efi = loader/efi/linux.c;
|
||||
emu = loader/emu/linux.c;
|
||||
common = loader/linux.c;
|
||||
- common = lib/cmdline.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
@@ -2611,3 +2610,8 @@
|
||||
efi = commands/bli.c;
|
||||
enable = efi;
|
||||
};
|
||||
+
|
||||
+module = {
|
||||
+ name = cmdline;
|
||||
+ common = lib/cmdline.c;
|
||||
+};
|
||||
--- a/grub-core/lib/cmdline.c
|
||||
+++ b/grub-core/lib/cmdline.c
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
#include <grub/lib/cmdline.h>
|
||||
#include <grub/misc.h>
|
||||
+#include <grub/dl.h>
|
||||
+
|
||||
+GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static unsigned int check_arg (char *c, int *has_space)
|
||||
{
|
||||
41
0002-cryptodisk-Fallback-to-passphrase.patch
Normal file
41
0002-cryptodisk-Fallback-to-passphrase.patch
Normal file
@ -0,0 +1,41 @@
|
||||
From 7cc578baf26986c2badce998125b429a2aeb4d33 Mon Sep 17 00:00:00 2001
|
||||
From: Patrick Colp <patrick.colp@oracle.com>
|
||||
Date: Sun, 30 Jul 2023 12:58:18 -0700
|
||||
Subject: [PATCH 2/4] cryptodisk: Fallback to passphrase
|
||||
|
||||
If a protector is specified, but it fails to unlock the disk, fall back
|
||||
to asking for the passphrase. However, an error was set indicating that
|
||||
the protector(s) failed. Later code (e.g., LUKS code) fails as
|
||||
`grub_errno` is now set. Print the existing errors out first, before
|
||||
proceeding with the passphrase.
|
||||
|
||||
Signed-off-by: Patrick Colp <patrick.colp@oracle.com>
|
||||
---
|
||||
grub-core/disk/cryptodisk.c | 7 ++++++-
|
||||
1 file changed, 6 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c
|
||||
index 6620fca00..cf37a0934 100644
|
||||
--- a/grub-core/disk/cryptodisk.c
|
||||
+++ b/grub-core/disk/cryptodisk.c
|
||||
@@ -1191,11 +1191,16 @@ grub_cryptodisk_scan_device_real (const char *name,
|
||||
source->name, source->partition != NULL ? "," : "",
|
||||
part != NULL ? part : N_("UNKNOWN"), dev->uuid);
|
||||
grub_free (part);
|
||||
- goto error;
|
||||
}
|
||||
|
||||
if (!cargs->key_len)
|
||||
{
|
||||
+ if (grub_errno)
|
||||
+ {
|
||||
+ grub_print_error ();
|
||||
+ grub_errno = GRUB_ERR_NONE;
|
||||
+ }
|
||||
+
|
||||
/* Get the passphrase from the user, if no key data. */
|
||||
askpass = 1;
|
||||
part = grub_partition_get_name (source->partition);
|
||||
--
|
||||
2.35.3
|
||||
|
||||
@ -0,0 +1,88 @@
|
||||
From 2271da7522d8406c528d2a9079d810e140f8041a Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Fri, 3 Feb 2023 19:40:31 +0800
|
||||
Subject: [PATCH 2/2] discard cached key before entering grub shell and editor
|
||||
mode
|
||||
|
||||
The cached key is cleared in case of anyone poking around it by means of
|
||||
the interactive shell offerings.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/commands/crypttab.c | 16 ++++++++++++++++
|
||||
grub-core/normal/main.c | 2 ++
|
||||
grub-core/normal/menu_entry.c | 3 +++
|
||||
include/grub/crypttab.h | 2 ++
|
||||
4 files changed, 23 insertions(+)
|
||||
|
||||
--- a/grub-core/commands/crypttab.c
|
||||
+++ b/grub-core/commands/crypttab.c
|
||||
@@ -53,6 +53,22 @@
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
+void
|
||||
+grub_initrd_discard_key (void)
|
||||
+{
|
||||
+ struct grub_key_publisher *cur, *nxt;
|
||||
+
|
||||
+ FOR_LIST_ELEMENTS_SAFE (cur, nxt, kpuber)
|
||||
+ {
|
||||
+ grub_list_remove (GRUB_AS_LIST (cur));
|
||||
+ grub_memset (cur->key, 0, cur->key_len);
|
||||
+ grub_free (cur->name);
|
||||
+ grub_free (cur->path);
|
||||
+ grub_free (cur->key);
|
||||
+ grub_free (cur);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
static grub_err_t
|
||||
grub_cmd_crypttab_entry (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char **argv)
|
||||
--- a/grub-core/normal/main.c
|
||||
+++ b/grub-core/normal/main.c
|
||||
@@ -37,6 +37,7 @@
|
||||
#ifdef GRUB_MACHINE_IEEE1275
|
||||
#include <grub/ieee1275/ieee1275.h>
|
||||
#endif
|
||||
+#include <grub/crypttab.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -478,6 +479,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
+ grub_initrd_discard_key ();
|
||||
grub_normal_reader_init (nested);
|
||||
|
||||
while (1)
|
||||
--- a/grub-core/normal/menu_entry.c
|
||||
+++ b/grub-core/normal/menu_entry.c
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/charset.h>
|
||||
#include <grub/safemath.h>
|
||||
+#include <grub/crypttab.h>
|
||||
|
||||
enum update_mode
|
||||
{
|
||||
@@ -1262,6 +1263,8 @@
|
||||
return;
|
||||
}
|
||||
|
||||
+ grub_initrd_discard_key();
|
||||
+
|
||||
screen = make_screen (entry);
|
||||
if (! screen)
|
||||
return;
|
||||
--- a/include/grub/crypttab.h
|
||||
+++ b/include/grub/crypttab.h
|
||||
@@ -19,4 +19,6 @@
|
||||
grub_err_t
|
||||
grub_initrd_publish_key (const char *uuid, const char *key, grub_size_t key_len, const char *path);
|
||||
|
||||
+void
|
||||
+grub_initrd_discard_key (void);
|
||||
#endif /* ! GRUB_CRYPTTAB_HEADER */
|
||||
373
0002-ieee1275-ofpath-enable-NVMeoF-logical-device-transla.patch
Normal file
373
0002-ieee1275-ofpath-enable-NVMeoF-logical-device-transla.patch
Normal file
@ -0,0 +1,373 @@
|
||||
From 9e61624db77e5073961126457f599bc70e877fd1 Mon Sep 17 00:00:00 2001
|
||||
From: Diego Domingos <diegodo@br.ibm.com>
|
||||
Date: Tue, 15 Mar 2022 15:59:41 -0400
|
||||
Subject: [PATCH 2/4] ieee1275/ofpath: enable NVMeoF logical device translation
|
||||
|
||||
This patch add code to enable the translation of logical devices to the of NVMeoFC paths.
|
||||
---
|
||||
grub-core/osdep/linux/ofpath.c | 260 +++++++++++++++++++++++++++++++--
|
||||
include/grub/util/ofpath.h | 29 ++++
|
||||
2 files changed, 280 insertions(+), 9 deletions(-)
|
||||
|
||||
diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
|
||||
index 89beceef4..212782d3f 100644
|
||||
--- a/grub-core/osdep/linux/ofpath.c
|
||||
+++ b/grub-core/osdep/linux/ofpath.c
|
||||
@@ -137,7 +137,7 @@ trim_newline (char *path)
|
||||
*end-- = '\0';
|
||||
}
|
||||
|
||||
-#define MAX_DISK_CAT 64
|
||||
+#define MAX_DISK_CAT 512
|
||||
|
||||
static char *
|
||||
find_obppath (const char *sysfs_path_orig)
|
||||
@@ -313,6 +313,69 @@ get_basename(char *p)
|
||||
return ret;
|
||||
}
|
||||
|
||||
+
|
||||
+void
|
||||
+add_filename_to_pile(char *filename, struct ofpath_files_list_root* root){
|
||||
+ struct ofpath_files_list_node* file;
|
||||
+
|
||||
+ file = malloc(sizeof(struct ofpath_files_list_node));
|
||||
+
|
||||
+ file->filename = filename;
|
||||
+
|
||||
+ if(root->first == NULL){
|
||||
+ root->items = 1;
|
||||
+ root->first = file;
|
||||
+ file->next = NULL;
|
||||
+ } else {
|
||||
+ root->items++;
|
||||
+ file->next = root->first;
|
||||
+ root->first = file;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+
|
||||
+void
|
||||
+find_file(char* filename, char* directory, struct ofpath_files_list_root* root, int max_depth, int depth){
|
||||
+ struct dirent *ep;
|
||||
+ struct stat statbuf;
|
||||
+ DIR *dp;
|
||||
+
|
||||
+ if(depth > max_depth){
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ if((dp = opendir(directory)) == NULL){
|
||||
+
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ while((ep = readdir(dp)) != NULL){
|
||||
+
|
||||
+ char* full_path = malloc(1024*sizeof(char));
|
||||
+ snprintf(full_path,1024,"%s/%s",directory,ep->d_name);
|
||||
+
|
||||
+ lstat(full_path,&statbuf);
|
||||
+
|
||||
+ if(S_ISLNK(statbuf.st_mode)){
|
||||
+
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ if(!strcmp(ep->d_name,".") || !strcmp(ep->d_name,"..")){
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ if(!strcmp(ep->d_name,filename)){
|
||||
+ add_filename_to_pile(full_path, root);
|
||||
+ }
|
||||
+
|
||||
+ find_file(filename, full_path, root, max_depth, depth+1);
|
||||
+
|
||||
+ }
|
||||
+ closedir(dp);
|
||||
+}
|
||||
+
|
||||
+
|
||||
static char *
|
||||
of_path_of_vdisk(const char *sys_devname __attribute__((unused)),
|
||||
const char *device,
|
||||
@@ -351,7 +414,142 @@ of_path_of_ide(const char *sys_devname __attribute__((unused)), const char *devi
|
||||
return ret;
|
||||
}
|
||||
|
||||
-#ifdef __sparc__
|
||||
+char*
|
||||
+of_find_fc_host(char* host_wwpn){
|
||||
+
|
||||
+ FILE* fp;
|
||||
+ char *buf;
|
||||
+ char portname_filename[sizeof("port_name")] = "port_name";
|
||||
+ char devices_path[sizeof("/sys/devices")] = "/sys/devices";
|
||||
+
|
||||
+ struct ofpath_files_list_root* portnames_file_list;
|
||||
+
|
||||
+ portnames_file_list=malloc(sizeof(portnames_file_list));
|
||||
+ portnames_file_list->items=0;
|
||||
+ portnames_file_list->first=NULL;
|
||||
+
|
||||
+ find_file(portname_filename, devices_path, portnames_file_list, 10, 0);
|
||||
+
|
||||
+ struct ofpath_files_list_node* node = portnames_file_list->first;
|
||||
+ while(node != NULL){
|
||||
+ fp = fopen(node->filename,"r");
|
||||
+ buf = malloc(sizeof(char)*512);
|
||||
+ fscanf(fp, "%s", buf);
|
||||
+ fclose(fp);
|
||||
+ if((strcmp(buf,host_wwpn) == 0) && grub_strstr(node->filename, "fc_host")){
|
||||
+ return node->filename;
|
||||
+ }
|
||||
+ node = node->next;
|
||||
+ }
|
||||
+
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+of_path_get_nvmeof_adapter_info(char* sysfs_path,
|
||||
+ struct ofpath_nvmeof_info* nvmeof_info){
|
||||
+
|
||||
+ FILE *fp;
|
||||
+ char *buf, *buf2, *buf3;
|
||||
+
|
||||
+ nvmeof_info->host_wwpn = malloc(sizeof(char)*256);
|
||||
+ nvmeof_info->target_wwpn = malloc(sizeof(char)*256);
|
||||
+ nvmeof_info->nqn = malloc(sizeof(char)*256);
|
||||
+
|
||||
+ buf = malloc(sizeof(char)*512);
|
||||
+ snprintf(buf,512,"%s/subsysnqn",sysfs_path);
|
||||
+ fp = fopen(buf,"r");
|
||||
+ fscanf(fp, "%s", nvmeof_info->nqn);
|
||||
+ fclose(fp);
|
||||
+
|
||||
+ snprintf(buf,512,"%s/cntlid",sysfs_path);
|
||||
+ fp = fopen(buf,"r");
|
||||
+ fscanf(fp, "%u", &(nvmeof_info->cntlid));
|
||||
+ fclose(fp);
|
||||
+
|
||||
+ //snprintf(buf,512,"%s/nsid",sysfs_path);
|
||||
+ //fp = fopen(buf,"r");
|
||||
+ //fscanf(fp, "%u", &(nvmeof_info->nsid));
|
||||
+ //fclose(fp);
|
||||
+
|
||||
+ snprintf(buf,512,"%s/address",sysfs_path);
|
||||
+ fp = fopen(buf,"r");
|
||||
+ buf2 = malloc(sizeof(char)*512);
|
||||
+ fscanf(fp, "%s", buf2);
|
||||
+ fclose(fp);
|
||||
+
|
||||
+ nvmeof_info->host_wwpn = strrchr(buf2,'-')+1;
|
||||
+
|
||||
+ buf3=strchr(buf2,'-')+1;
|
||||
+ buf3=strchr(buf3,'-')+1;
|
||||
+ nvmeof_info->target_wwpn = buf3;
|
||||
+ buf3 = strchr(nvmeof_info->target_wwpn,',');
|
||||
+ *buf3 = '\0';
|
||||
+
|
||||
+
|
||||
+ free(buf);
|
||||
+
|
||||
+ return;
|
||||
+}
|
||||
+
|
||||
+#define MAX_NVME_NSID_DIGITS 6
|
||||
+
|
||||
+static char *
|
||||
+of_path_get_nvme_controller_name_node(const char* devname)
|
||||
+{
|
||||
+ char *controller_node, *end;
|
||||
+
|
||||
+ controller_node = strdup(devname);
|
||||
+
|
||||
+ end = grub_strchr(controller_node+1, 'n');
|
||||
+
|
||||
+ if(end != NULL){
|
||||
+ *end = '\0';
|
||||
+ }
|
||||
+
|
||||
+ return controller_node;
|
||||
+}
|
||||
+
|
||||
+unsigned int
|
||||
+of_path_get_nvme_nsid(const char* devname)
|
||||
+{
|
||||
+ unsigned int nsid;
|
||||
+ char *sysfs_path, *buf;
|
||||
+ FILE *fp;
|
||||
+
|
||||
+ buf=malloc(sizeof(char)*512);
|
||||
+
|
||||
+ sysfs_path = block_device_get_sysfs_path_and_link (devname);
|
||||
+
|
||||
+ snprintf(buf,512,"%s/%s/nsid",sysfs_path,devname);
|
||||
+ fp = fopen(buf,"r");
|
||||
+ fscanf(fp, "%u", &(nsid));
|
||||
+ fclose(fp);
|
||||
+
|
||||
+ free(sysfs_path);
|
||||
+ free(buf);
|
||||
+
|
||||
+ return nsid;
|
||||
+
|
||||
+}
|
||||
+
|
||||
+static char *
|
||||
+nvme_get_syspath(const char *nvmedev)
|
||||
+{
|
||||
+ char *sysfs_path, *controller_node;
|
||||
+ sysfs_path = block_device_get_sysfs_path_and_link (nvmedev);
|
||||
+
|
||||
+ if(strstr(sysfs_path,"nvme-subsystem")){
|
||||
+ controller_node = of_path_get_nvme_controller_name_node(nvmedev);
|
||||
+ strcat(sysfs_path,"/");
|
||||
+ strcat(sysfs_path,controller_node);
|
||||
+ sysfs_path = xrealpath(sysfs_path);
|
||||
+ }
|
||||
+
|
||||
+ return sysfs_path;
|
||||
+}
|
||||
+
|
||||
+
|
||||
static char *
|
||||
of_path_of_nvme(const char *sys_devname __attribute__((unused)),
|
||||
const char *device,
|
||||
@@ -360,6 +558,7 @@ of_path_of_nvme(const char *sys_devname __attribute__((unused)),
|
||||
{
|
||||
char *sysfs_path, *of_path, disk[MAX_DISK_CAT];
|
||||
const char *digit_string, *part_end;
|
||||
+ int chars_written;
|
||||
|
||||
digit_string = trailing_digits (device);
|
||||
part_end = devicenode + strlen (devicenode) - 1;
|
||||
@@ -379,15 +578,61 @@ of_path_of_nvme(const char *sys_devname __attribute__((unused)),
|
||||
/* Remove the p. */
|
||||
*end = '\0';
|
||||
sscanf (digit_string, "%d", &part);
|
||||
- snprintf (disk, sizeof (disk), "/disk@1:%c", 'a' + (part - 1));
|
||||
- sysfs_path = block_device_get_sysfs_path_and_link (nvmedev);
|
||||
+
|
||||
+ sysfs_path = nvme_get_syspath(nvmedev);
|
||||
+
|
||||
+ /* If is a NVMeoF */
|
||||
+ if(strstr(sysfs_path,"nvme-fabrics")){
|
||||
+ struct ofpath_nvmeof_info* nvmeof_info;
|
||||
+ nvmeof_info = malloc(sizeof(nvmeof_info));
|
||||
+
|
||||
+ of_path_get_nvmeof_adapter_info(sysfs_path, nvmeof_info);
|
||||
+
|
||||
+ sysfs_path = of_find_fc_host(nvmeof_info->host_wwpn);
|
||||
+
|
||||
+ chars_written = snprintf(disk,sizeof(disk),"/nvme-of/controller@%s,%x:nqn=%s",
|
||||
+ nvmeof_info->target_wwpn,
|
||||
+ 0xffff,
|
||||
+ nvmeof_info->nqn);
|
||||
+
|
||||
+ unsigned int nsid = of_path_get_nvme_nsid(nvmedev);
|
||||
+
|
||||
+ if(nsid){
|
||||
+ snprintf(disk+chars_written,sizeof(disk) - chars_written,
|
||||
+ "/namespace@%x:%d",nsid, part);
|
||||
+ }
|
||||
+
|
||||
+ } else {
|
||||
+ snprintf (disk, sizeof (disk), "/disk@1:%c", 'a' + (part - 1));
|
||||
+ }
|
||||
free (nvmedev);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We do not have the parition. */
|
||||
- snprintf (disk, sizeof (disk), "/disk@1");
|
||||
- sysfs_path = block_device_get_sysfs_path_and_link (device);
|
||||
+ sysfs_path = nvme_get_syspath (device);
|
||||
+ if(strstr(sysfs_path,"nvme-fabrics")){
|
||||
+ struct ofpath_nvmeof_info* nvmeof_info;
|
||||
+ nvmeof_info = malloc(sizeof(nvmeof_info));
|
||||
+
|
||||
+ of_path_get_nvmeof_adapter_info(sysfs_path, nvmeof_info);
|
||||
+
|
||||
+ sysfs_path = of_find_fc_host(nvmeof_info->host_wwpn);
|
||||
+
|
||||
+ chars_written = snprintf(disk,sizeof(disk),"/nvme-of/controller@%s,%x:nqn=%s",
|
||||
+ nvmeof_info->target_wwpn,
|
||||
+ 0xffff,
|
||||
+ nvmeof_info->nqn);
|
||||
+
|
||||
+ unsigned int nsid = of_path_get_nvme_nsid(device);
|
||||
+ if(nsid){
|
||||
+ snprintf(disk+chars_written,sizeof(disk) - chars_written,
|
||||
+ "/namespace@%x",nsid);
|
||||
+ }
|
||||
+ } else {
|
||||
+ snprintf (disk, sizeof (disk), "/disk@1");
|
||||
+ }
|
||||
+
|
||||
}
|
||||
|
||||
of_path = find_obppath (sysfs_path);
|
||||
@@ -398,7 +643,6 @@ of_path_of_nvme(const char *sys_devname __attribute__((unused)),
|
||||
free (sysfs_path);
|
||||
return of_path;
|
||||
}
|
||||
-#endif
|
||||
|
||||
static void
|
||||
of_fc_port_name(const char *path, const char *subpath, char *port_name)
|
||||
@@ -840,11 +1084,9 @@ grub_util_devname_to_ofpath (const char *sys_devname)
|
||||
/* All the models I've seen have a devalias "floppy".
|
||||
New models have no floppy at all. */
|
||||
ofpath = xstrdup ("floppy");
|
||||
-#ifdef __sparc__
|
||||
else if (device[0] == 'n' && device[1] == 'v' && device[2] == 'm'
|
||||
&& device[3] == 'e')
|
||||
ofpath = of_path_of_nvme (name_buf, device, devnode, devicenode);
|
||||
-#endif
|
||||
else
|
||||
{
|
||||
grub_util_warn (_("unknown device type %s"), device);
|
||||
diff --git a/include/grub/util/ofpath.h b/include/grub/util/ofpath.h
|
||||
index b43c523cb..a0ec30620 100644
|
||||
--- a/include/grub/util/ofpath.h
|
||||
+++ b/include/grub/util/ofpath.h
|
||||
@@ -3,4 +3,33 @@
|
||||
|
||||
char *grub_util_devname_to_ofpath (const char *devname);
|
||||
|
||||
+struct ofpath_files_list_node {
|
||||
+ char* filename;
|
||||
+ struct ofpath_files_list_node* next;
|
||||
+};
|
||||
+
|
||||
+struct ofpath_files_list_root {
|
||||
+ int items;
|
||||
+ struct ofpath_files_list_node* first;
|
||||
+};
|
||||
+
|
||||
+struct ofpath_nvmeof_info {
|
||||
+ char* host_wwpn;
|
||||
+ char* target_wwpn;
|
||||
+ char* nqn;
|
||||
+ int cntlid;
|
||||
+ int nsid;
|
||||
+};
|
||||
+
|
||||
+void of_path_get_nvmeof_adapter_info(char* sysfs_path,
|
||||
+ struct ofpath_nvmeof_info* nvmeof_info);
|
||||
+
|
||||
+unsigned int of_path_get_nvme_nsid(const char* devname);
|
||||
+
|
||||
+void add_filename_to_pile(char *filename, struct ofpath_files_list_root* root);
|
||||
+
|
||||
+void find_file(char* filename, char* directory, struct ofpath_files_list_root* root, int max_depth, int depth);
|
||||
+
|
||||
+char* of_find_fc_host(char* host_wwpn);
|
||||
+
|
||||
#endif /* ! GRUB_OFPATH_MACHINE_UTIL_HEADER */
|
||||
--
|
||||
2.35.3
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From 8b31ebfa42eb5af0633191d26fcdcea8c539e521 Mon Sep 17 00:00:00 2001
|
||||
From: Diego Domingos <diegodo@br.ibm.com>
|
||||
Date: Mon, 14 Dec 2020 17:47:16 +0100
|
||||
Subject: [PATCH] ieee1275/powerpc: enables device mapper discovery
|
||||
Date: Wed, 24 Jun 2020 08:22:50 -0400
|
||||
Subject: [PATCH 2/2] ieee1275/powerpc: enables device mapper discovery
|
||||
|
||||
this patch enables the device mapper discovery on ofpath.c. Currently,
|
||||
when we are dealing with a device like /dev/dm-* the ofpath returns null
|
||||
@ -11,13 +11,14 @@ This patch implements a function that will look into /sys/block/dm-*
|
||||
devices and search recursively inside slaves directory to find the root
|
||||
disk.
|
||||
|
||||
Signed-off-by: Diego Domingos <diegodo@br.ibm.com>
|
||||
v2:
|
||||
Fix gcc-12 error: pointer 'device_path' may be used after 'free'
|
||||
[-Werror=use-after-free]
|
||||
|
||||
---
|
||||
grub-core/osdep/linux/ofpath.c | 64 +++++++++++++++++++++++++++++++++++++++++-
|
||||
grub-core/osdep/linux/ofpath.c | 64 ++++++++++++++++++++++++++++++++++++++++-
|
||||
1 file changed, 63 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
|
||||
index 0f5d54e9f2d..cc849d9c94c 100644
|
||||
--- a/grub-core/osdep/linux/ofpath.c
|
||||
+++ b/grub-core/osdep/linux/ofpath.c
|
||||
@@ -37,6 +37,7 @@
|
||||
@ -28,7 +29,7 @@ index 0f5d54e9f2d..cc849d9c94c 100644
|
||||
|
||||
#ifdef __sparc__
|
||||
typedef enum
|
||||
@@ -755,13 +756,74 @@ strip_trailing_digits (const char *p)
|
||||
@@ -754,13 +755,74 @@
|
||||
return new;
|
||||
}
|
||||
|
||||
@ -77,7 +78,7 @@ index 0f5d54e9f2d..cc849d9c94c 100644
|
||||
+ closedir (dp);
|
||||
+ }
|
||||
+ else
|
||||
+ grub_util_warn (_("cannot open directory `%s'"), device_path);
|
||||
+ grub_util_warn (_("cannot open directory `/sys/block/%s/slaves'"), curr_device);
|
||||
+ }
|
||||
+
|
||||
+ free (directory);
|
||||
164
0002-ofdisk-add-early_log-support.patch
Normal file
164
0002-ofdisk-add-early_log-support.patch
Normal file
@ -0,0 +1,164 @@
|
||||
From 8959b9d97b00f791ffe02b5e3ec3fdf6bff25838 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Tue, 12 Dec 2023 15:34:18 +0800
|
||||
Subject: [PATCH 2/2] ofdisk: add early_log support
|
||||
|
||||
The command ofdisk_early_msg can be used to review debug message logged
|
||||
before output console is initialized.
|
||||
|
||||
For eg:
|
||||
|
||||
grub> ofdisk_early_msg
|
||||
/vdevice/v-scsi@71000002/disk@8000000000000000 is canonical
|
||||
/vdevice/v-scsi@71000002/disk@8000000000000000
|
||||
|
||||
/vdevice/v-scsi@71000002 is parent of
|
||||
/vdevice/v-scsi@71000002/disk@80000000
|
||||
00000000
|
||||
|
||||
the boot device type vscsi is used for root device discovery, others excluded
|
||||
|
||||
We can use it in conjunction with the $ofdisk_boot_type variable to get
|
||||
better understanding the boot device information.
|
||||
|
||||
grub> echo $ofdisk_boot_type
|
||||
boot: /vdevice/v-scsi@71000002 type: vscsi is_nvmeof? 0
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/disk/ieee1275/ofdisk.c | 75 +++++++++++++++++++++++++++++---
|
||||
1 file changed, 70 insertions(+), 5 deletions(-)
|
||||
|
||||
--- a/grub-core/disk/ieee1275/ofdisk.c
|
||||
+++ b/grub-core/disk/ieee1275/ofdisk.c
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/time.h>
|
||||
#include <grub/env.h>
|
||||
+#include <grub/command.h>
|
||||
|
||||
#define RETRY_DEFAULT_TIMEOUT 15
|
||||
|
||||
@@ -60,6 +61,9 @@
|
||||
#define OFDISK_HASH_SZ 8
|
||||
static struct ofdisk_hash_ent *ofdisk_hash[OFDISK_HASH_SZ];
|
||||
|
||||
+static void early_log (const char *fmt, ...);
|
||||
+static void print_early_log (void);
|
||||
+
|
||||
static int
|
||||
ofdisk_hash_fn (const char *devpath)
|
||||
{
|
||||
@@ -1132,10 +1136,10 @@
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
- grub_dprintf ("ofdisk", "%s is canonical %s\n", bootpath, canon);
|
||||
+ early_log ("%s is canonical %s\n", bootpath, canon);
|
||||
|
||||
parent = get_parent_devname (canon, is_nvmeof);
|
||||
- grub_dprintf ("ofdisk", "%s is parent of %s\n", parent, canon);
|
||||
+ early_log ("%s is parent of %s\n", parent, canon);
|
||||
|
||||
grub_free (canon);
|
||||
return parent;
|
||||
@@ -1179,9 +1183,9 @@
|
||||
boot_parent = get_boot_device_parent (bootpath, &is_boot_nvmeof);
|
||||
boot_type = grub_ieee1275_get_device_type (boot_parent);
|
||||
if (boot_type)
|
||||
- grub_dprintf ("ofdisk", "the boot device type %s is used for root device discovery, others excluded\n", boot_type);
|
||||
+ early_log ("the boot device type %s is used for root device discovery, others excluded\n", boot_type);
|
||||
else
|
||||
- grub_dprintf ("ofdisk", "unknown boot device type, will use all devices to discover root and may be slow\n");
|
||||
+ early_log ("unknown boot device type, will use all devices to discover root and may be slow\n");
|
||||
}
|
||||
grub_free (type);
|
||||
grub_free (bootpath);
|
||||
@@ -1205,7 +1209,7 @@
|
||||
static char *ret;
|
||||
|
||||
if (!ret)
|
||||
- ret = grub_xasprintf("boot: %s type: %s is_nvmeof: %d",
|
||||
+ ret = grub_xasprintf("boot: %s type: %s is_nvmeof? %d",
|
||||
boot_parent,
|
||||
boot_type ? : "unknown",
|
||||
is_boot_nvmeof);
|
||||
@@ -1221,6 +1225,17 @@
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+static grub_err_t
|
||||
+grub_cmd_early_msg (struct grub_command *cmd __attribute__ ((unused)),
|
||||
+ int argc __attribute__ ((unused)),
|
||||
+ char *argv[] __attribute__ ((unused)))
|
||||
+{
|
||||
+ print_early_log ();
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static grub_command_t cmd_early_msg;
|
||||
+
|
||||
void
|
||||
grub_ofdisk_init (void)
|
||||
{
|
||||
@@ -1230,6 +1245,9 @@
|
||||
grub_register_variable_hook ("ofdisk_boot_type", grub_env_get_boot_type,
|
||||
grub_env_set_boot_type );
|
||||
|
||||
+ cmd_early_msg =
|
||||
+ grub_register_command ("ofdisk_early_msg", grub_cmd_early_msg,
|
||||
+ 0, N_("Show early boot message in ofdisk."));
|
||||
grub_disk_dev_register (&grub_ofdisk_dev);
|
||||
}
|
||||
|
||||
@@ -1278,3 +1296,50 @@
|
||||
|
||||
return 0;
|
||||
}
|
||||
+
|
||||
+struct ofdisk_early_msg
|
||||
+{
|
||||
+ struct ofdisk_early_msg *next;
|
||||
+ char *msg;
|
||||
+};
|
||||
+
|
||||
+static struct ofdisk_early_msg *early_msg_head;
|
||||
+static struct ofdisk_early_msg **early_msg_last = &early_msg_head;
|
||||
+
|
||||
+static void
|
||||
+early_log (const char *fmt, ...)
|
||||
+{
|
||||
+ struct ofdisk_early_msg *n;
|
||||
+ va_list args;
|
||||
+
|
||||
+ grub_error_push ();
|
||||
+ n = grub_malloc (sizeof (*n));
|
||||
+ if (!n)
|
||||
+ {
|
||||
+ grub_errno = 0;
|
||||
+ grub_error_pop ();
|
||||
+ return;
|
||||
+ }
|
||||
+ n->next = 0;
|
||||
+
|
||||
+ va_start (args, fmt);
|
||||
+ n->msg = grub_xvasprintf (fmt, args);
|
||||
+ va_end (args);
|
||||
+
|
||||
+ *early_msg_last = n;
|
||||
+ early_msg_last = &n->next;
|
||||
+
|
||||
+ grub_errno = 0;
|
||||
+ grub_error_pop ();
|
||||
+}
|
||||
+
|
||||
+static void
|
||||
+print_early_log (void)
|
||||
+{
|
||||
+ struct ofdisk_early_msg *cur;
|
||||
+
|
||||
+ if (!early_msg_head)
|
||||
+ grub_printf ("no early log is available\n");
|
||||
+ for (cur = early_msg_head; cur; cur = cur->next)
|
||||
+ grub_printf ("%s\n", cur->msg);
|
||||
+}
|
||||
205
0002-prep_loadenv-Fix-regex-for-Open-Firmware-device-spec.patch
Normal file
205
0002-prep_loadenv-Fix-regex-for-Open-Firmware-device-spec.patch
Normal file
@ -0,0 +1,205 @@
|
||||
From 990902e28c390217d25ea474e5ef163d79eadc7f Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Fri, 31 Mar 2023 15:19:58 +0800
|
||||
Subject: [PATCH 2/2] prep_loadenv: Fix regex for Open Firmware device
|
||||
specifier with encoded commas
|
||||
|
||||
The Open Firmware device specifier allows for comma-separated properties
|
||||
of a component, but this conflicts with the way that grub separates
|
||||
device and partition in its device specifier. To address this, grub
|
||||
encodes commas in Open Firmware device strings with a leading backslash
|
||||
as an established convention.
|
||||
|
||||
However, the regular expression used to extract the boot device
|
||||
substring from the $cmdpath environment variable did not properly retain
|
||||
commas with leading backslashes as part of the device. This could cause
|
||||
the comma to be incorrectly interpreted as a partition delimiter and
|
||||
result in a broken name for the boot disk.
|
||||
|
||||
To fix this issue, we have updated the regular expression to properly
|
||||
handle the encoded comma in the Open Firmware device specifier, ensuring
|
||||
that the correct boot device is identified and used.
|
||||
|
||||
v2:
|
||||
Fix the issue of freeing an uninitialized pointer in early_prep_loadenv.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/commands/prep_loadenv.c | 108 ++++++++++++++++++++++--------
|
||||
1 file changed, 79 insertions(+), 29 deletions(-)
|
||||
|
||||
--- a/grub-core/commands/prep_loadenv.c
|
||||
+++ b/grub-core/commands/prep_loadenv.c
|
||||
@@ -15,7 +15,7 @@
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
static char *
|
||||
-match_substr (regmatch_t *match, const char *str)
|
||||
+match_substr (const regmatch_t *match, const char *str)
|
||||
{
|
||||
if (match->rm_so != -1)
|
||||
{
|
||||
@@ -185,24 +185,18 @@
|
||||
return err;
|
||||
}
|
||||
|
||||
-static grub_err_t
|
||||
-boot_disk_prep_partname (char **name)
|
||||
+static regmatch_t *
|
||||
+regex_match_str (const char *pattern, const char *str, grub_size_t *nmatch)
|
||||
{
|
||||
regex_t regex;
|
||||
int ret;
|
||||
grub_size_t s;
|
||||
char *comperr;
|
||||
- const char *cmdpath;
|
||||
regmatch_t *matches = NULL;
|
||||
grub_err_t err = GRUB_ERR_NONE;
|
||||
|
||||
- *name = NULL;
|
||||
-
|
||||
- cmdpath = grub_env_get ("cmdpath");
|
||||
- if (!cmdpath)
|
||||
- return GRUB_ERR_NONE;
|
||||
-
|
||||
- ret = regcomp (®ex, "\\(([^,]+)(,?.*)?\\)(.*)", REG_EXTENDED);
|
||||
+ *nmatch = 0;
|
||||
+ ret = regcomp (®ex, pattern, REG_EXTENDED);
|
||||
if (ret)
|
||||
goto fail;
|
||||
|
||||
@@ -210,22 +204,11 @@
|
||||
if (! matches)
|
||||
goto fail;
|
||||
|
||||
- ret = regexec (®ex, cmdpath, regex.re_nsub + 1, matches, 0);
|
||||
- if (!ret)
|
||||
+ ret = regexec (®ex, str, regex.re_nsub + 1, matches, 0);
|
||||
+ if (ret == 0)
|
||||
{
|
||||
- char *devname = devname = match_substr (matches + 1, cmdpath);
|
||||
- if (!devname)
|
||||
- {
|
||||
- err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "%s contains no disk name", cmdpath);
|
||||
- goto out;
|
||||
- }
|
||||
-
|
||||
- err = prep_partname (devname, name);
|
||||
- out:
|
||||
- grub_free (devname);
|
||||
- regfree (®ex);
|
||||
- grub_free (matches);
|
||||
- return err;
|
||||
+ *nmatch = regex.re_nsub + 1;
|
||||
+ return matches;
|
||||
}
|
||||
|
||||
fail:
|
||||
@@ -235,13 +218,60 @@
|
||||
if (!comperr)
|
||||
{
|
||||
regfree (®ex);
|
||||
- return grub_errno;
|
||||
+ return NULL;
|
||||
}
|
||||
regerror (ret, ®ex, comperr, s);
|
||||
err = grub_error (GRUB_ERR_TEST_FAILURE, "%s", comperr);
|
||||
regfree (®ex);
|
||||
grub_free (comperr);
|
||||
- return err;
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
+static grub_err_t
|
||||
+boot_disk_prep_partname (const char *varname, char **name)
|
||||
+{
|
||||
+ const char *cmdpath;
|
||||
+ regmatch_t *matches;
|
||||
+ grub_size_t nmatch;
|
||||
+ char *devname = NULL;
|
||||
+
|
||||
+ *name = NULL;
|
||||
+
|
||||
+ if (varname)
|
||||
+ cmdpath = grub_env_get (varname);
|
||||
+ else
|
||||
+ cmdpath = grub_env_get ("cmdpath");
|
||||
+ if (!cmdpath)
|
||||
+ return GRUB_ERR_NONE;
|
||||
+
|
||||
+ matches = regex_match_str("\\((.*)\\)(.*)", cmdpath, &nmatch);
|
||||
+ if (matches && nmatch >= 2)
|
||||
+ devname = match_substr (matches + 1, cmdpath);
|
||||
+ if (devname == NULL)
|
||||
+ goto quit;
|
||||
+ grub_free (matches);
|
||||
+
|
||||
+ matches = regex_match_str ("(.*[^\\])(,.*)", devname, &nmatch);
|
||||
+ if (matches && nmatch >= 2)
|
||||
+ {
|
||||
+ char *n = match_substr (matches + 1, devname);
|
||||
+ grub_free (devname);
|
||||
+ devname = n;
|
||||
+ }
|
||||
+ else
|
||||
+ grub_errno = GRUB_ERR_NONE;
|
||||
+ if (devname)
|
||||
+ {
|
||||
+ grub_printf ("search prep from disk `%s'\n", devname);
|
||||
+ prep_partname (devname, name);
|
||||
+ }
|
||||
+
|
||||
+ quit:
|
||||
+ grub_free (devname);
|
||||
+ grub_free (matches);
|
||||
+ if (grub_errno)
|
||||
+ grub_print_error ();
|
||||
+ return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
@@ -274,13 +304,31 @@
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
+static grub_err_t
|
||||
+grub_cmd_prep_partname (grub_command_t cmd __attribute__ ((unused)),
|
||||
+ int argc,
|
||||
+ char **argv)
|
||||
+{
|
||||
+ char *prep = NULL;
|
||||
+ const char *varname = NULL;
|
||||
+
|
||||
+ if (argc > 0)
|
||||
+ varname = argv[0];
|
||||
+
|
||||
+ boot_disk_prep_partname(varname, &prep);
|
||||
+ if (prep)
|
||||
+ grub_printf ("prep: %s\n", prep);
|
||||
+
|
||||
+ return GRUB_ERR_NONE;
|
||||
+}
|
||||
+
|
||||
static void
|
||||
early_prep_loadenv (void)
|
||||
{
|
||||
grub_err_t err;
|
||||
- char *prep;
|
||||
+ char *prep = NULL;
|
||||
|
||||
- err = boot_disk_prep_partname (&prep);
|
||||
+ err = boot_disk_prep_partname (NULL, &prep);
|
||||
if (err == GRUB_ERR_NONE && prep)
|
||||
err = prep_read_envblk (prep);
|
||||
if (err == GRUB_ERR_BAD_FILE_TYPE || err == GRUB_ERR_FILE_NOT_FOUND)
|
||||
@@ -296,6 +344,10 @@
|
||||
{
|
||||
early_env_hook = early_prep_loadenv;
|
||||
cmd_prep_load =
|
||||
+ grub_register_command("prep_partname", grub_cmd_prep_partname,
|
||||
+ "VARNAME",
|
||||
+ N_("Get partition name of PReP."));
|
||||
+ cmd_prep_load =
|
||||
grub_register_command("prep_load_env", grub_cmd_prep_loadenv,
|
||||
"DEVICE",
|
||||
N_("Load variables from environment block file."));
|
||||
3569
0002-tpm2-Add-TPM-Software-Stack-TSS.patch
Normal file
3569
0002-tpm2-Add-TPM-Software-Stack-TSS.patch
Normal file
File diff suppressed because it is too large
Load Diff
427
0002-tpm2-Add-more-marshal-unmarshal-functions.patch
Normal file
427
0002-tpm2-Add-more-marshal-unmarshal-functions.patch
Normal file
@ -0,0 +1,427 @@
|
||||
From 1d34522075949581ccb34a08dd73607566517824 Mon Sep 17 00:00:00 2001
|
||||
From: Gary Lin <glin@suse.com>
|
||||
Date: Tue, 7 Feb 2023 18:33:42 +0800
|
||||
Subject: [PATCH 2/4] tpm2: Add more marshal/unmarshal functions
|
||||
|
||||
Add a few more marshal/unmarshal functions to support authorized policy.
|
||||
|
||||
* Marshal:
|
||||
grub_tpm2_mu_TPMU_SENSITIVE_COMPOSITE_Marshal()
|
||||
grub_tpm2_mu_TPMT_SENSITIVE_Marshal()
|
||||
grub_tpm2_mu_TPM2B_SENSITIVE_Marshal()
|
||||
grub_tpm2_mu_TPMS_SIGNATURE_RSA_Marshal()
|
||||
grub_tpm2_mu_TPMS_SIGNATURE_ECC_Marshal()
|
||||
grub_tpm2_mu_TPMU_HA_Marshal()
|
||||
grub_tpm2_mu_TPMT_HA_Marshal()
|
||||
grub_tpm2_mu_TPMU_SIGNATURE_Marshal()
|
||||
grub_tpm2_mu_TPMT_SIGNATURE_Marshal()
|
||||
grub_tpm2_mu_TPMT_TK_VERIFIED_Marshal()
|
||||
|
||||
* Unmarshal:
|
||||
grub_tpm2_mu_TPMT_TK_HASHCHECK_Unmarshal()
|
||||
grub_tpm2_mu_TPMT_TK_VERIFIED_Unmarshal()
|
||||
grub_tpm2_mu_TPMS_SIGNATURE_RSA_Unmarshal()
|
||||
grub_tpm2_mu_TPMS_SIGNATURE_ECC_Unmarshal()
|
||||
grub_tpm2_mu_TPMU_HA_Unmarshal()
|
||||
grub_tpm2_mu_TPMT_HA_Unmarshal()
|
||||
grub_tpm2_mu_TPMU_SIGNATURE_Unmarshal()
|
||||
grub_tpm2_mu_TPMT_SIGNATURE_Unmarshal()
|
||||
|
||||
Signed-off-by: Gary Lin <glin@suse.com>
|
||||
---
|
||||
grub-core/tpm2/mu.c | 262 +++++++++++++++++++++++++++++++++++++++++
|
||||
include/grub/tpm2/mu.h | 75 ++++++++++++
|
||||
2 files changed, 337 insertions(+)
|
||||
|
||||
diff --git a/grub-core/tpm2/mu.c b/grub-core/tpm2/mu.c
|
||||
index 1617f37cd..3a9a3c1be 100644
|
||||
--- a/grub-core/tpm2/mu.c
|
||||
+++ b/grub-core/tpm2/mu.c
|
||||
@@ -383,6 +383,49 @@ grub_tpm2_mu_TPMS_SENSITIVE_CREATE_Marshal (grub_tpm2_buffer_t buffer,
|
||||
grub_tpm2_mu_TPM2B_Marshal (buffer, p->data.size, p->data.buffer);
|
||||
}
|
||||
|
||||
+void
|
||||
+grub_tpm2_mu_TPMU_SENSITIVE_COMPOSITE_Marshal (grub_tpm2_buffer_t buffer,
|
||||
+ const TPMI_ALG_PUBLIC type,
|
||||
+ const TPMU_SENSITIVE_COMPOSITE *p)
|
||||
+{
|
||||
+ switch(type)
|
||||
+ {
|
||||
+ case TPM_ALG_RSA:
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->rsa.size, p->rsa.buffer);
|
||||
+ break;
|
||||
+ case TPM_ALG_ECC:
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->ecc.size, p->ecc.buffer);
|
||||
+ break;
|
||||
+ case TPM_ALG_KEYEDHASH:
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->bits.size, p->bits.buffer);
|
||||
+ break;
|
||||
+ case TPM_ALG_SYMCIPHER:
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->sym.size, p->sym.buffer);
|
||||
+ break;
|
||||
+ default:
|
||||
+ buffer->error = 1;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMT_SENSITIVE_Marshal (grub_tpm2_buffer_t buffer,
|
||||
+ const TPMT_SENSITIVE *p)
|
||||
+{
|
||||
+ grub_tpm2_buffer_pack_u16 (buffer, p->sensitiveType);
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->authValue.size, p->authValue.buffer);
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->seedValue.size, p->seedValue.buffer);
|
||||
+ grub_tpm2_mu_TPMU_SENSITIVE_COMPOSITE_Marshal (buffer, p->sensitiveType,
|
||||
+ &p->sensitive);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPM2B_SENSITIVE_Marshal (grub_tpm2_buffer_t buffer,
|
||||
+ const TPM2B_SENSITIVE *p)
|
||||
+{
|
||||
+ grub_tpm2_buffer_pack_u16 (buffer, p->size);
|
||||
+ grub_tpm2_mu_TPMT_SENSITIVE_Marshal (buffer, &p->sensitiveArea);
|
||||
+}
|
||||
+
|
||||
void
|
||||
grub_tpm2_mu_TPM2B_SENSITIVE_CREATE_Marshal (grub_tpm2_buffer_t buffer,
|
||||
const TPM2B_SENSITIVE_CREATE *sensitiveCreate)
|
||||
@@ -405,6 +448,113 @@ grub_tpm2_mu_TPM2B_SENSITIVE_CREATE_Marshal (grub_tpm2_buffer_t buffer,
|
||||
grub_tpm2_buffer_pack_u16 (buffer, 0);
|
||||
}
|
||||
|
||||
+void
|
||||
+grub_tpm2_mu_TPMS_SIGNATURE_RSA_Marshal (grub_tpm2_buffer_t buffer,
|
||||
+ const TPMS_SIGNATURE_RSA *p)
|
||||
+{
|
||||
+ grub_tpm2_buffer_pack_u16 (buffer, p->hash);
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->sig.size, p->sig.buffer);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMS_SIGNATURE_ECC_Marshal (grub_tpm2_buffer_t buffer,
|
||||
+ const TPMS_SIGNATURE_ECC *p)
|
||||
+{
|
||||
+ grub_tpm2_buffer_pack_u16 (buffer, p->hash);
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->signatureR.size, p->signatureR.buffer);
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->signatureS.size, p->signatureS.buffer);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMU_HA_Marshal (grub_tpm2_buffer_t buffer,
|
||||
+ const TPMI_ALG_HASH hashAlg,
|
||||
+ const TPMU_HA *p)
|
||||
+{
|
||||
+ switch (hashAlg)
|
||||
+ {
|
||||
+ case TPM_ALG_SHA1:
|
||||
+ for (grub_uint16_t i = 0; i < TPM_SHA1_DIGEST_SIZE; i++)
|
||||
+ grub_tpm2_buffer_pack_u8 (buffer, p->sha1[i]);
|
||||
+ break;
|
||||
+ case TPM_ALG_SHA256:
|
||||
+ for (grub_uint16_t i = 0; i < TPM_SHA256_DIGEST_SIZE; i++)
|
||||
+ grub_tpm2_buffer_pack_u8 (buffer, p->sha256[i]);
|
||||
+ break;
|
||||
+ case TPM_ALG_SHA384:
|
||||
+ for (grub_uint16_t i = 0; i < TPM_SHA384_DIGEST_SIZE; i++)
|
||||
+ grub_tpm2_buffer_pack_u8 (buffer, p->sha384[i]);
|
||||
+ break;
|
||||
+ case TPM_ALG_SHA512:
|
||||
+ for (grub_uint16_t i = 0; i < TPM_SHA512_DIGEST_SIZE; i++)
|
||||
+ grub_tpm2_buffer_pack_u8 (buffer, p->sha512[i]);
|
||||
+ break;
|
||||
+ default:
|
||||
+ buffer->error = 1;
|
||||
+ break;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMT_HA_Marshal (grub_tpm2_buffer_t buffer,
|
||||
+ const TPMT_HA *p)
|
||||
+{
|
||||
+ grub_tpm2_buffer_pack_u16 (buffer, p->hashAlg);
|
||||
+ grub_tpm2_mu_TPMU_HA_Marshal (buffer, p->hashAlg, &p->digest);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMU_SIGNATURE_Marshal (grub_tpm2_buffer_t buffer,
|
||||
+ const TPMI_ALG_SIG_SCHEME sigAlg,
|
||||
+ const TPMU_SIGNATURE *p)
|
||||
+{
|
||||
+ switch (sigAlg)
|
||||
+ {
|
||||
+ case TPM_ALG_RSASSA:
|
||||
+ grub_tpm2_mu_TPMS_SIGNATURE_RSA_Marshal (buffer, (TPMS_SIGNATURE_RSA *)&p->rsassa);
|
||||
+ break;
|
||||
+ case TPM_ALG_RSAPSS:
|
||||
+ grub_tpm2_mu_TPMS_SIGNATURE_RSA_Marshal (buffer, (TPMS_SIGNATURE_RSA *)&p->rsapss);
|
||||
+ break;
|
||||
+ case TPM_ALG_ECDSA:
|
||||
+ grub_tpm2_mu_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecdsa);
|
||||
+ break;
|
||||
+ case TPM_ALG_ECDAA:
|
||||
+ grub_tpm2_mu_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecdaa);
|
||||
+ break;
|
||||
+ case TPM_ALG_SM2:
|
||||
+ grub_tpm2_mu_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC *)&p->sm2);
|
||||
+ break;
|
||||
+ case TPM_ALG_ECSCHNORR:
|
||||
+ grub_tpm2_mu_TPMS_SIGNATURE_ECC_Marshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecschnorr);
|
||||
+ break;
|
||||
+ case TPM_ALG_HMAC:
|
||||
+ grub_tpm2_mu_TPMT_HA_Marshal (buffer, &p->hmac);
|
||||
+ break;
|
||||
+ case TPM_ALG_NULL:
|
||||
+ break;
|
||||
+ default:
|
||||
+ buffer->error = 1;
|
||||
+ break;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMT_SIGNATURE_Marshal (grub_tpm2_buffer_t buffer,
|
||||
+ const TPMT_SIGNATURE *p)
|
||||
+{
|
||||
+ grub_tpm2_buffer_pack_u16 (buffer, p->sigAlg);
|
||||
+ grub_tpm2_mu_TPMU_SIGNATURE_Marshal (buffer, p->sigAlg, &p->signature);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMT_TK_VERIFIED_Marshal (grub_tpm2_buffer_t buffer,
|
||||
+ const TPMT_TK_VERIFIED *p)
|
||||
+{
|
||||
+ grub_tpm2_buffer_pack_u16 (buffer, p->tag);
|
||||
+ grub_tpm2_buffer_pack_u32 (buffer, p->hierarchy);
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (buffer, p->digest.size, p->digest.buffer);
|
||||
+}
|
||||
+
|
||||
void
|
||||
grub_tpm2_mu_TPM2B_Unmarshal (grub_tpm2_buffer_t buffer,
|
||||
TPM2B* p)
|
||||
@@ -775,6 +925,24 @@ grub_tpm2_mu_TPMT_TK_CREATION_Unmarshal (grub_tpm2_buffer_t buffer,
|
||||
grub_tpm2_mu_TPM2B_Unmarshal (buffer, (TPM2B*) &p->digest);
|
||||
}
|
||||
|
||||
+void
|
||||
+grub_tpm2_mu_TPMT_TK_HASHCHECK_Unmarshal (grub_tpm2_buffer_t buffer,
|
||||
+ TPMT_TK_HASHCHECK *p)
|
||||
+{
|
||||
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->tag);
|
||||
+ grub_tpm2_buffer_unpack_u32 (buffer, &p->hierarchy);
|
||||
+ grub_tpm2_mu_TPM2B_Unmarshal (buffer, (TPM2B*) &p->digest);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMT_TK_VERIFIED_Unmarshal (grub_tpm2_buffer_t buffer,
|
||||
+ TPMT_TK_VERIFIED *p)
|
||||
+{
|
||||
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->tag);
|
||||
+ grub_tpm2_buffer_unpack_u32 (buffer, &p->hierarchy);
|
||||
+ grub_tpm2_mu_TPM2B_Unmarshal (buffer, (TPM2B*) &p->digest);
|
||||
+}
|
||||
+
|
||||
void
|
||||
grub_tpm2_mu_TPMS_PCR_SELECTION_Unmarshal (grub_tpm2_buffer_t buf,
|
||||
TPMS_PCR_SELECTION* pcrSelection)
|
||||
@@ -805,3 +973,97 @@ grub_tpm2_mu_TPML_DIGEST_Unmarshal (grub_tpm2_buffer_t buf,
|
||||
for (grub_uint32_t i = 0; i < digest->count; i++)
|
||||
grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (buf, &digest->digests[i]);
|
||||
}
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMS_SIGNATURE_RSA_Unmarshal (grub_tpm2_buffer_t buffer,
|
||||
+ TPMS_SIGNATURE_RSA *rsa)
|
||||
+{
|
||||
+ grub_tpm2_buffer_unpack_u16 (buffer, &rsa->hash);
|
||||
+ grub_tpm2_mu_TPM2B_Unmarshal (buffer, (TPM2B*)&rsa->sig);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMS_SIGNATURE_ECC_Unmarshal (grub_tpm2_buffer_t buffer,
|
||||
+ TPMS_SIGNATURE_ECC *ecc)
|
||||
+{
|
||||
+ grub_tpm2_buffer_unpack_u16 (buffer, &ecc->hash);
|
||||
+ grub_tpm2_mu_TPM2B_Unmarshal (buffer, (TPM2B*)&ecc->signatureR);
|
||||
+ grub_tpm2_mu_TPM2B_Unmarshal (buffer, (TPM2B*)&ecc->signatureS);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMU_HA_Unmarshal (grub_tpm2_buffer_t buffer,
|
||||
+ TPMI_ALG_HASH hashAlg,
|
||||
+ TPMU_HA *p)
|
||||
+{
|
||||
+ switch (hashAlg)
|
||||
+ {
|
||||
+ case TPM_ALG_SHA1:
|
||||
+ grub_tpm2_buffer_unpack (buffer, &p->sha1, TPM_SHA1_DIGEST_SIZE);
|
||||
+ break;
|
||||
+ case TPM_ALG_SHA256:
|
||||
+ grub_tpm2_buffer_unpack (buffer, &p->sha256, TPM_SHA256_DIGEST_SIZE);
|
||||
+ break;
|
||||
+ case TPM_ALG_SHA384:
|
||||
+ grub_tpm2_buffer_unpack (buffer, &p->sha384, TPM_SHA384_DIGEST_SIZE);
|
||||
+ break;
|
||||
+ case TPM_ALG_SHA512:
|
||||
+ grub_tpm2_buffer_unpack (buffer, &p->sha512, TPM_SHA512_DIGEST_SIZE);
|
||||
+ break;
|
||||
+ default:
|
||||
+ buffer->error = 1;
|
||||
+ break;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMT_HA_Unmarshal (grub_tpm2_buffer_t buffer,
|
||||
+ TPMT_HA *p)
|
||||
+{
|
||||
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->hashAlg);
|
||||
+ grub_tpm2_mu_TPMU_HA_Unmarshal (buffer, p->hashAlg, &p->digest);
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMU_SIGNATURE_Unmarshal (grub_tpm2_buffer_t buffer,
|
||||
+ TPMI_ALG_SIG_SCHEME sigAlg,
|
||||
+ TPMU_SIGNATURE *p)
|
||||
+{
|
||||
+ switch (sigAlg)
|
||||
+ {
|
||||
+ case TPM_ALG_RSASSA:
|
||||
+ grub_tpm2_mu_TPMS_SIGNATURE_RSA_Unmarshal (buffer, (TPMS_SIGNATURE_RSA *)&p->rsassa);
|
||||
+ break;
|
||||
+ case TPM_ALG_RSAPSS:
|
||||
+ grub_tpm2_mu_TPMS_SIGNATURE_RSA_Unmarshal (buffer, (TPMS_SIGNATURE_RSA *)&p->rsapss);
|
||||
+ break;
|
||||
+ case TPM_ALG_ECDSA:
|
||||
+ grub_tpm2_mu_TPMS_SIGNATURE_ECC_Unmarshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecdsa);
|
||||
+ break;
|
||||
+ case TPM_ALG_ECDAA:
|
||||
+ grub_tpm2_mu_TPMS_SIGNATURE_ECC_Unmarshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecdaa);
|
||||
+ break;
|
||||
+ case TPM_ALG_SM2:
|
||||
+ grub_tpm2_mu_TPMS_SIGNATURE_ECC_Unmarshal (buffer, (TPMS_SIGNATURE_ECC *)&p->sm2);
|
||||
+ break;
|
||||
+ case TPM_ALG_ECSCHNORR:
|
||||
+ grub_tpm2_mu_TPMS_SIGNATURE_ECC_Unmarshal (buffer, (TPMS_SIGNATURE_ECC *)&p->ecschnorr);
|
||||
+ break;
|
||||
+ case TPM_ALG_HMAC:
|
||||
+ grub_tpm2_mu_TPMT_HA_Unmarshal (buffer, &p->hmac);
|
||||
+ break;
|
||||
+ case TPM_ALG_NULL:
|
||||
+ break;
|
||||
+ default:
|
||||
+ buffer->error = 1;
|
||||
+ break;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMT_SIGNATURE_Unmarshal (grub_tpm2_buffer_t buffer,
|
||||
+ TPMT_SIGNATURE *p)
|
||||
+{
|
||||
+ grub_tpm2_buffer_unpack_u16 (buffer, &p->sigAlg);
|
||||
+ grub_tpm2_mu_TPMU_SIGNATURE_Unmarshal (buffer, p->sigAlg, &p->signature);
|
||||
+}
|
||||
diff --git a/include/grub/tpm2/mu.h b/include/grub/tpm2/mu.h
|
||||
index c545976db..afb842ab5 100644
|
||||
--- a/include/grub/tpm2/mu.h
|
||||
+++ b/include/grub/tpm2/mu.h
|
||||
@@ -147,6 +147,47 @@ grub_tpm2_mu_TPM2B_SENSITIVE_CREATE_Marshal (grub_tpm2_buffer_t buf,
|
||||
const TPM2B_SENSITIVE_CREATE *sensitiveCreate);
|
||||
|
||||
void
|
||||
+grub_tpm2_mu_TPMU_SENSITIVE_COMPOSITE_Marshal (grub_tpm2_buffer_t buf,
|
||||
+ const TPMI_ALG_PUBLIC type,
|
||||
+ const TPMU_SENSITIVE_COMPOSITE *p);
|
||||
+void
|
||||
+grub_tpm2_mu_TPMT_SENSITIVE_Marshal (grub_tpm2_buffer_t buf,
|
||||
+ const TPMT_SENSITIVE *p);
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPM2B_SENSITIVE_Marshal (grub_tpm2_buffer_t buf,
|
||||
+ const TPM2B_SENSITIVE *p);
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMS_SIGNATURE_RSA_Marshal (grub_tpm2_buffer_t buf,
|
||||
+ const TPMS_SIGNATURE_RSA *p);
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMS_SIGNATURE_ECC_Marshal (grub_tpm2_buffer_t buf,
|
||||
+ const TPMS_SIGNATURE_ECC *p);
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMU_HA_Marshal (grub_tpm2_buffer_t buf,
|
||||
+ const TPMI_ALG_HASH hashAlg,
|
||||
+ const TPMU_HA *p);
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMT_HA_Marshal (grub_tpm2_buffer_t buf,
|
||||
+ const TPMT_HA *p);
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMU_SIGNATURE_Marshal (grub_tpm2_buffer_t buf,
|
||||
+ const TPMI_ALG_SIG_SCHEME sigAlg,
|
||||
+ const TPMU_SIGNATURE *p);
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMT_SIGNATURE_Marshal (grub_tpm2_buffer_t buf,
|
||||
+ const TPMT_SIGNATURE *p);
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMT_TK_VERIFIED_Marshal (grub_tpm2_buffer_t buf,
|
||||
+ const TPMT_TK_VERIFIED *p);
|
||||
+void
|
||||
grub_tpm2_mu_TPM2B_Unmarshal (grub_tpm2_buffer_t buf,
|
||||
TPM2B* p);
|
||||
|
||||
@@ -277,6 +318,14 @@ void
|
||||
grub_tpm2_mu_TPMT_TK_CREATION_Unmarshal (grub_tpm2_buffer_t buf,
|
||||
TPMT_TK_CREATION *p);
|
||||
|
||||
+void
|
||||
+grub_tpm2_mu_TPMT_TK_HASHCHECK_Unmarshal (grub_tpm2_buffer_t buf,
|
||||
+ TPMT_TK_HASHCHECK *p);
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMT_TK_VERIFIED_Unmarshal (grub_tpm2_buffer_t buf,
|
||||
+ TPMT_TK_VERIFIED *p);
|
||||
+
|
||||
void
|
||||
grub_tpm2_mu_TPMS_PCR_SELECTION_Unmarshal (grub_tpm2_buffer_t buf,
|
||||
TPMS_PCR_SELECTION* pcrSelection);
|
||||
@@ -289,4 +338,30 @@ void
|
||||
grub_tpm2_mu_TPML_DIGEST_Unmarshal (grub_tpm2_buffer_t buf,
|
||||
TPML_DIGEST* digest);
|
||||
|
||||
+void
|
||||
+grub_tpm2_mu_TPMS_SIGNATURE_RSA_Unmarshal (grub_tpm2_buffer_t buf,
|
||||
+ TPMS_SIGNATURE_RSA *p);
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMS_SIGNATURE_ECC_Unmarshal (grub_tpm2_buffer_t buf,
|
||||
+ TPMS_SIGNATURE_ECC *p);
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMU_HA_Unmarshal (grub_tpm2_buffer_t buf,
|
||||
+ TPMI_ALG_HASH hashAlg,
|
||||
+ TPMU_HA *p);
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMT_HA_Unmarshal (grub_tpm2_buffer_t buf,
|
||||
+ TPMT_HA *p);
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMU_SIGNATURE_Unmarshal (grub_tpm2_buffer_t buf,
|
||||
+ TPMI_ALG_SIG_SCHEME sigAlg,
|
||||
+ TPMU_SIGNATURE *p);
|
||||
+
|
||||
+void
|
||||
+grub_tpm2_mu_TPMT_SIGNATURE_Unmarshal (grub_tpm2_buffer_t buf,
|
||||
+ TPMT_SIGNATURE *p);
|
||||
+
|
||||
#endif /* ! GRUB_TPM2_MU_HEADER */
|
||||
--
|
||||
2.35.3
|
||||
|
||||
@ -1,46 +1,20 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From 25069a23257ba9c6db644bbe6114dafb879063e5 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Jones <pjones@redhat.com>
|
||||
Date: Mon, 8 Jul 2019 12:32:37 +0200
|
||||
Subject: [PATCH] Handle multi-arch (64-on-32) boot in linuxefi loader.
|
||||
Subject: [PATCH 03/11] Handle multi-arch (64-on-32) boot in linuxefi loader.
|
||||
|
||||
Allow booting 64-bit kernels on 32-bit EFI on x86.
|
||||
|
||||
Signed-off-by: Peter Jones <pjones@redhat.com>
|
||||
---
|
||||
grub-core/loader/efi/linux.c | 9 +++-
|
||||
grub-core/loader/i386/efi/linux.c | 110 ++++++++++++++++++++++++++------------
|
||||
include/grub/i386/linux.h | 7 ++-
|
||||
3 files changed, 89 insertions(+), 37 deletions(-)
|
||||
grub-core/loader/efi/linux.c | 11 ++-
|
||||
grub-core/loader/i386/efi/linux.c | 127 +++++++++++++++++++-----------
|
||||
include/grub/i386/linux.h | 7 +-
|
||||
3 files changed, 97 insertions(+), 48 deletions(-)
|
||||
|
||||
diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
|
||||
index c8ecce6dfd0..0622dfa48d4 100644
|
||||
--- a/grub-core/loader/efi/linux.c
|
||||
+++ b/grub-core/loader/efi/linux.c
|
||||
@@ -69,12 +69,17 @@ grub_linuxefi_secure_validate (void *data, grub_uint32_t size)
|
||||
typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *);
|
||||
|
||||
grub_err_t
|
||||
-grub_efi_linux_boot (void *kernel_addr, grub_off_t offset,
|
||||
+grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset,
|
||||
void *kernel_params)
|
||||
{
|
||||
handover_func hf;
|
||||
+ int offset = 0;
|
||||
|
||||
- hf = (handover_func)((char *)kernel_addr + offset);
|
||||
+#ifdef __x86_64__
|
||||
+ offset = 512;
|
||||
+#endif
|
||||
+
|
||||
+ hf = (handover_func)((char *)kernel_addr + handover_offset + offset);
|
||||
hf (grub_efi_image_handle, grub_efi_system_table, kernel_params);
|
||||
|
||||
return GRUB_ERR_BUG;
|
||||
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
|
||||
index 6b24cbb9483..3017d0f3e52 100644
|
||||
--- a/grub-core/loader/i386/efi/linux.c
|
||||
+++ b/grub-core/loader/i386/efi/linux.c
|
||||
@@ -44,14 +44,10 @@ static char *linux_cmdline;
|
||||
@@ -44,14 +44,10 @@
|
||||
static grub_err_t
|
||||
grub_linuxefi_boot (void)
|
||||
{
|
||||
@ -57,7 +31,7 @@ index 6b24cbb9483..3017d0f3e52 100644
|
||||
params);
|
||||
}
|
||||
|
||||
@@ -153,14 +149,20 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -147,14 +143,20 @@
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
@ -77,10 +51,10 @@ index 6b24cbb9483..3017d0f3e52 100644
|
||||
+ grub_ssize_t start, filelen;
|
||||
void *kernel = NULL;
|
||||
+ int setup_header_end_offset;
|
||||
int rc;
|
||||
grub_err_t err;
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
@@ -200,48 +202,79 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -185,45 +187,79 @@
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -94,14 +68,12 @@ index 6b24cbb9483..3017d0f3e52 100644
|
||||
goto fail;
|
||||
}
|
||||
|
||||
- grub_dprintf ("linux", "params = %lx\n", (unsigned long) params);
|
||||
- grub_memset (params, 0, 16384);
|
||||
+ grub_dprintf ("linux", "params = %p\n", params);
|
||||
|
||||
- grub_memset (params, 0, 16384);
|
||||
- grub_memcpy (&lh, kernel, sizeof (lh));
|
||||
+ grub_memset (params, 0, sizeof(*params));
|
||||
|
||||
- grub_memcpy (&lh, kernel, sizeof (lh));
|
||||
-
|
||||
- if (lh.boot_flag != grub_cpu_to_le16 (0xaa55))
|
||||
+ setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201);
|
||||
+ grub_dprintf ("linux", "copying %lu bytes from %p to %p\n",
|
||||
@ -145,6 +117,8 @@ index 6b24cbb9483..3017d0f3e52 100644
|
||||
goto fail;
|
||||
}
|
||||
|
||||
- linux_cmdline = grub_efi_allocate_pages_max(0x3fffffff,
|
||||
- BYTES_TO_PAGES(lh.cmdline_size + 1));
|
||||
+#if defined(__x86_64__) || defined(__aarch64__)
|
||||
+ grub_dprintf ("linux", "checking lh->xloadflags\n");
|
||||
+ if (!(lh->xloadflags & LINUX_XLF_KERNEL_64))
|
||||
@ -153,7 +127,7 @@ index 6b24cbb9483..3017d0f3e52 100644
|
||||
+ goto fail;
|
||||
+ }
|
||||
+#endif
|
||||
+
|
||||
|
||||
+#if defined(__i386__)
|
||||
+ if ((lh->xloadflags & LINUX_XLF_KERNEL_64) &&
|
||||
+ !(lh->xloadflags & LINUX_XLF_EFI_HANDOVER_32))
|
||||
@ -164,21 +138,21 @@ index 6b24cbb9483..3017d0f3e52 100644
|
||||
+ }
|
||||
+#endif
|
||||
+
|
||||
grub_dprintf ("linux", "setting up cmdline\n");
|
||||
linux_cmdline = grub_efi_allocate_pages_max(0x3fffffff,
|
||||
- BYTES_TO_PAGES(lh.cmdline_size + 1));
|
||||
-
|
||||
+ grub_dprintf ("linux", "setting up cmdline\n");
|
||||
+ linux_cmdline = grub_efi_allocate_pages_max(0x3fffffff,
|
||||
+ BYTES_TO_PAGES(lh->cmdline_size + 1));
|
||||
if (!linux_cmdline)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate cmdline"));
|
||||
@@ -254,22 +287,24 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -233,27 +269,26 @@
|
||||
grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
grub_create_loader_cmdline (argc, argv,
|
||||
err = grub_create_loader_cmdline (argc, argv,
|
||||
linux_cmdline + sizeof (LINUX_IMAGE) - 1,
|
||||
- lh.cmdline_size - (sizeof (LINUX_IMAGE) - 1),
|
||||
+ lh->cmdline_size - (sizeof (LINUX_IMAGE) - 1),
|
||||
GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
if (err)
|
||||
goto fail;
|
||||
|
||||
- lh.cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline;
|
||||
+ grub_dprintf ("linux", "cmdline:%s\n", linux_cmdline);
|
||||
@ -193,19 +167,23 @@ index 6b24cbb9483..3017d0f3e52 100644
|
||||
- len = grub_file_size(file) - start;
|
||||
+ start = (lh->setup_sects + 1) * 512;
|
||||
|
||||
- kernel_mem = grub_efi_allocate_pages_max(lh.pref_address,
|
||||
- BYTES_TO_PAGES(lh.init_size));
|
||||
- kernel_mem = grub_efi_allocate_fixed (lh.pref_address,
|
||||
- BYTES_TO_PAGES(lh.init_size));
|
||||
+ kernel_mem = grub_efi_allocate_pages_max(lh->pref_address,
|
||||
+ BYTES_TO_PAGES(lh->init_size));
|
||||
|
||||
if (!kernel_mem)
|
||||
kernel_mem = grub_efi_allocate_pages_max(0x3fffffff,
|
||||
- {
|
||||
- grub_errno = GRUB_ERR_NONE;
|
||||
- kernel_mem = grub_efi_allocate_pages_max(0x3fffffff,
|
||||
- BYTES_TO_PAGES(lh.init_size));
|
||||
- }
|
||||
+ kernel_mem = grub_efi_allocate_pages_max(0x3fffffff,
|
||||
+ BYTES_TO_PAGES(lh->init_size));
|
||||
|
||||
if (!kernel_mem)
|
||||
{
|
||||
@@ -277,14 +312,21 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -261,21 +296,23 @@
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -218,47 +196,82 @@ index 6b24cbb9483..3017d0f3e52 100644
|
||||
+ lh->code32_start = (grub_uint32_t)(grub_addr_t) kernel_mem;
|
||||
|
||||
- lh.code32_start = (grub_uint32_t)(grub_uint64_t) kernel_mem;
|
||||
- grub_memcpy (params, &lh, 2 * 512);
|
||||
- /* Grub linuxefi erroneously initialize linux's boot_params with non-zero values. (bsc#1025563)
|
||||
+ grub_memcpy (kernel_mem, (char *)kernel + start, filelen - start);
|
||||
|
||||
- params->type_of_loader = 0x21;
|
||||
- From https://www.kernel.org/doc/Documentation/x86/boot.txt:
|
||||
- The memory for struct boot_params could be allocated anywhere (even above 4G)
|
||||
- and initialized to all zero.
|
||||
- Then, the setup header at offset 0x01f1 of kernel image on should be
|
||||
- loaded into struct boot_params and examined. */
|
||||
- grub_memcpy (¶ms->setup_sects, &lh.setup_sects, sizeof (lh) - 0x01f1);
|
||||
+ grub_dprintf ("linux", "setting lh->type_of_loader\n");
|
||||
+ lh->type_of_loader = 0x6;
|
||||
+
|
||||
|
||||
- params->type_of_loader = 0x21;
|
||||
+ grub_dprintf ("linux", "setting lh->ext_loader_{type,ver}\n");
|
||||
+ params->ext_loader_type = 0;
|
||||
+ params->ext_loader_ver = 2;
|
||||
grub_dprintf("linux", "kernel_mem: %p handover_offset: %08x\n",
|
||||
kernel_mem, handover_offset);
|
||||
+ grub_dprintf("linux", "kernel_mem: %p handover_offset: %08x\n",
|
||||
+ kernel_mem, handover_offset);
|
||||
|
||||
@@ -301,10 +343,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
fail:
|
||||
|
||||
@@ -291,8 +328,10 @@
|
||||
loaded = 0;
|
||||
}
|
||||
|
||||
- if (linux_cmdline && !loaded)
|
||||
- grub_efi_free_pages((grub_efi_physical_address_t)(grub_addr_t)linux_cmdline, BYTES_TO_PAGES(lh.cmdline_size + 1));
|
||||
+ if (linux_cmdline && lh && !loaded)
|
||||
grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)
|
||||
linux_cmdline,
|
||||
- BYTES_TO_PAGES(lh.cmdline_size + 1));
|
||||
+ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)
|
||||
+ linux_cmdline,
|
||||
+ BYTES_TO_PAGES(lh->cmdline_size + 1));
|
||||
|
||||
if (kernel_mem && !loaded)
|
||||
grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem,
|
||||
diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h
|
||||
index eddf9251d9a..25ef52c04eb 100644
|
||||
grub_efi_free_pages((grub_efi_physical_address_t)(grub_addr_t)kernel_mem, BYTES_TO_PAGES(kernel_size));
|
||||
--- a/include/grub/i386/linux.h
|
||||
+++ b/include/grub/i386/linux.h
|
||||
@@ -138,7 +138,12 @@ struct linux_i386_kernel_header
|
||||
@@ -148,6 +148,11 @@
|
||||
grub_uint32_t kernel_alignment;
|
||||
grub_uint8_t relocatable;
|
||||
grub_uint8_t min_alignment;
|
||||
- grub_uint8_t pad[2];
|
||||
+#define LINUX_XLF_KERNEL_64 (1<<0)
|
||||
+#define LINUX_XLF_CAN_BE_LOADED_ABOVE_4G (1<<1)
|
||||
+#define LINUX_XLF_EFI_HANDOVER_32 (1<<2)
|
||||
+#define LINUX_XLF_EFI_HANDOVER_64 (1<<3)
|
||||
+#define LINUX_XLF_EFI_KEXEC (1<<4)
|
||||
+ grub_uint16_t xloadflags;
|
||||
grub_uint16_t xloadflags;
|
||||
grub_uint32_t cmdline_size;
|
||||
grub_uint32_t hardware_subarch;
|
||||
grub_uint64_t hardware_subarch_data;
|
||||
--- a/grub-core/loader/efi/linux_boot.c
|
||||
+++ b/grub-core/loader/efi/linux_boot.c
|
||||
@@ -30,11 +30,16 @@
|
||||
typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *);
|
||||
|
||||
grub_err_t
|
||||
-grub_efi_linux_boot (void *kernel_addr, grub_off_t offset,
|
||||
+grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset,
|
||||
void *kernel_params)
|
||||
{
|
||||
grub_efi_loaded_image_t *loaded_image = NULL;
|
||||
handover_func hf;
|
||||
+ int offset = 0;
|
||||
+
|
||||
+#ifdef __x86_64__
|
||||
+ offset = 512;
|
||||
+#endif
|
||||
|
||||
/*
|
||||
* Since the EFI loader is not calling the LoadImage() and StartImage()
|
||||
@@ -48,8 +53,8 @@
|
||||
grub_dprintf ("linux", "Loaded Image base address could not be set\n");
|
||||
|
||||
grub_dprintf ("linux", "kernel_addr: %p handover_offset: %p params: %p\n",
|
||||
- kernel_addr, (void *)(grub_efi_uintn_t)offset, kernel_params);
|
||||
- hf = (handover_func)((char *)kernel_addr + offset);
|
||||
+ kernel_addr, (void *)(grub_efi_uintn_t)handover_offset, kernel_params);
|
||||
+ hf = (handover_func)((char *)kernel_addr + handover_offset + offset);
|
||||
hf (grub_efi_image_handle, grub_efi_system_table, kernel_params);
|
||||
|
||||
return GRUB_ERR_BUG;
|
||||
@ -1,19 +1,18 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From 3526c4e467ee01a3cfd2f4d627433d078a1ab780 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Jones <pjones@redhat.com>
|
||||
Date: Mon, 27 Aug 2018 13:14:06 -0400
|
||||
Subject: [PATCH] Make grub_error() more verbose
|
||||
Subject: [PATCH 3/9] Make grub_error() more verbose
|
||||
|
||||
Signed-off-by: Peter Jones <pjones@redhat.com>
|
||||
---
|
||||
grub-core/kern/err.c | 13 +++++++++++--
|
||||
include/grub/err.h | 8 ++++++--
|
||||
2 files changed, 17 insertions(+), 4 deletions(-)
|
||||
grub-core/kern/efi/mm.c | 17 ++++++++++++++---
|
||||
grub-core/kern/err.c | 13 +++++++++++--
|
||||
include/grub/err.h | 5 ++++-
|
||||
3 files changed, 29 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/grub-core/kern/err.c b/grub-core/kern/err.c
|
||||
index 53c734de70e..aebfe0cf839 100644
|
||||
--- a/grub-core/kern/err.c
|
||||
+++ b/grub-core/kern/err.c
|
||||
@@ -33,15 +33,24 @@ static struct grub_error_saved grub_error_stack_items[GRUB_ERROR_STACK_SIZE];
|
||||
@@ -33,15 +33,24 @@
|
||||
static int grub_error_stack_pos;
|
||||
static int grub_error_stack_assert;
|
||||
|
||||
@ -40,21 +39,18 @@ index 53c734de70e..aebfe0cf839 100644
|
||||
va_end (ap);
|
||||
|
||||
return n;
|
||||
diff --git a/include/grub/err.h b/include/grub/err.h
|
||||
index b08d5d0de4c..c0f90ef07c8 100644
|
||||
--- a/include/grub/err.h
|
||||
+++ b/include/grub/err.h
|
||||
@@ -85,8 +85,12 @@ struct grub_error_saved
|
||||
@@ -86,8 +86,11 @@
|
||||
extern grub_err_t EXPORT_VAR(grub_errno);
|
||||
extern char EXPORT_VAR(grub_errmsg)[GRUB_MAX_ERRMSG];
|
||||
|
||||
-grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *fmt, ...)
|
||||
- __attribute__ ((format (GNU_PRINTF, 2, 3)));
|
||||
+grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *file, const int line, const char *fmt, ...)
|
||||
+ __attribute__ ((format (GNU_PRINTF, 4, 5)));
|
||||
+ __attribute__ ((format (GNU_PRINTF, 4, 5)));
|
||||
+
|
||||
+#define grub_error(n, fmt, ...) grub_error (n, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
|
||||
+
|
||||
+
|
||||
void EXPORT_FUNC(grub_fatal) (const char *fmt, ...) __attribute__ ((noreturn));
|
||||
void EXPORT_FUNC(grub_error_push) (void);
|
||||
117
0003-Restrict-ls-and-auto-file-completion-on-cryptodisk-p.patch
Normal file
117
0003-Restrict-ls-and-auto-file-completion-on-cryptodisk-p.patch
Normal file
@ -0,0 +1,117 @@
|
||||
From 6c8d390809956d355fed8bc830f64e86838e3e82 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Sat, 18 Nov 2023 21:42:00 +0800
|
||||
Subject: [PATCH 3/4] Restrict 'ls' and auto file completion on cryptodisk
|
||||
print
|
||||
|
||||
The 'ls' command allows file listing, while file completion assists in
|
||||
providing matched file names by partially inputting via the TAB key.
|
||||
Both functionalities should be restricted when the disk is automatically
|
||||
unlocked for the same reasons as highlighted in the previous patch
|
||||
addressing the limitation on file access to the cryptodisk.
|
||||
|
||||
Given that no file is explicitly opened for listing, employing file
|
||||
filters becomes impractical. Consequently, this patch focuses on
|
||||
modifying relevant routines separately to incorporate necessary checks.
|
||||
The objective is to introduce measures that prevent 'ls' and auto file
|
||||
completion from accessing encrypted data when the disk is automatically
|
||||
unlocked.
|
||||
|
||||
By implementing these modifications, any attempt to utilize 'ls' or file
|
||||
completion on the cryptodisk will result in an "Access Denied:
|
||||
prohibited to browse encrypted data" error message, thus effectively
|
||||
alerting the user about the restricted access.
|
||||
|
||||
While protecting content within disk files from viewing is essential,
|
||||
it's equally crucial to restrict access to in-memory content. This
|
||||
includes prohibiting access to the decrypted in-memory copies of disk
|
||||
files.
|
||||
|
||||
This enhancement aims to fortify security protocols by extending
|
||||
restrictions to additional functionalities beyond direct file access.
|
||||
|
||||
Signed-Off-by Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/commands/ls.c | 8 ++++++++
|
||||
grub-core/commands/minicmd.c | 6 ++++++
|
||||
grub-core/kern/corecmd.c | 8 ++++++++
|
||||
grub-core/normal/completion.c | 8 ++++++++
|
||||
4 files changed, 30 insertions(+)
|
||||
|
||||
diff --git a/grub-core/commands/ls.c b/grub-core/commands/ls.c
|
||||
index 8e98c73cc..aeb336a73 100644
|
||||
--- a/grub-core/commands/ls.c
|
||||
+++ b/grub-core/commands/ls.c
|
||||
@@ -183,6 +183,14 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
|
||||
if (! dev)
|
||||
goto fail;
|
||||
|
||||
+ if (dev->disk &&
|
||||
+ grub_disk_is_crypto (dev->disk) &&
|
||||
+ grub_file_filters[GRUB_FILE_FILTER_NOCAT])
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_ACCESS_DENIED, N_("prohibited to browse encrypted content"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
fs = grub_fs_probe (dev);
|
||||
path = grub_strchr (dirname, ')');
|
||||
if (! path)
|
||||
diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c
|
||||
index fa498931e..8f2ac0539 100644
|
||||
--- a/grub-core/commands/minicmd.c
|
||||
+++ b/grub-core/commands/minicmd.c
|
||||
@@ -101,6 +101,12 @@ grub_mini_cmd_dump (struct grub_command *cmd __attribute__ ((unused)),
|
||||
if (argc == 0)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no address specified");
|
||||
|
||||
+ /* NOCAT filter is applied to prevent cat alike command from revealing file
|
||||
+ * content, the dump command should also be prohibited to revealing memory
|
||||
+ * content as well */
|
||||
+ if (grub_file_filters[GRUB_FILE_FILTER_NOCAT])
|
||||
+ return grub_error (GRUB_ERR_ACCESS_DENIED, N_("prohibited by security policy"));
|
||||
+
|
||||
#if GRUB_CPU_SIZEOF_VOID_P == GRUB_CPU_SIZEOF_LONG
|
||||
#define grub_strtoaddr grub_strtoul
|
||||
#else
|
||||
diff --git a/grub-core/kern/corecmd.c b/grub-core/kern/corecmd.c
|
||||
index 62d434ba9..b639bc3ae 100644
|
||||
--- a/grub-core/kern/corecmd.c
|
||||
+++ b/grub-core/kern/corecmd.c
|
||||
@@ -135,6 +135,14 @@ grub_core_cmd_ls (struct grub_command *cmd __attribute__ ((unused)),
|
||||
if (! dev)
|
||||
goto fail;
|
||||
|
||||
+ if (dev->disk &&
|
||||
+ grub_disk_is_crypto (dev->disk) &&
|
||||
+ grub_file_filters[GRUB_FILE_FILTER_NOCAT])
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_ACCESS_DENIED, N_("prohibited to browse encrypted content"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
fs = grub_fs_probe (dev);
|
||||
path = grub_strchr (argv[0], ')');
|
||||
if (! path)
|
||||
diff --git a/grub-core/normal/completion.c b/grub-core/normal/completion.c
|
||||
index 18cadfa85..d003ec37d 100644
|
||||
--- a/grub-core/normal/completion.c
|
||||
+++ b/grub-core/normal/completion.c
|
||||
@@ -259,6 +259,14 @@ complete_file (void)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
+ if (dev->disk &&
|
||||
+ grub_disk_is_crypto (dev->disk) &&
|
||||
+ grub_file_filters[GRUB_FILE_FILTER_NOCAT])
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_ACCESS_DENIED, N_("prohibited to browse encrypted content"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
fs = grub_fs_probe (dev);
|
||||
if (! fs)
|
||||
{
|
||||
--
|
||||
2.42.1
|
||||
|
||||
@ -1,70 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Javier Martinez Canillas <javierm@redhat.com>
|
||||
Date: Fri, 11 Jun 2021 12:10:58 +0200
|
||||
Subject: [PATCH] Revert "templates: Disable the os-prober by default"
|
||||
|
||||
This reverts commit e346414725a70e5c74ee87ca14e580c66f517666.
|
||||
---
|
||||
docs/grub.texi | 18 ++++++++----------
|
||||
util/grub.d/30_os-prober.in | 5 +----
|
||||
2 files changed, 9 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/docs/grub.texi b/docs/grub.texi
|
||||
index f8b4b3b21a7..69f08d289f9 100644
|
||||
--- a/docs/grub.texi
|
||||
+++ b/docs/grub.texi
|
||||
@@ -1519,13 +1519,10 @@ boot sequence. If you have problems, set this option to @samp{text} and
|
||||
GRUB will tell Linux to boot in normal text mode.
|
||||
|
||||
@item GRUB_DISABLE_OS_PROBER
|
||||
-The @command{grub-mkconfig} has a feature to use the external
|
||||
-@command{os-prober} program to discover other operating systems installed on
|
||||
-the same machine and generate appropriate menu entries for them. It is disabled
|
||||
-by default since automatic and silent execution of @command{os-prober}, and
|
||||
-creating boot entries based on that data, is a potential attack vector. Set
|
||||
-this option to @samp{false} to enable this feature in the
|
||||
-@command{grub-mkconfig} command.
|
||||
+Normally, @command{grub-mkconfig} will try to use the external
|
||||
+@command{os-prober} program, if installed, to discover other operating
|
||||
+systems installed on the same system and generate appropriate menu entries
|
||||
+for them. Set this option to @samp{true} to disable this.
|
||||
|
||||
@item GRUB_OS_PROBER_SKIP_LIST
|
||||
List of space-separated FS UUIDs of filesystems to be ignored from os-prober
|
||||
@@ -1853,9 +1850,10 @@ than zero; otherwise 0.
|
||||
@section Multi-boot manual config
|
||||
|
||||
Currently autogenerating config files for multi-boot environments depends on
|
||||
-os-prober and has several shortcomings. Due to that it is disabled by default.
|
||||
-It is advised to use the power of GRUB syntax and do it yourself. A possible
|
||||
-configuration is detailed here, feel free to adjust to your needs.
|
||||
+os-prober and has several shortcomings. While fixing it is scheduled for the
|
||||
+next release, meanwhile you can make use of the power of GRUB syntax and do it
|
||||
+yourself. A possible configuration is detailed here, feel free to adjust to your
|
||||
+needs.
|
||||
|
||||
First create a separate GRUB partition, big enough to hold GRUB. Some of the
|
||||
following entries show how to load OS installer images from this same partition,
|
||||
diff --git a/util/grub.d/30_os-prober.in b/util/grub.d/30_os-prober.in
|
||||
index 80685b15f4d..1b91c102f35 100644
|
||||
--- a/util/grub.d/30_os-prober.in
|
||||
+++ b/util/grub.d/30_os-prober.in
|
||||
@@ -26,8 +26,7 @@ export TEXTDOMAINDIR="@localedir@"
|
||||
|
||||
. "$pkgdatadir/grub-mkconfig_lib"
|
||||
|
||||
-if [ "x${GRUB_DISABLE_OS_PROBER}" = "xfalse" ]; then
|
||||
- gettext_printf "os-prober will not be executed to detect other bootable partitions.\nSystems on them will not be added to the GRUB boot configuration.\nCheck GRUB_DISABLE_OS_PROBER documentation entry.\n"
|
||||
+if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@@ -40,8 +39,6 @@ OSPROBED="`os-prober | tr ' ' '^' | paste -s -d ' '`"
|
||||
if [ -z "${OSPROBED}" ] ; then
|
||||
# empty os-prober output, nothing doing
|
||||
exit 0
|
||||
-else
|
||||
- grub_warn "$(gettext_printf "os-prober was executed to detect other bootable partitions.\nIt's output will be used to detect bootable binaries on them and create new boot entries.")"
|
||||
fi
|
||||
|
||||
osx_entry() {
|
||||
@ -1,25 +1,24 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From f6c8c7985fd88fc89cd49227c9e74feaf58cfdd6 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Wed, 10 Jul 2019 15:42:36 +0200
|
||||
Subject: [PATCH] bootp: New net_bootp6 command
|
||||
Date: Sun, 10 Jul 2016 23:46:06 +0800
|
||||
Subject: [PATCH 3/8] bootp: New net_bootp6 command
|
||||
|
||||
Implement new net_bootp6 command for IPv6 network auto configuration via the
|
||||
DHCPv6 protocol (RFC3315).
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
Signed-off-by: Ken Lin <ken.lin@hpe.com>
|
||||
[pjones: Put back our code to add a local route]
|
||||
Signed-off-by: Peter Jones <pjones@redhat.com>
|
||||
---
|
||||
grub-core/net/bootp.c | 1059 ++++++++++++++++++++++++++++++------
|
||||
grub-core/net/drivers/efi/efinet.c | 20 +-
|
||||
grub-core/net/ip.c | 39 ++
|
||||
include/grub/efi/api.h | 2 +-
|
||||
include/grub/net.h | 91 ++--
|
||||
5 files changed, 1002 insertions(+), 209 deletions(-)
|
||||
|
||||
diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
|
||||
index 08b6b2b5d6c..fe93b80f1cf 100644
|
||||
V1:
|
||||
* Use grub_calloc for overflow check and return NULL when it would
|
||||
occur.
|
||||
|
||||
---
|
||||
grub-core/net/bootp.c | 908 +++++++++++++++++++++++++++++++++++++++++++++++++-
|
||||
grub-core/net/ip.c | 39 +++
|
||||
include/grub/net.h | 72 ++++
|
||||
3 files changed, 1018 insertions(+), 1 deletion(-)
|
||||
|
||||
--- a/grub-core/net/bootp.c
|
||||
+++ b/grub-core/net/bootp.c
|
||||
@@ -24,6 +24,98 @@
|
||||
@ -121,7 +120,7 @@ index 08b6b2b5d6c..fe93b80f1cf 100644
|
||||
|
||||
struct grub_dhcp_discover_options
|
||||
{
|
||||
@@ -604,6 +696,584 @@ out:
|
||||
@@ -610,6 +702,578 @@
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -269,7 +268,7 @@ index 08b6b2b5d6c..fe93b80f1cf 100644
|
||||
+ break;
|
||||
+ }
|
||||
+ dhcp6->num_dns_server = ln = len >> 4;
|
||||
+ dhcp6->dns_server_addrs = la = grub_zalloc (ln * sizeof (*la));
|
||||
+ dhcp6->dns_server_addrs = la = grub_calloc (ln, sizeof (*la));
|
||||
+
|
||||
+ for (po = opt->data; ln > 0; po += 0x10, la++, ln--)
|
||||
+ {
|
||||
@ -372,7 +371,6 @@ index 08b6b2b5d6c..fe93b80f1cf 100644
|
||||
+}
|
||||
+
|
||||
+static grub_dhcp6_session_t grub_dhcp6_sessions;
|
||||
+#define FOR_DHCP6_SESSIONS_SAFE(var, next) FOR_LIST_ELEMENTS_SAFE (var, next, grub_dhcp6_sessions)
|
||||
+#define FOR_DHCP6_SESSIONS(var) FOR_LIST_ELEMENTS (var, grub_dhcp6_sessions)
|
||||
+
|
||||
+static void
|
||||
@ -427,7 +425,7 @@ index 08b6b2b5d6c..fe93b80f1cf 100644
|
||||
+ grub_dhcp6_session_t se;
|
||||
+ struct grub_datetime date;
|
||||
+ grub_err_t err;
|
||||
+ grub_int32_t t = 0;
|
||||
+ grub_int64_t t = 0;
|
||||
+
|
||||
+ se = grub_malloc (sizeof (*se));
|
||||
+
|
||||
@ -464,13 +462,13 @@ index 08b6b2b5d6c..fe93b80f1cf 100644
|
||||
+static void
|
||||
+grub_dhcp6_session_remove_all (void)
|
||||
+{
|
||||
+ grub_dhcp6_session_t se, next;
|
||||
+ grub_dhcp6_session_t se;
|
||||
+
|
||||
+ FOR_DHCP6_SESSIONS_SAFE (se, next)
|
||||
+ FOR_DHCP6_SESSIONS (se)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove (se);
|
||||
+ se = grub_dhcp6_sessions;
|
||||
+ }
|
||||
+ grub_dhcp6_sessions = NULL;
|
||||
+}
|
||||
+
|
||||
+static grub_err_t
|
||||
@ -664,7 +662,6 @@ index 08b6b2b5d6c..fe93b80f1cf 100644
|
||||
+{
|
||||
+ struct grub_net_network_level_interface *inf;
|
||||
+ grub_dhcp6_options_t dhcp6;
|
||||
+ int mask = -1;
|
||||
+
|
||||
+ dhcp6 = grub_dhcp6_options_get (v6h, size);
|
||||
+ if (!dhcp6)
|
||||
@ -696,23 +693,19 @@ index 08b6b2b5d6c..fe93b80f1cf 100644
|
||||
+ }
|
||||
+
|
||||
+ grub_dhcp6_options_free (dhcp6);
|
||||
+
|
||||
+ if (inf)
|
||||
+ grub_net_add_ipv6_local (inf, mask);
|
||||
+
|
||||
+ return inf;
|
||||
+}
|
||||
+
|
||||
/*
|
||||
* This is called directly from net/ip.c:handle_dgram(), because those
|
||||
* BOOTP/DHCP packets are a bit special due to their improper
|
||||
@@ -672,6 +1342,77 @@ grub_net_process_dhcp (struct grub_net_buff *nb,
|
||||
@@ -678,6 +1342,77 @@
|
||||
}
|
||||
}
|
||||
|
||||
+grub_err_t
|
||||
+grub_net_process_dhcp6 (struct grub_net_buff *nb,
|
||||
+ struct grub_net_card *card __attribute__ ((unused)))
|
||||
+ struct grub_net_card *card __attribute__ ((unused)))
|
||||
+{
|
||||
+ const struct grub_net_dhcp6_packet *v6h;
|
||||
+ grub_dhcp6_session_t se;
|
||||
@ -735,9 +728,9 @@ index 08b6b2b5d6c..fe93b80f1cf 100644
|
||||
+ FOR_DHCP6_SESSIONS (se)
|
||||
+ {
|
||||
+ if (se->transaction_id == v6h->transaction_id &&
|
||||
+ grub_memcmp (options->client_duid, &se->duid, sizeof (se->duid)) == 0 &&
|
||||
+ se->iaid == options->iaid)
|
||||
+ break;
|
||||
+ grub_memcmp (options->client_duid, &se->duid, sizeof (se->duid)) == 0 &&
|
||||
+ se->iaid == options->iaid)
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ if (!se)
|
||||
@ -750,11 +743,11 @@ index 08b6b2b5d6c..fe93b80f1cf 100644
|
||||
+ if (v6h->message_type == GRUB_NET_DHCP6_ADVERTISE)
|
||||
+ {
|
||||
+ if (se->adv)
|
||||
+ {
|
||||
+ grub_dprintf ("bootp", "Skipped DHCPv6 Advertised .. \n");
|
||||
+ grub_dhcp6_options_free (options);
|
||||
+ return GRUB_ERR_NONE;
|
||||
+ }
|
||||
+ {
|
||||
+ grub_dprintf ("bootp", "Skipped DHCPv6 Advertised .. \n");
|
||||
+ grub_dhcp6_options_free (options);
|
||||
+ return GRUB_ERR_NONE;
|
||||
+ }
|
||||
+
|
||||
+ se->adv = options;
|
||||
+ return grub_dhcp6_session_send_request (se);
|
||||
@ -762,11 +755,11 @@ index 08b6b2b5d6c..fe93b80f1cf 100644
|
||||
+ else if (v6h->message_type == GRUB_NET_DHCP6_REPLY)
|
||||
+ {
|
||||
+ if (!se->adv)
|
||||
+ {
|
||||
+ grub_dprintf ("bootp", "Skipped DHCPv6 Reply .. \n");
|
||||
+ grub_dhcp6_options_free (options);
|
||||
+ return GRUB_ERR_NONE;
|
||||
+ }
|
||||
+ {
|
||||
+ grub_dprintf ("bootp", "Skipped DHCPv6 Reply .. \n");
|
||||
+ grub_dhcp6_options_free (options);
|
||||
+ return GRUB_ERR_NONE;
|
||||
+ }
|
||||
+
|
||||
+ se->reply = options;
|
||||
+ grub_dhcp6_session_configure_network (se);
|
||||
@ -784,342 +777,183 @@ index 08b6b2b5d6c..fe93b80f1cf 100644
|
||||
static grub_err_t
|
||||
grub_cmd_dhcpopt (struct grub_command *cmd __attribute__ ((unused)),
|
||||
int argc, char **args)
|
||||
@@ -897,180 +1638,174 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)),
|
||||
@@ -903,7 +1638,174 @@
|
||||
return err;
|
||||
}
|
||||
|
||||
-static grub_command_t cmd_getdhcp, cmd_bootp, cmd_dhcp;
|
||||
-
|
||||
-struct grub_net_network_level_interface *
|
||||
-grub_net_configure_by_dhcpv6_ack (const char *name,
|
||||
- struct grub_net_card *card,
|
||||
- grub_net_interface_flags_t flags
|
||||
- __attribute__((__unused__)),
|
||||
- const grub_net_link_level_address_t *hwaddr,
|
||||
- const struct grub_net_dhcpv6_packet *packet,
|
||||
- int is_def, char **device, char **path)
|
||||
+static grub_err_t
|
||||
+grub_cmd_bootp6 (struct grub_command *cmd __attribute__ ((unused)),
|
||||
+ int argc, char **args)
|
||||
{
|
||||
- struct grub_net_network_level_interface *inter = NULL;
|
||||
- struct grub_net_network_level_address addr;
|
||||
- int mask = -1;
|
||||
+ int argc, char **args)
|
||||
+{
|
||||
+ struct grub_net_card *card;
|
||||
+ grub_uint32_t iaid = 0;
|
||||
+ int interval;
|
||||
+ grub_err_t err;
|
||||
+ grub_dhcp6_session_t se;
|
||||
|
||||
- if (!device || !path)
|
||||
- return NULL;
|
||||
+
|
||||
+ err = GRUB_ERR_NONE;
|
||||
|
||||
- *device = 0;
|
||||
- *path = 0;
|
||||
+
|
||||
+ FOR_NET_CARDS (card)
|
||||
+ {
|
||||
+ struct grub_net_network_level_interface *iface;
|
||||
|
||||
- grub_dprintf ("net", "mac address is %02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||
- hwaddr->mac[0], hwaddr->mac[1], hwaddr->mac[2],
|
||||
- hwaddr->mac[3], hwaddr->mac[4], hwaddr->mac[5]);
|
||||
+
|
||||
+ if (argc > 0 && grub_strcmp (card->name, args[0]) != 0)
|
||||
+ continue;
|
||||
|
||||
- if (is_def)
|
||||
- grub_net_default_server = 0;
|
||||
+
|
||||
+ iface = grub_net_ipv6_get_link_local (card, &card->default_address);
|
||||
+ if (!iface)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ return grub_errno;
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ return grub_errno;
|
||||
+ }
|
||||
|
||||
- if (is_def && !grub_net_default_server && packet)
|
||||
+
|
||||
+ grub_dhcp6_session_add (iface, iaid++);
|
||||
+ }
|
||||
+
|
||||
+ for (interval = 200; interval < 10000; interval *= 2)
|
||||
{
|
||||
- const grub_uint8_t *options = packet->dhcp_options;
|
||||
- unsigned int option_max = 1024 - OFFSET_OF (dhcp_options, packet);
|
||||
- unsigned int i;
|
||||
-
|
||||
- for (i = 0; i < option_max - sizeof (grub_net_dhcpv6_option_t); )
|
||||
- {
|
||||
- grub_uint16_t num, len;
|
||||
- grub_net_dhcpv6_option_t *opt =
|
||||
- (grub_net_dhcpv6_option_t *)(options + i);
|
||||
-
|
||||
- num = grub_be_to_cpu16(opt->option_num);
|
||||
- len = grub_be_to_cpu16(opt->option_len);
|
||||
-
|
||||
- grub_dprintf ("net", "got dhcpv6 option %d len %d\n", num, len);
|
||||
-
|
||||
- if (len == 0)
|
||||
- break;
|
||||
-
|
||||
- if (len + i > 1024)
|
||||
- break;
|
||||
-
|
||||
- if (num == GRUB_NET_DHCP6_BOOTFILE_URL)
|
||||
- {
|
||||
- char *scheme, *userinfo, *host, *file;
|
||||
- char *tmp;
|
||||
- int hostlen;
|
||||
- int port;
|
||||
- int rc = extract_url_info ((const char *)opt->option_data,
|
||||
- (grub_size_t)len,
|
||||
- &scheme, &userinfo, &host, &port,
|
||||
- &file);
|
||||
- if (rc < 0)
|
||||
- continue;
|
||||
-
|
||||
- /* right now this only handles tftp. */
|
||||
- if (grub_strcmp("tftp", scheme))
|
||||
- {
|
||||
- grub_free (scheme);
|
||||
- grub_free (userinfo);
|
||||
- grub_free (host);
|
||||
- grub_free (file);
|
||||
- continue;
|
||||
- }
|
||||
- grub_free (userinfo);
|
||||
-
|
||||
- hostlen = grub_strlen (host);
|
||||
- if (hostlen > 2 && host[0] == '[' && host[hostlen-1] == ']')
|
||||
- {
|
||||
- tmp = host+1;
|
||||
- host[hostlen-1] = '\0';
|
||||
- }
|
||||
- else
|
||||
- tmp = host;
|
||||
-
|
||||
- *device = grub_xasprintf ("%s,%s", scheme, tmp);
|
||||
- grub_free (scheme);
|
||||
- grub_free (host);
|
||||
-
|
||||
- if (file && *file)
|
||||
- {
|
||||
- tmp = grub_strrchr (file, '/');
|
||||
- if (tmp)
|
||||
- *(tmp+1) = '\0';
|
||||
- else
|
||||
- file[0] = '\0';
|
||||
- }
|
||||
- else if (!file)
|
||||
- file = grub_strdup ("");
|
||||
-
|
||||
- if (file[0] == '/')
|
||||
- {
|
||||
- *path = grub_strdup (file+1);
|
||||
- grub_free (file);
|
||||
- }
|
||||
- else
|
||||
- *path = file;
|
||||
- }
|
||||
- else if (num == GRUB_NET_DHCP6_IA_NA)
|
||||
- {
|
||||
- const grub_net_dhcpv6_option_t *ia_na_opt;
|
||||
- const grub_net_dhcpv6_opt_ia_na_t *ia_na =
|
||||
- (const grub_net_dhcpv6_opt_ia_na_t *)opt;
|
||||
- unsigned int left = len - OFFSET_OF (options, ia_na);
|
||||
- unsigned int j;
|
||||
-
|
||||
- if ((grub_uint8_t *)ia_na + left >
|
||||
- (grub_uint8_t *)options + option_max)
|
||||
- left -= ((grub_uint8_t *)ia_na + left)
|
||||
- - ((grub_uint8_t *)options + option_max);
|
||||
-
|
||||
- if (len < OFFSET_OF (option_data, opt)
|
||||
- + sizeof (grub_net_dhcpv6_option_t))
|
||||
- {
|
||||
- grub_dprintf ("net",
|
||||
- "found dhcpv6 ia_na option with no address\n");
|
||||
- continue;
|
||||
- }
|
||||
-
|
||||
- for (j = 0; left > sizeof (grub_net_dhcpv6_option_t); )
|
||||
- {
|
||||
- ia_na_opt = (const grub_net_dhcpv6_option_t *)
|
||||
- (ia_na->options + j);
|
||||
- grub_uint16_t ia_na_opt_num, ia_na_opt_len;
|
||||
-
|
||||
- ia_na_opt_num = grub_be_to_cpu16 (ia_na_opt->option_num);
|
||||
- ia_na_opt_len = grub_be_to_cpu16 (ia_na_opt->option_len);
|
||||
- if (ia_na_opt_len == 0)
|
||||
- break;
|
||||
- if (j + ia_na_opt_len > left)
|
||||
- break;
|
||||
- if (ia_na_opt_num == GRUB_NET_DHCP6_IA_ADDRESS)
|
||||
- {
|
||||
- const grub_net_dhcpv6_opt_ia_address_t *ia_addr;
|
||||
-
|
||||
- ia_addr = (const grub_net_dhcpv6_opt_ia_address_t *)
|
||||
- ia_na_opt;
|
||||
- addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6;
|
||||
- grub_memcpy(addr.ipv6, ia_addr->ipv6_address,
|
||||
- sizeof (ia_addr->ipv6_address));
|
||||
- inter = grub_net_add_addr (name, card, &addr, hwaddr, 0);
|
||||
- }
|
||||
-
|
||||
- j += ia_na_opt_len;
|
||||
- left -= ia_na_opt_len;
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- i += len + 4;
|
||||
- }
|
||||
-
|
||||
- grub_print_error ();
|
||||
+ {
|
||||
+ int done = 1;
|
||||
+
|
||||
+ FOR_DHCP6_SESSIONS (se)
|
||||
+ {
|
||||
+ struct grub_net_buff *nb;
|
||||
+ struct grub_net_dhcp6_option *opt;
|
||||
+ struct grub_net_dhcp6_packet *v6h;
|
||||
+ struct grub_net_dhcp6_option_duid_ll *duid;
|
||||
+ struct grub_net_dhcp6_option_iana *ia_na;
|
||||
+ grub_net_network_level_address_t multicast;
|
||||
+ grub_net_link_level_address_t ll_multicast;
|
||||
+ struct udphdr *udph;
|
||||
+ {
|
||||
+ struct grub_net_buff *nb;
|
||||
+ struct grub_net_dhcp6_option *opt;
|
||||
+ struct grub_net_dhcp6_packet *v6h;
|
||||
+ struct grub_net_dhcp6_option_duid_ll *duid;
|
||||
+ struct grub_net_dhcp6_option_iana *ia_na;
|
||||
+ grub_net_network_level_address_t multicast;
|
||||
+ grub_net_link_level_address_t ll_multicast;
|
||||
+ struct udphdr *udph;
|
||||
+
|
||||
+ multicast.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6;
|
||||
+ multicast.ipv6[0] = grub_cpu_to_be64_compile_time (0xff02ULL << 48);
|
||||
+ multicast.ipv6[1] = grub_cpu_to_be64_compile_time (0x10002ULL);
|
||||
+ multicast.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6;
|
||||
+ multicast.ipv6[0] = grub_cpu_to_be64_compile_time (0xff02ULL << 48);
|
||||
+ multicast.ipv6[1] = grub_cpu_to_be64_compile_time (0x10002ULL);
|
||||
+
|
||||
+ err = grub_net_link_layer_resolve (se->iface,
|
||||
+ &multicast, &ll_multicast);
|
||||
+ if (err)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ return err;
|
||||
+ }
|
||||
+ err = grub_net_link_layer_resolve (se->iface,
|
||||
+ &multicast, &ll_multicast);
|
||||
+ if (err)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ return err;
|
||||
+ }
|
||||
+
|
||||
+ nb = grub_netbuff_alloc (GRUB_DHCP6_DEFAULT_NETBUFF_ALLOC_SIZE);
|
||||
+ nb = grub_netbuff_alloc (GRUB_DHCP6_DEFAULT_NETBUFF_ALLOC_SIZE);
|
||||
+
|
||||
+ if (!nb)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ return grub_errno;
|
||||
+ }
|
||||
+ if (!nb)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ return grub_errno;
|
||||
+ }
|
||||
+
|
||||
+ err = grub_netbuff_reserve (nb, GRUB_DHCP6_DEFAULT_NETBUFF_ALLOC_SIZE);
|
||||
+ if (err)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ grub_netbuff_free (nb);
|
||||
+ return err;
|
||||
+ }
|
||||
+ err = grub_netbuff_reserve (nb, GRUB_DHCP6_DEFAULT_NETBUFF_ALLOC_SIZE);
|
||||
+ if (err)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ grub_netbuff_free (nb);
|
||||
+ return err;
|
||||
+ }
|
||||
+
|
||||
+ err = grub_netbuff_push (nb, sizeof (*opt) + sizeof (grub_uint16_t));
|
||||
+ if (err)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ grub_netbuff_free (nb);
|
||||
+ return err;
|
||||
+ }
|
||||
+ err = grub_netbuff_push (nb, sizeof (*opt) + sizeof (grub_uint16_t));
|
||||
+ if (err)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ grub_netbuff_free (nb);
|
||||
+ return err;
|
||||
+ }
|
||||
+
|
||||
+ opt = (struct grub_net_dhcp6_option *)nb->data;
|
||||
+ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_ELAPSED_TIME);
|
||||
+ opt->len = grub_cpu_to_be16_compile_time (sizeof (grub_uint16_t));
|
||||
+ grub_set_unaligned16 (opt->data, 0);
|
||||
+ opt = (struct grub_net_dhcp6_option *)nb->data;
|
||||
+ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_ELAPSED_TIME);
|
||||
+ opt->len = grub_cpu_to_be16_compile_time (sizeof (grub_uint16_t));
|
||||
+ grub_set_unaligned16 (opt->data, 0);
|
||||
+
|
||||
+ err = grub_netbuff_push (nb, sizeof (*opt) + sizeof (*duid));
|
||||
+ if (err)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ grub_netbuff_free (nb);
|
||||
+ return err;
|
||||
+ }
|
||||
+ err = grub_netbuff_push (nb, sizeof (*opt) + sizeof (*duid));
|
||||
+ if (err)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ grub_netbuff_free (nb);
|
||||
+ return err;
|
||||
+ }
|
||||
+
|
||||
+ opt = (struct grub_net_dhcp6_option *)nb->data;
|
||||
+ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_CLIENTID);
|
||||
+ opt->len = grub_cpu_to_be16 (sizeof (*duid));
|
||||
+ opt = (struct grub_net_dhcp6_option *)nb->data;
|
||||
+ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_CLIENTID);
|
||||
+ opt->len = grub_cpu_to_be16 (sizeof (*duid));
|
||||
+
|
||||
+ duid = (struct grub_net_dhcp6_option_duid_ll *) opt->data;
|
||||
+ grub_memcpy (duid, &se->duid, sizeof (*duid));
|
||||
+ duid = (struct grub_net_dhcp6_option_duid_ll *) opt->data;
|
||||
+ grub_memcpy (duid, &se->duid, sizeof (*duid));
|
||||
+
|
||||
+ err = grub_netbuff_push (nb, sizeof (*opt) + sizeof (*ia_na));
|
||||
+ if (err)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ grub_netbuff_free (nb);
|
||||
+ return err;
|
||||
+ }
|
||||
+ err = grub_netbuff_push (nb, sizeof (*opt) + sizeof (*ia_na));
|
||||
+ if (err)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ grub_netbuff_free (nb);
|
||||
+ return err;
|
||||
+ }
|
||||
+
|
||||
+ opt = (struct grub_net_dhcp6_option *)nb->data;
|
||||
+ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_IA_NA);
|
||||
+ opt->len = grub_cpu_to_be16 (sizeof (*ia_na));
|
||||
+ ia_na = (struct grub_net_dhcp6_option_iana *)opt->data;
|
||||
+ ia_na->iaid = grub_cpu_to_be32 (se->iaid);
|
||||
+ ia_na->t1 = 0;
|
||||
+ ia_na->t2 = 0;
|
||||
+ opt = (struct grub_net_dhcp6_option *)nb->data;
|
||||
+ opt->code = grub_cpu_to_be16_compile_time (GRUB_NET_DHCP6_OPTION_IA_NA);
|
||||
+ opt->len = grub_cpu_to_be16 (sizeof (*ia_na));
|
||||
+ ia_na = (struct grub_net_dhcp6_option_iana *)opt->data;
|
||||
+ ia_na->iaid = grub_cpu_to_be32 (se->iaid);
|
||||
+ ia_na->t1 = 0;
|
||||
+ ia_na->t2 = 0;
|
||||
+
|
||||
+ err = grub_netbuff_push (nb, sizeof (*v6h));
|
||||
+ if (err)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ grub_netbuff_free (nb);
|
||||
+ return err;
|
||||
+ }
|
||||
+ err = grub_netbuff_push (nb, sizeof (*v6h));
|
||||
+ if (err)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ grub_netbuff_free (nb);
|
||||
+ return err;
|
||||
+ }
|
||||
+
|
||||
+ v6h = (struct grub_net_dhcp6_packet *)nb->data;
|
||||
+ v6h->message_type = GRUB_NET_DHCP6_SOLICIT;
|
||||
+ v6h->transaction_id = se->transaction_id;
|
||||
+ v6h = (struct grub_net_dhcp6_packet *)nb->data;
|
||||
+ v6h->message_type = GRUB_NET_DHCP6_SOLICIT;
|
||||
+ v6h->transaction_id = se->transaction_id;
|
||||
+
|
||||
+ grub_netbuff_push (nb, sizeof (*udph));
|
||||
+ grub_netbuff_push (nb, sizeof (*udph));
|
||||
+
|
||||
+ udph = (struct udphdr *) nb->data;
|
||||
+ udph->src = grub_cpu_to_be16_compile_time (DHCP6_CLIENT_PORT);
|
||||
+ udph->dst = grub_cpu_to_be16_compile_time (DHCP6_SERVER_PORT);
|
||||
+ udph->chksum = 0;
|
||||
+ udph->len = grub_cpu_to_be16 (nb->tail - nb->data);
|
||||
+ udph = (struct udphdr *) nb->data;
|
||||
+ udph->src = grub_cpu_to_be16_compile_time (DHCP6_CLIENT_PORT);
|
||||
+ udph->dst = grub_cpu_to_be16_compile_time (DHCP6_SERVER_PORT);
|
||||
+ udph->chksum = 0;
|
||||
+ udph->len = grub_cpu_to_be16 (nb->tail - nb->data);
|
||||
+
|
||||
+ udph->chksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_UDP,
|
||||
+ &se->iface->address, &multicast);
|
||||
+ udph->chksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_UDP,
|
||||
+ &se->iface->address, &multicast);
|
||||
+
|
||||
+ err = grub_net_send_ip_packet (se->iface, &multicast,
|
||||
+ &ll_multicast, nb, GRUB_NET_IP_UDP);
|
||||
+ done = 0;
|
||||
+ grub_netbuff_free (nb);
|
||||
+ err = grub_net_send_ip_packet (se->iface, &multicast,
|
||||
+ &ll_multicast, nb, GRUB_NET_IP_UDP);
|
||||
+ done = 0;
|
||||
+ grub_netbuff_free (nb);
|
||||
+
|
||||
+ if (err)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ return err;
|
||||
+ }
|
||||
+ }
|
||||
+ if (err)
|
||||
+ {
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+ return err;
|
||||
+ }
|
||||
+ }
|
||||
+ if (!done)
|
||||
+ grub_net_poll_cards (interval, 0);
|
||||
}
|
||||
|
||||
- if (is_def)
|
||||
+ grub_net_poll_cards (interval, 0);
|
||||
+ }
|
||||
+
|
||||
+ FOR_DHCP6_SESSIONS (se)
|
||||
{
|
||||
- grub_env_set ("net_default_interface", name);
|
||||
- grub_env_export ("net_default_interface");
|
||||
+ {
|
||||
+ grub_error_push ();
|
||||
+ err = grub_error (GRUB_ERR_FILE_NOT_FOUND,
|
||||
+ N_("couldn't autoconfigure %s"),
|
||||
+ se->iface->card->name);
|
||||
}
|
||||
|
||||
- if (inter)
|
||||
- grub_net_add_ipv6_local (inter, mask);
|
||||
- return inter;
|
||||
+ N_("couldn't autoconfigure %s"),
|
||||
+ se->iface->card->name);
|
||||
+ }
|
||||
+
|
||||
+ grub_dhcp6_session_remove_all ();
|
||||
+
|
||||
+ return err;
|
||||
}
|
||||
|
||||
+}
|
||||
+
|
||||
+static grub_command_t cmd_getdhcp, cmd_bootp, cmd_dhcp, cmd_bootp6;
|
||||
|
||||
void
|
||||
grub_bootp_init (void)
|
||||
@@ -1084,11 +1819,15 @@ grub_bootp_init (void)
|
||||
@@ -917,6 +1819,9 @@
|
||||
cmd_getdhcp = grub_register_command ("net_get_dhcp_option", grub_cmd_dhcpopt,
|
||||
N_("VAR INTERFACE NUMBER DESCRIPTION"),
|
||||
N_("retrieve DHCP option and save it into VAR. If VAR is - then print the value."));
|
||||
@ -1129,55 +963,15 @@ index 08b6b2b5d6c..fe93b80f1cf 100644
|
||||
}
|
||||
|
||||
void
|
||||
grub_bootp_fini (void)
|
||||
{
|
||||
+ grub_unregister_command (cmd_bootp6);
|
||||
@@ -925,4 +1830,5 @@
|
||||
grub_unregister_command (cmd_getdhcp);
|
||||
grub_unregister_command (cmd_bootp);
|
||||
grub_unregister_command (cmd_dhcp);
|
||||
diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c
|
||||
index a673bea807a..8e25680db0c 100644
|
||||
--- a/grub-core/net/drivers/efi/efinet.c
|
||||
+++ b/grub-core/net/drivers/efi/efinet.c
|
||||
@@ -393,9 +393,6 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
|
||||
pxe_mode = pxe->mode;
|
||||
if (pxe_mode->using_ipv6)
|
||||
{
|
||||
- grub_net_link_level_address_t hwaddr;
|
||||
- struct grub_net_network_level_interface *intf;
|
||||
-
|
||||
grub_dprintf ("efinet", "using ipv6 and dhcpv6\n");
|
||||
grub_dprintf ("efinet", "dhcp_ack_received: %s%s\n",
|
||||
pxe_mode->dhcp_ack_received ? "yes" : "no",
|
||||
@@ -403,15 +400,14 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
|
||||
if (!pxe_mode->dhcp_ack_received)
|
||||
continue;
|
||||
|
||||
- hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
|
||||
- grub_memcpy (hwaddr.mac,
|
||||
- card->efi_net->mode->current_address,
|
||||
- sizeof (hwaddr.mac));
|
||||
-
|
||||
- intf = grub_net_configure_by_dhcpv6_ack (card->name, card, 0, &hwaddr,
|
||||
- (const struct grub_net_dhcpv6_packet *)&pxe_mode->dhcp_ack.dhcpv6,
|
||||
- 1, device, path);
|
||||
- if (intf && device && path)
|
||||
+ grub_net_configure_by_dhcpv6_reply (card->name, card, 0,
|
||||
+ (struct grub_net_dhcp6_packet *)
|
||||
+ &pxe_mode->dhcp_ack,
|
||||
+ sizeof (pxe_mode->dhcp_ack),
|
||||
+ 1, device, path);
|
||||
+ if (grub_errno)
|
||||
+ grub_print_error ();
|
||||
+ if (device && path)
|
||||
grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path);
|
||||
}
|
||||
else
|
||||
diff --git a/grub-core/net/ip.c b/grub-core/net/ip.c
|
||||
index a5896f6dc26..ce6bdc75c6d 100644
|
||||
+ grub_unregister_command (cmd_bootp6);
|
||||
}
|
||||
--- a/grub-core/net/ip.c
|
||||
+++ b/grub-core/net/ip.c
|
||||
@@ -239,6 +239,45 @@ handle_dgram (struct grub_net_buff *nb,
|
||||
@@ -240,6 +240,45 @@
|
||||
{
|
||||
struct udphdr *udph;
|
||||
udph = (struct udphdr *) nb->data;
|
||||
@ -1223,50 +1017,19 @@ index a5896f6dc26..ce6bdc75c6d 100644
|
||||
if (proto == GRUB_NET_IP_UDP && grub_be_to_cpu16 (udph->dst) == 68)
|
||||
{
|
||||
const struct grub_net_bootp_packet *bootp;
|
||||
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
|
||||
index 99628801478..7614b58dca8 100644
|
||||
--- a/include/grub/efi/api.h
|
||||
+++ b/include/grub/efi/api.h
|
||||
@@ -1532,7 +1532,7 @@ typedef struct grub_efi_pxe_ip_filter
|
||||
{
|
||||
grub_efi_uint8_t filters;
|
||||
grub_efi_uint8_t ip_count;
|
||||
- grub_efi_uint8_t reserved;
|
||||
+ grub_efi_uint16_t reserved;
|
||||
grub_efi_ip_address_t ip_list[GRUB_EFI_PXE_MAX_IPCNT];
|
||||
} grub_efi_pxe_ip_filter_t;
|
||||
|
||||
diff --git a/include/grub/net.h b/include/grub/net.h
|
||||
index d55d505a03a..543251f7273 100644
|
||||
--- a/include/grub/net.h
|
||||
+++ b/include/grub/net.h
|
||||
@@ -451,50 +451,65 @@ struct grub_net_bootp_packet
|
||||
@@ -450,6 +450,66 @@
|
||||
grub_uint8_t vendor[0];
|
||||
} GRUB_PACKED;
|
||||
|
||||
-enum
|
||||
- {
|
||||
- GRUB_NET_DHCP6_IA_NA = 3,
|
||||
- GRUB_NET_DHCP6_IA_ADDRESS = 5,
|
||||
- GRUB_NET_DHCP6_BOOTFILE_URL = 59,
|
||||
- };
|
||||
-
|
||||
-struct grub_net_dhcpv6_option
|
||||
+struct grub_net_dhcp6_packet
|
||||
{
|
||||
- grub_uint16_t option_num;
|
||||
- grub_uint16_t option_len;
|
||||
- grub_uint8_t option_data[];
|
||||
+{
|
||||
+ grub_uint32_t message_type:8;
|
||||
+ grub_uint32_t transaction_id:24;
|
||||
+ grub_uint8_t dhcp_options[0];
|
||||
} GRUB_PACKED;
|
||||
-typedef struct grub_net_dhcpv6_option grub_net_dhcpv6_option_t;
|
||||
|
||||
-struct grub_net_dhcpv6_opt_ia_na
|
||||
-{
|
||||
- grub_uint16_t option_num;
|
||||
- grub_uint16_t option_len;
|
||||
+} GRUB_PACKED;
|
||||
+
|
||||
+struct grub_net_dhcp6_option {
|
||||
+ grub_uint16_t code;
|
||||
+ grub_uint16_t len;
|
||||
@ -1274,39 +1037,25 @@ index d55d505a03a..543251f7273 100644
|
||||
+} GRUB_PACKED;
|
||||
+
|
||||
+struct grub_net_dhcp6_option_iana {
|
||||
grub_uint32_t iaid;
|
||||
grub_uint32_t t1;
|
||||
grub_uint32_t t2;
|
||||
- grub_uint8_t options[];
|
||||
+ grub_uint32_t iaid;
|
||||
+ grub_uint32_t t1;
|
||||
+ grub_uint32_t t2;
|
||||
+ grub_uint8_t data[0];
|
||||
} GRUB_PACKED;
|
||||
-typedef struct grub_net_dhcpv6_opt_ia_na grub_net_dhcpv6_opt_ia_na_t;
|
||||
|
||||
-struct grub_net_dhcpv6_opt_ia_address
|
||||
-{
|
||||
- grub_uint16_t option_num;
|
||||
- grub_uint16_t option_len;
|
||||
- grub_uint64_t ipv6_address[2];
|
||||
+} GRUB_PACKED;
|
||||
+
|
||||
+struct grub_net_dhcp6_option_iaaddr {
|
||||
+ grub_uint8_t addr[16];
|
||||
grub_uint32_t preferred_lifetime;
|
||||
grub_uint32_t valid_lifetime;
|
||||
- grub_uint8_t options[];
|
||||
+ grub_uint32_t preferred_lifetime;
|
||||
+ grub_uint32_t valid_lifetime;
|
||||
+ grub_uint8_t data[0];
|
||||
} GRUB_PACKED;
|
||||
-typedef struct grub_net_dhcpv6_opt_ia_address grub_net_dhcpv6_opt_ia_address_t;
|
||||
|
||||
-struct grub_net_dhcpv6_packet
|
||||
+} GRUB_PACKED;
|
||||
+
|
||||
+struct grub_net_dhcp6_option_duid_ll
|
||||
{
|
||||
- grub_uint32_t message_type:8;
|
||||
- grub_uint32_t transaction_id:24;
|
||||
- grub_uint8_t dhcp_options[1024];
|
||||
+{
|
||||
+ grub_uint16_t type;
|
||||
+ grub_uint16_t hw_type;
|
||||
+ grub_uint8_t hwaddr[6];
|
||||
} GRUB_PACKED;
|
||||
-typedef struct grub_net_dhcpv6_packet grub_net_dhcpv6_packet_t;
|
||||
+} GRUB_PACKED;
|
||||
+
|
||||
+enum
|
||||
+ {
|
||||
@ -1333,29 +1082,26 @@ index d55d505a03a..543251f7273 100644
|
||||
+ GRUB_NET_DHCP6_OPTION_DNS_SERVERS = 23,
|
||||
+ GRUB_NET_DHCP6_OPTION_BOOTFILE_URL = 59
|
||||
+ };
|
||||
|
||||
+
|
||||
#define GRUB_NET_BOOTP_RFC1048_MAGIC_0 0x63
|
||||
#define GRUB_NET_BOOTP_RFC1048_MAGIC_1 0x82
|
||||
@@ -532,12 +547,12 @@ grub_net_configure_by_dhcp_ack (const char *name,
|
||||
#define GRUB_NET_BOOTP_RFC1048_MAGIC_2 0x53
|
||||
@@ -485,6 +545,14 @@
|
||||
grub_size_t size,
|
||||
int is_def, char **device, char **path);
|
||||
|
||||
struct grub_net_network_level_interface *
|
||||
-grub_net_configure_by_dhcpv6_ack (const char *name,
|
||||
- struct grub_net_card *card,
|
||||
- grub_net_interface_flags_t flags,
|
||||
- const grub_net_link_level_address_t *hwaddr,
|
||||
- const struct grub_net_dhcpv6_packet *packet,
|
||||
- int is_def, char **device, char **path);
|
||||
+struct grub_net_network_level_interface *
|
||||
+grub_net_configure_by_dhcpv6_reply (const char *name,
|
||||
+ struct grub_net_card *card,
|
||||
+ grub_net_interface_flags_t flags,
|
||||
+ const struct grub_net_dhcp6_packet *v6,
|
||||
+ grub_size_t size,
|
||||
+ int is_def, char **device, char **path);
|
||||
|
||||
int
|
||||
grub_ipv6_get_masksize(grub_uint16_t *mask);
|
||||
@@ -554,6 +569,10 @@ void
|
||||
+
|
||||
grub_err_t
|
||||
grub_net_add_ipv4_local (struct grub_net_network_level_interface *inf,
|
||||
int mask);
|
||||
@@ -493,6 +561,10 @@
|
||||
grub_net_process_dhcp (struct grub_net_buff *nb,
|
||||
struct grub_net_network_level_interface *iface);
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
From 64494ffc442a5de05b237ad48d27c70d22849a44 Mon Sep 17 00:00:00 2001
|
||||
From: Gary Lin <glin@suse.com>
|
||||
Date: Thu, 3 Aug 2023 15:52:52 +0800
|
||||
Subject: [PATCH 3/4] cryptodisk: wipe out the cached keys from protectors
|
||||
|
||||
An attacker may insert a malicious disk with the same crypto UUID and
|
||||
trick grub2 to mount the fake root. Even though the key from the key
|
||||
protector fails to unlock the fake root, it's not wiped out cleanly so
|
||||
the attacker could dump the memory to retrieve the secret key. To defend
|
||||
such attack, wipe out the cached key when we don't need it.
|
||||
|
||||
Signed-off-by: Gary Lin <glin@suse.com>
|
||||
---
|
||||
grub-core/disk/cryptodisk.c | 6 +++++-
|
||||
1 file changed, 5 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c
|
||||
index cf37a0934..f42437f4e 100644
|
||||
--- a/grub-core/disk/cryptodisk.c
|
||||
+++ b/grub-core/disk/cryptodisk.c
|
||||
@@ -1348,7 +1348,11 @@ grub_cryptodisk_clear_key_cache (struct grub_cryptomount_args *cargs)
|
||||
return;
|
||||
|
||||
for (i = 0; cargs->protectors[i]; i++)
|
||||
- grub_free (cargs->key_cache[i].key);
|
||||
+ {
|
||||
+ if (cargs->key_cache[i].key)
|
||||
+ grub_memset (cargs->key_cache[i].key, 0, cargs->key_cache[i].key_len);
|
||||
+ grub_free (cargs->key_cache[i].key);
|
||||
+ }
|
||||
|
||||
grub_free (cargs->key_cache);
|
||||
}
|
||||
--
|
||||
2.35.3
|
||||
|
||||
137
0003-grub-install-support-prep-environment-block.patch
Normal file
137
0003-grub-install-support-prep-environment-block.patch
Normal file
@ -0,0 +1,137 @@
|
||||
From c31fc5aa0ded9ce1e774d0a3526cfee19be1b77f Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Mon, 7 Feb 2022 20:49:01 +0800
|
||||
Subject: [PATCH 3/5] grub-install: support prep environment block
|
||||
|
||||
The grub-install can be instructed to create environment block at end of
|
||||
PReP paritition with probed device identities and properties in
|
||||
variables to facilitate root device discovery. So far these variables
|
||||
are defined for this purpose:
|
||||
|
||||
ENV_FS_UUID - The filesystem uuid for the grub root device
|
||||
ENV_CRYPTO_UUID - The crytodisk uuid for the grub root device separated
|
||||
by space
|
||||
ENV_GRUB_DIR - The path to grub prefix directory
|
||||
ENV_HINT - The recommended hint string for searching root device
|
||||
|
||||
The size of environment block is defined in GRUB_ENVBLK_PREP_SIZE which
|
||||
is 4096 bytes and can be extended in the future.
|
||||
|
||||
v2: Improve detection of ENV_CRYPTO_UUID by traversing all members of
|
||||
the logical disk and utilize a space as a separator when multiple UUIDs
|
||||
are found (bsc#1216075).
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
include/grub/lib/envblk.h | 3 +++
|
||||
util/grub-install.c | 38 ++++++++++++++++++++++++++++++++++++++
|
||||
2 files changed, 41 insertions(+)
|
||||
|
||||
--- a/include/grub/lib/envblk.h
|
||||
+++ b/include/grub/lib/envblk.h
|
||||
@@ -24,6 +24,9 @@
|
||||
|
||||
#ifndef ASM_FILE
|
||||
|
||||
+#include <grub/disk.h>
|
||||
+#define GRUB_ENVBLK_PREP_SIZE (GRUB_DISK_SECTOR_SIZE << 3)
|
||||
+
|
||||
struct grub_envblk
|
||||
{
|
||||
char *buf;
|
||||
--- a/util/grub-install.c
|
||||
+++ b/util/grub-install.c
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <grub/util/ofpath.h>
|
||||
#include <grub/hfsplus.h>
|
||||
#include <grub/time.h>
|
||||
+#include <grub/lib/envblk.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -609,6 +610,41 @@
|
||||
}
|
||||
}
|
||||
|
||||
+static char *
|
||||
+cryptodisk_uuids (grub_disk_t disk, int in_recurse)
|
||||
+{
|
||||
+ grub_disk_memberlist_t list = NULL, tmp;
|
||||
+ static char *ret;
|
||||
+
|
||||
+ if (!in_recurse)
|
||||
+ ret = NULL;
|
||||
+
|
||||
+ if (disk->dev->disk_memberlist)
|
||||
+ list = disk->dev->disk_memberlist (disk);
|
||||
+
|
||||
+ while (list)
|
||||
+ {
|
||||
+ ret = cryptodisk_uuids (list->disk, 1);
|
||||
+ tmp = list->next;
|
||||
+ free (list);
|
||||
+ list = tmp;
|
||||
+ }
|
||||
+
|
||||
+ if (disk->dev->id == GRUB_DISK_DEVICE_CRYPTODISK_ID)
|
||||
+ {
|
||||
+ if (!ret)
|
||||
+ ret = grub_strdup (grub_util_cryptodisk_get_uuid (disk));
|
||||
+ else
|
||||
+ {
|
||||
+ char *s = grub_xasprintf ("%s %s", grub_util_cryptodisk_get_uuid (disk), ret);
|
||||
+ grub_free (ret);
|
||||
+ ret = s;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
static int
|
||||
is_same_disk (const char *a, const char *b)
|
||||
{
|
||||
@@ -2138,6 +2174,43 @@
|
||||
if (write_to_disk (ins_dev, imgfile))
|
||||
grub_util_error ("%s", _("failed to copy Grub to the PReP partition"));
|
||||
grub_set_install_backup_ponr ();
|
||||
+
|
||||
+ if ((signed_grub_mode >= SIGNED_GRUB_FORCE) || ((signed_grub_mode == SIGNED_GRUB_AUTO) && (ppc_sb_state > 0)))
|
||||
+ {
|
||||
+ char *uuid = NULL;
|
||||
+ grub_envblk_t envblk = NULL;
|
||||
+ char *buf;
|
||||
+ char *cryptouuid = NULL;
|
||||
+
|
||||
+ if (grub_dev->disk)
|
||||
+ cryptouuid = cryptodisk_uuids (grub_dev->disk, 0);
|
||||
+
|
||||
+ if (grub_fs->fs_uuid && grub_fs->fs_uuid (grub_dev, &uuid))
|
||||
+ {
|
||||
+ grub_print_error ();
|
||||
+ grub_errno = 0;
|
||||
+ uuid = NULL;
|
||||
+ }
|
||||
+ buf = grub_envblk_buf (GRUB_ENVBLK_PREP_SIZE);
|
||||
+ envblk = grub_envblk_open (buf, GRUB_ENVBLK_PREP_SIZE);
|
||||
+ if (uuid)
|
||||
+ grub_envblk_set (envblk, "ENV_FS_UUID", uuid);
|
||||
+ if (cryptouuid)
|
||||
+ grub_envblk_set (envblk, "ENV_CRYPTO_UUID", cryptouuid);
|
||||
+ if (relative_grubdir)
|
||||
+ grub_envblk_set (envblk, "ENV_GRUB_DIR", relative_grubdir);
|
||||
+ if (have_abstractions)
|
||||
+ grub_envblk_set (envblk, "ENV_HINT", grub_dev->disk->name);
|
||||
+ if (use_relative_path_on_btrfs)
|
||||
+ grub_envblk_set (envblk, "btrfs_relative_path", "1");
|
||||
+ if (envblk)
|
||||
+ {
|
||||
+ fprintf (stderr, _("Write environment block to PReP.\n"));
|
||||
+ if (grub_disk_write_tail (ins_dev->disk, envblk->size, envblk->buf))
|
||||
+ grub_util_error ("%s", _("failed to write environment block to the PReP partition"));
|
||||
+ }
|
||||
+ grub_envblk_close (envblk);
|
||||
+ }
|
||||
grub_device_close (ins_dev);
|
||||
if (update_nvram)
|
||||
grub_install_register_ieee1275 (1, grub_util_get_os_disk (install_device),
|
||||
62
0003-ieee1275-change-the-logic-of-ieee1275_get_devargs.patch
Normal file
62
0003-ieee1275-change-the-logic-of-ieee1275_get_devargs.patch
Normal file
@ -0,0 +1,62 @@
|
||||
From 1729400ab816804a28ebf50cb1310607b2c4b75e Mon Sep 17 00:00:00 2001
|
||||
From: Diego Domingos <diegodo@br.ibm.com>
|
||||
Date: Fri, 25 Feb 2022 12:49:51 -0500
|
||||
Subject: [PATCH 3/4] ieee1275: change the logic of ieee1275_get_devargs()
|
||||
|
||||
Usually grub will parse the PFW arguments by searching for the first occurence of the character ':'.
|
||||
However, we can have this char more than once on NQN.
|
||||
This patch changes the logic to find the last occurence of this char so we can get the proper values
|
||||
for NVMeoFC
|
||||
---
|
||||
grub-core/kern/ieee1275/openfw.c | 21 ++++++++++++++++++++-
|
||||
1 file changed, 20 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c
|
||||
index f819bd106..655a71310 100644
|
||||
--- a/grub-core/kern/ieee1275/openfw.c
|
||||
+++ b/grub-core/kern/ieee1275/openfw.c
|
||||
@@ -354,6 +354,13 @@ static char *
|
||||
grub_ieee1275_get_devargs (const char *path)
|
||||
{
|
||||
char *colon = grub_strchr (path, ':');
|
||||
+ char *colon_check = colon;
|
||||
+
|
||||
+ /* Find the last occurence of colon */
|
||||
+ while(colon_check){
|
||||
+ colon = colon_check;
|
||||
+ colon_check = grub_strchr (colon+1, ':');
|
||||
+ }
|
||||
|
||||
if (! colon)
|
||||
return 0;
|
||||
@@ -368,6 +375,18 @@ grub_ieee1275_get_devname (const char *path)
|
||||
char *colon = grub_strchr (path, ':');
|
||||
int pathlen = grub_strlen (path);
|
||||
struct grub_ieee1275_devalias curalias;
|
||||
+
|
||||
+ /* Check some special cases */
|
||||
+ if(grub_strstr(path, "nvme-of")){
|
||||
+ char *namespace_split = grub_strstr(path,"/namespace@");
|
||||
+ if(namespace_split){
|
||||
+ colon = grub_strchr (namespace_split, ':');
|
||||
+ } else {
|
||||
+ colon = NULL;
|
||||
+ }
|
||||
+
|
||||
+ }
|
||||
+
|
||||
if (colon)
|
||||
pathlen = (int)(colon - path);
|
||||
|
||||
@@ -693,7 +712,7 @@ grub_ieee1275_get_boot_dev (void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
- bootpath = (char *) grub_malloc ((grub_size_t) bootpath_size + 64);
|
||||
+ bootpath = (char *) grub_malloc ((grub_size_t) bootpath_size + 64 + 256);
|
||||
if (! bootpath)
|
||||
{
|
||||
grub_print_error ();
|
||||
--
|
||||
2.35.3
|
||||
|
||||
2052
0003-protectors-Add-TPM2-Key-Protector.patch
Normal file
2052
0003-protectors-Add-TPM2-Key-Protector.patch
Normal file
File diff suppressed because it is too large
Load Diff
543
0003-tpm2-Implement-more-TPM2-commands.patch
Normal file
543
0003-tpm2-Implement-more-TPM2-commands.patch
Normal file
@ -0,0 +1,543 @@
|
||||
From a49c4dcbcb04078434f461ed3356c04042be461a Mon Sep 17 00:00:00 2001
|
||||
From: Gary Lin <glin@suse.com>
|
||||
Date: Wed, 8 Feb 2023 10:30:55 +0800
|
||||
Subject: [PATCH 3/4] tpm2: Implement more TPM2 commands
|
||||
|
||||
This commit implements a few more TPM2 commands as the preparation for
|
||||
the authorized policy support.
|
||||
|
||||
* TPM2_LoadExternal
|
||||
This command is added to load the external public key to verify the
|
||||
signed policy digest
|
||||
* TPM2_HashSequenceStart, TPM2_SequenceUpdate, TPM2_SequenceComplete,
|
||||
and TPM2_Hash
|
||||
With those commands, we can use the TPM as a coprocessor to calculate
|
||||
the hash of a given binary blob.
|
||||
* TPM2_VerifySignature
|
||||
This command verifies the given signature with the given public key
|
||||
and returns the validation ticket to authorize the policy.
|
||||
* TPM2_PolicyAuthorize
|
||||
This command approves the given policy digest so that we can unseal
|
||||
the key with the newly authorized policy.
|
||||
|
||||
Signed-off-by: Gary Lin <glin@suse.com>
|
||||
---
|
||||
grub-core/tpm2/tpm2.c | 424 +++++++++++++++++++++++++
|
||||
include/grub/tpm2/internal/functions.h | 57 ++++
|
||||
2 files changed, 481 insertions(+)
|
||||
|
||||
diff --git a/grub-core/tpm2/tpm2.c b/grub-core/tpm2/tpm2.c
|
||||
index d67699a24..159353b08 100644
|
||||
--- a/grub-core/tpm2/tpm2.c
|
||||
+++ b/grub-core/tpm2/tpm2.c
|
||||
@@ -427,6 +427,73 @@ TPM2_Load (const TPMI_DH_OBJECT parent_handle,
|
||||
return TPM_RC_SUCCESS;
|
||||
}
|
||||
|
||||
+TPM_RC
|
||||
+TPM2_LoadExternal (const TPMS_AUTH_COMMAND *authCommand,
|
||||
+ const TPM2B_SENSITIVE *inPrivate,
|
||||
+ const TPM2B_PUBLIC *inPublic,
|
||||
+ const TPMI_RH_HIERARCHY hierarchy,
|
||||
+ TPM_HANDLE *objectHandle,
|
||||
+ TPM2B_NAME *name,
|
||||
+ TPMS_AUTH_RESPONSE *authResponse)
|
||||
+{
|
||||
+ TPM_RC rc;
|
||||
+ struct grub_tpm2_buffer in;
|
||||
+ struct grub_tpm2_buffer out;
|
||||
+ TPM_HANDLE objectHandleTmp;
|
||||
+ TPM2B_NAME nameTmp;
|
||||
+ TPMS_AUTH_RESPONSE authResponseTmp;
|
||||
+ TPMI_ST_COMMAND_TAG tag = authCommand ? TPM_ST_SESSIONS : TPM_ST_NO_SESSIONS;
|
||||
+ TPM_RC responseCode;
|
||||
+ grub_uint32_t param_size;
|
||||
+
|
||||
+ if (!inPublic)
|
||||
+ return TPM_RC_VALUE;
|
||||
+
|
||||
+ if (!objectHandle)
|
||||
+ objectHandle = &objectHandleTmp;
|
||||
+ if (!name)
|
||||
+ name = &nameTmp;
|
||||
+ if (!authResponse)
|
||||
+ authResponse = &authResponseTmp;
|
||||
+
|
||||
+ grub_memset (objectHandle, 0, sizeof (*objectHandle));
|
||||
+ grub_memset (name, 0, sizeof (*name));
|
||||
+ grub_memset (authResponse, 0, sizeof (*authResponse));
|
||||
+
|
||||
+ /* Marshal */
|
||||
+ grub_tpm2_buffer_init (&in);
|
||||
+ if (authCommand)
|
||||
+ grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
|
||||
+ if (inPrivate)
|
||||
+ grub_tpm2_mu_TPM2B_SENSITIVE_Marshal (&in, inPrivate);
|
||||
+ else
|
||||
+ grub_tpm2_buffer_pack_u16 (&in, 0);
|
||||
+ grub_tpm2_mu_TPM2B_PUBLIC_Marshal (&in, inPublic);
|
||||
+ grub_tpm2_buffer_pack_u32 (&in, hierarchy);
|
||||
+ if (in.error)
|
||||
+ return TPM_RC_FAILURE;
|
||||
+
|
||||
+ /* Submit */
|
||||
+ grub_tpm2_buffer_init (&out);
|
||||
+ rc = grub_tpm2_submit_command (tag, TPM_CC_LoadExternal, &responseCode, &in, &out);
|
||||
+ if (rc != TPM_RC_SUCCESS)
|
||||
+ return rc;
|
||||
+ if (responseCode != TPM_RC_SUCCESS)
|
||||
+ return responseCode;
|
||||
+
|
||||
+ /* Unmarshal*/
|
||||
+ grub_tpm2_buffer_unpack_u32 (&out, objectHandle);
|
||||
+ if (tag == TPM_ST_SESSIONS)
|
||||
+ grub_tpm2_buffer_unpack_u32 (&out, ¶m_size);
|
||||
+ grub_tpm2_mu_TPM2B_Unmarshal (&out, (TPM2B*)name);
|
||||
+ if (tag == TPM_ST_SESSIONS)
|
||||
+ grub_tpm2_mu_TPMS_AUTH_RESPONSE_Unmarshal (&out, authResponse);
|
||||
+ if (out.error)
|
||||
+ return TPM_RC_FAILURE;
|
||||
+
|
||||
+ return TPM_RC_SUCCESS;
|
||||
+}
|
||||
+
|
||||
TPM_RC
|
||||
TPM2_Unseal (const TPMI_DH_OBJECT itemHandle,
|
||||
const TPMS_AUTH_COMMAND *authCommand,
|
||||
@@ -759,3 +826,360 @@ TPM2_EvictControl (const TPMI_RH_PROVISION auth,
|
||||
|
||||
return TPM_RC_SUCCESS;
|
||||
}
|
||||
+
|
||||
+TPM_RC
|
||||
+TPM2_HashSequenceStart (const TPMS_AUTH_COMMAND *authCommand,
|
||||
+ const TPM2B_AUTH *auth,
|
||||
+ const TPMI_ALG_HASH hashAlg,
|
||||
+ TPMI_DH_OBJECT *sequenceHandle,
|
||||
+ TPMS_AUTH_RESPONSE *authResponse)
|
||||
+{
|
||||
+ struct grub_tpm2_buffer in;
|
||||
+ struct grub_tpm2_buffer out;
|
||||
+ TPMI_DH_OBJECT sequenceHandleTmp;
|
||||
+ TPMS_AUTH_RESPONSE authResponseTmp;
|
||||
+ TPMI_ST_COMMAND_TAG tag = authCommand ? TPM_ST_SESSIONS : TPM_ST_NO_SESSIONS;
|
||||
+ TPM_RC responseCode;
|
||||
+ TPM_RC rc;
|
||||
+ grub_uint32_t parameterSize;
|
||||
+
|
||||
+ if (!auth)
|
||||
+ return TPM_RC_VALUE;
|
||||
+
|
||||
+ if (!sequenceHandle)
|
||||
+ sequenceHandle = &sequenceHandleTmp;
|
||||
+ if (!authResponse)
|
||||
+ authResponse = &authResponseTmp;
|
||||
+
|
||||
+ grub_memset (sequenceHandle, 0, sizeof (*sequenceHandle));
|
||||
+ grub_memset (authResponse, 0, sizeof (*authResponse));
|
||||
+
|
||||
+ /* Marshal */
|
||||
+ grub_tpm2_buffer_init (&in);
|
||||
+ if (authCommand)
|
||||
+ grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (&in, auth->size, auth->buffer);
|
||||
+ grub_tpm2_buffer_pack_u16 (&in, hashAlg);
|
||||
+ if (in.error)
|
||||
+ return TPM_RC_FAILURE;
|
||||
+
|
||||
+ /* Submit */
|
||||
+ grub_tpm2_buffer_init (&out);
|
||||
+ rc = grub_tpm2_submit_command (tag, TPM_CC_HashSequenceStart, &responseCode, &in,
|
||||
+ &out);
|
||||
+ if (rc != TPM_RC_SUCCESS)
|
||||
+ return rc;
|
||||
+ if (responseCode != TPM_RC_SUCCESS)
|
||||
+ return responseCode;
|
||||
+
|
||||
+ /* Unmarshal */
|
||||
+ grub_tpm2_buffer_unpack_u32 (&out, sequenceHandle);
|
||||
+ if (tag == TPM_ST_SESSIONS)
|
||||
+ {
|
||||
+ grub_tpm2_buffer_unpack_u32 (&out, ¶meterSize);
|
||||
+ grub_tpm2_mu_TPMS_AUTH_RESPONSE_Unmarshal(&out, authResponse);
|
||||
+ }
|
||||
+ if (out.error)
|
||||
+ return TPM_RC_FAILURE;
|
||||
+
|
||||
+ return TPM_RC_SUCCESS;
|
||||
+}
|
||||
+
|
||||
+TPM_RC
|
||||
+TPM2_SequenceUpdate (const TPMI_DH_OBJECT sequenceHandle,
|
||||
+ const TPMS_AUTH_COMMAND *authCommand,
|
||||
+ const TPM2B_MAX_BUFFER *buffer,
|
||||
+ TPMS_AUTH_RESPONSE *authResponse)
|
||||
+{
|
||||
+ struct grub_tpm2_buffer in;
|
||||
+ struct grub_tpm2_buffer out;
|
||||
+ TPMS_AUTH_RESPONSE authResponseTmp;
|
||||
+ TPM_RC responseCode;
|
||||
+ TPM_RC rc;
|
||||
+ grub_uint32_t parameterSize;
|
||||
+
|
||||
+ if (!authCommand)
|
||||
+ return TPM_RC_VALUE;
|
||||
+
|
||||
+ if (!authResponse)
|
||||
+ authResponse = &authResponseTmp;
|
||||
+
|
||||
+ grub_memset (authResponse, 0, sizeof (*authResponse));
|
||||
+
|
||||
+ /* Marshal */
|
||||
+ grub_tpm2_buffer_init (&in);
|
||||
+ grub_tpm2_buffer_pack_u32 (&in, sequenceHandle);
|
||||
+ grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
|
||||
+ if (buffer)
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (&in, buffer->size, buffer->buffer);
|
||||
+ else
|
||||
+ grub_tpm2_buffer_pack_u16 (&in, 0);
|
||||
+ if (in.error)
|
||||
+ return TPM_RC_FAILURE;
|
||||
+
|
||||
+ /* Submit */
|
||||
+ grub_tpm2_buffer_init (&out);
|
||||
+ rc = grub_tpm2_submit_command (TPM_ST_SESSIONS, TPM_CC_SequenceUpdate,
|
||||
+ &responseCode, &in, &out);
|
||||
+ if (rc != TPM_RC_SUCCESS)
|
||||
+ return rc;
|
||||
+ if (responseCode != TPM_RC_SUCCESS)
|
||||
+ return responseCode;
|
||||
+
|
||||
+ /* Unmarshal */
|
||||
+ grub_tpm2_buffer_unpack_u32 (&out, ¶meterSize);
|
||||
+ grub_tpm2_mu_TPMS_AUTH_RESPONSE_Unmarshal(&out, authResponse);
|
||||
+ if (out.error)
|
||||
+ return TPM_RC_FAILURE;
|
||||
+
|
||||
+ return TPM_RC_SUCCESS;
|
||||
+}
|
||||
+
|
||||
+TPM_RC
|
||||
+TPM2_SequenceComplete (const TPMI_DH_OBJECT sequenceHandle,
|
||||
+ const TPMS_AUTH_COMMAND *authCommand,
|
||||
+ const TPM2B_MAX_BUFFER *buffer,
|
||||
+ const TPMI_RH_HIERARCHY hierarchy,
|
||||
+ TPM2B_DIGEST *result,
|
||||
+ TPMT_TK_HASHCHECK *validation,
|
||||
+ TPMS_AUTH_RESPONSE *authResponse)
|
||||
+{
|
||||
+ struct grub_tpm2_buffer in;
|
||||
+ struct grub_tpm2_buffer out;
|
||||
+ TPM2B_DIGEST resultTmp;
|
||||
+ TPMT_TK_HASHCHECK validationTmp;
|
||||
+ TPMS_AUTH_RESPONSE authResponseTmp;
|
||||
+ TPM_RC responseCode;
|
||||
+ TPM_RC rc;
|
||||
+ grub_uint32_t parameterSize;
|
||||
+
|
||||
+ if (!authCommand)
|
||||
+ return TPM_RC_VALUE;
|
||||
+
|
||||
+ if (!result)
|
||||
+ result = &resultTmp;
|
||||
+ if (!validation)
|
||||
+ validation = &validationTmp;
|
||||
+ if (!authResponse)
|
||||
+ authResponse = &authResponseTmp;
|
||||
+
|
||||
+ grub_memset (result, 0, sizeof (*result));
|
||||
+ grub_memset (validation, 0, sizeof (*validation));
|
||||
+ grub_memset (authResponse, 0, sizeof (*authResponse));
|
||||
+
|
||||
+ /* Marshal */
|
||||
+ grub_tpm2_buffer_init (&in);
|
||||
+ grub_tpm2_buffer_pack_u32 (&in, sequenceHandle);
|
||||
+ grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
|
||||
+ if (buffer)
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (&in, buffer->size, buffer->buffer);
|
||||
+ else
|
||||
+ grub_tpm2_buffer_pack_u16 (&in, 0);
|
||||
+ grub_tpm2_buffer_pack_u32 (&in, hierarchy);
|
||||
+
|
||||
+ if (in.error)
|
||||
+ return TPM_RC_FAILURE;
|
||||
+
|
||||
+ /* Submit */
|
||||
+ grub_tpm2_buffer_init (&out);
|
||||
+ rc = grub_tpm2_submit_command (TPM_ST_SESSIONS, TPM_CC_SequenceComplete,
|
||||
+ &responseCode, &in, &out);
|
||||
+ if (rc != TPM_RC_SUCCESS)
|
||||
+ return rc;
|
||||
+ if (responseCode != TPM_RC_SUCCESS)
|
||||
+ return responseCode;
|
||||
+
|
||||
+ /* Unmarshal */
|
||||
+ grub_tpm2_buffer_unpack_u32 (&out, ¶meterSize);
|
||||
+ grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (&out, result);
|
||||
+ grub_tpm2_mu_TPMT_TK_HASHCHECK_Unmarshal (&out, validation);
|
||||
+ grub_tpm2_mu_TPMS_AUTH_RESPONSE_Unmarshal(&out, authResponse);
|
||||
+ if (out.error)
|
||||
+ return TPM_RC_FAILURE;
|
||||
+
|
||||
+ return TPM_RC_SUCCESS;
|
||||
+}
|
||||
+
|
||||
+TPM_RC
|
||||
+TPM2_Hash (const TPMS_AUTH_COMMAND *authCommand,
|
||||
+ const TPM2B_MAX_BUFFER *data,
|
||||
+ const TPMI_ALG_HASH hashAlg,
|
||||
+ const TPMI_RH_HIERARCHY hierarchy,
|
||||
+ TPM2B_DIGEST *outHash,
|
||||
+ TPMT_TK_HASHCHECK *validation,
|
||||
+ TPMS_AUTH_RESPONSE *authResponse)
|
||||
+{
|
||||
+ TPM_RC rc;
|
||||
+ struct grub_tpm2_buffer in;
|
||||
+ struct grub_tpm2_buffer out;
|
||||
+ TPMS_AUTH_RESPONSE authResponseTmp;
|
||||
+ TPM2B_DIGEST outHashTmp;
|
||||
+ TPMT_TK_HASHCHECK validationTmp;
|
||||
+ TPMI_ST_COMMAND_TAG tag = authCommand ? TPM_ST_SESSIONS : TPM_ST_NO_SESSIONS;
|
||||
+ TPM_RC responseCode;
|
||||
+ grub_uint32_t param_size;
|
||||
+
|
||||
+ if (hashAlg == TPM_ALG_NULL)
|
||||
+ return TPM_RC_VALUE;
|
||||
+
|
||||
+ if (!outHash)
|
||||
+ outHash = &outHashTmp;
|
||||
+ if (!validation)
|
||||
+ validation = &validationTmp;
|
||||
+ if (!authResponse)
|
||||
+ authResponse = &authResponseTmp;
|
||||
+
|
||||
+ grub_memset (outHash, 0, sizeof (*outHash));
|
||||
+ grub_memset (validation, 0, sizeof (*validation));
|
||||
+ grub_memset (authResponse, 0, sizeof (*authResponse));
|
||||
+
|
||||
+ /* Marshal */
|
||||
+ grub_tpm2_buffer_init (&in);
|
||||
+ if (authCommand)
|
||||
+ grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
|
||||
+ if (data)
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (&in, data->size, data->buffer);
|
||||
+ else
|
||||
+ grub_tpm2_buffer_pack_u16 (&in, 0);
|
||||
+ grub_tpm2_buffer_pack_u16 (&in, hashAlg);
|
||||
+ grub_tpm2_buffer_pack_u32 (&in, hierarchy);
|
||||
+ if (in.error)
|
||||
+ return TPM_RC_FAILURE;
|
||||
+
|
||||
+ /* Submit */
|
||||
+ grub_tpm2_buffer_init (&out);
|
||||
+ rc = grub_tpm2_submit_command (tag, TPM_CC_Hash, &responseCode, &in, &out);
|
||||
+ if (rc != TPM_RC_SUCCESS)
|
||||
+ return rc;
|
||||
+ if (responseCode != TPM_RC_SUCCESS)
|
||||
+ return responseCode;
|
||||
+
|
||||
+ /* Unmarshal*/
|
||||
+ if (tag == TPM_ST_SESSIONS)
|
||||
+ grub_tpm2_buffer_unpack_u32 (&out, ¶m_size);
|
||||
+ grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (&out, outHash);
|
||||
+ grub_tpm2_mu_TPMT_TK_HASHCHECK_Unmarshal (&out, validation);
|
||||
+ if (tag == TPM_ST_SESSIONS)
|
||||
+ grub_tpm2_mu_TPMS_AUTH_RESPONSE_Unmarshal (&out, authResponse);
|
||||
+ if (out.error)
|
||||
+ return TPM_RC_FAILURE;
|
||||
+
|
||||
+ return TPM_RC_SUCCESS;
|
||||
+}
|
||||
+
|
||||
+TPM_RC
|
||||
+TPM2_VerifySignature (const TPMI_DH_OBJECT keyHandle,
|
||||
+ const TPMS_AUTH_COMMAND *authCommand,
|
||||
+ const TPM2B_DIGEST *digest,
|
||||
+ const TPMT_SIGNATURE *signature,
|
||||
+ TPMT_TK_VERIFIED *validation,
|
||||
+ TPMS_AUTH_RESPONSE *authResponse)
|
||||
+{
|
||||
+ TPM_RC rc;
|
||||
+ struct grub_tpm2_buffer in;
|
||||
+ struct grub_tpm2_buffer out;
|
||||
+ TPMS_AUTH_RESPONSE authResponseTmp;
|
||||
+ TPMI_ST_COMMAND_TAG tag = authCommand ? TPM_ST_SESSIONS : TPM_ST_NO_SESSIONS;
|
||||
+ TPMT_TK_VERIFIED validationTmp;
|
||||
+ TPM_RC responseCode;
|
||||
+ grub_uint32_t param_size;
|
||||
+
|
||||
+ if (!digest || !signature)
|
||||
+ return TPM_RC_VALUE;
|
||||
+
|
||||
+ if (!validation)
|
||||
+ validation = &validationTmp;
|
||||
+ if (!authResponse)
|
||||
+ authResponse = &authResponseTmp;
|
||||
+
|
||||
+ grub_memset (validation, 0, sizeof (*validation));
|
||||
+ grub_memset (authResponse, 0, sizeof (*authResponse));
|
||||
+
|
||||
+ /* Marshal */
|
||||
+ grub_tpm2_buffer_init (&in);
|
||||
+ if (authCommand)
|
||||
+ grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
|
||||
+ grub_tpm2_buffer_pack_u32 (&in, keyHandle);
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (&in, digest->size, digest->buffer);
|
||||
+ grub_tpm2_mu_TPMT_SIGNATURE_Marshal (&in, signature);
|
||||
+ if (in.error)
|
||||
+ return TPM_RC_FAILURE;
|
||||
+
|
||||
+ /* Submit */
|
||||
+ grub_tpm2_buffer_init (&out);
|
||||
+ rc = grub_tpm2_submit_command (tag, TPM_CC_VerifySignature, &responseCode, &in, &out);
|
||||
+ if (rc != TPM_RC_SUCCESS)
|
||||
+ return rc;
|
||||
+ if (responseCode != TPM_RC_SUCCESS)
|
||||
+ return responseCode;
|
||||
+
|
||||
+ /* Unmarshal*/
|
||||
+ if (tag == TPM_ST_SESSIONS)
|
||||
+ grub_tpm2_buffer_unpack_u32 (&out, ¶m_size);
|
||||
+ grub_tpm2_mu_TPMT_TK_VERIFIED_Unmarshal (&out, validation);
|
||||
+ if (tag == TPM_ST_SESSIONS)
|
||||
+ grub_tpm2_mu_TPMS_AUTH_RESPONSE_Unmarshal (&out, authResponse);
|
||||
+ if (out.error)
|
||||
+ return TPM_RC_FAILURE;
|
||||
+
|
||||
+ return TPM_RC_SUCCESS;
|
||||
+}
|
||||
+
|
||||
+TPM_RC
|
||||
+TPM2_PolicyAuthorize (const TPMI_SH_POLICY policySession,
|
||||
+ const TPMS_AUTH_COMMAND *authCommand,
|
||||
+ const TPM2B_DIGEST *approvedPolicy,
|
||||
+ const TPM2B_NONCE *policyRef,
|
||||
+ const TPM2B_NAME *keySign,
|
||||
+ const TPMT_TK_VERIFIED *checkTicket,
|
||||
+ TPMS_AUTH_RESPONSE *authResponse)
|
||||
+{
|
||||
+ TPM_RC rc;
|
||||
+ struct grub_tpm2_buffer in;
|
||||
+ struct grub_tpm2_buffer out;
|
||||
+ TPMS_AUTH_RESPONSE authResponseTmp;
|
||||
+ TPMI_ST_COMMAND_TAG tag = authCommand ? TPM_ST_SESSIONS : TPM_ST_NO_SESSIONS;
|
||||
+ TPM_RC responseCode;
|
||||
+ grub_uint32_t param_size;
|
||||
+
|
||||
+ if (!approvedPolicy || !keySign || !checkTicket)
|
||||
+ return TPM_RC_VALUE;
|
||||
+
|
||||
+ if (!authResponse)
|
||||
+ authResponse = &authResponseTmp;
|
||||
+
|
||||
+ grub_memset (authResponse, 0, sizeof (*authResponse));
|
||||
+
|
||||
+ /* Marshal */
|
||||
+ grub_tpm2_buffer_init (&in);
|
||||
+ grub_tpm2_buffer_pack_u32 (&in, policySession);
|
||||
+ if (authCommand)
|
||||
+ grub_tpm2_mu_TPMS_AUTH_COMMAND_Marshal (&in, authCommand);
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (&in, approvedPolicy->size, approvedPolicy->buffer);
|
||||
+ if (policyRef)
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (&in, policyRef->size, policyRef->buffer);
|
||||
+ else
|
||||
+ grub_tpm2_buffer_pack_u16 (&in, 0);
|
||||
+ grub_tpm2_mu_TPM2B_Marshal (&in, keySign->size, keySign->name);
|
||||
+ grub_tpm2_mu_TPMT_TK_VERIFIED_Marshal (&in, checkTicket);
|
||||
+ if (in.error)
|
||||
+ return TPM_RC_FAILURE;
|
||||
+
|
||||
+ /* Submit */
|
||||
+ grub_tpm2_buffer_init (&out);
|
||||
+ rc = grub_tpm2_submit_command (tag, TPM_CC_PolicyAuthorize, &responseCode, &in, &out);
|
||||
+ if (rc != TPM_RC_SUCCESS)
|
||||
+ return rc;
|
||||
+ if (responseCode != TPM_RC_SUCCESS)
|
||||
+ return responseCode;
|
||||
+
|
||||
+ /* Unmarshal*/
|
||||
+ if (tag == TPM_ST_SESSIONS)
|
||||
+ grub_tpm2_buffer_unpack_u32 (&out, ¶m_size);
|
||||
+ if (tag == TPM_ST_SESSIONS)
|
||||
+ grub_tpm2_mu_TPMS_AUTH_RESPONSE_Unmarshal (&out, authResponse);
|
||||
+ if (out.error)
|
||||
+ return TPM_RC_FAILURE;
|
||||
+
|
||||
+ return TPM_RC_SUCCESS;
|
||||
+}
|
||||
diff --git a/include/grub/tpm2/internal/functions.h b/include/grub/tpm2/internal/functions.h
|
||||
index 9380f26a2..67b78fab8 100644
|
||||
--- a/include/grub/tpm2/internal/functions.h
|
||||
+++ b/include/grub/tpm2/internal/functions.h
|
||||
@@ -70,6 +70,15 @@ TPM2_Load (const TPMI_DH_OBJECT parent_handle,
|
||||
TPM2B_NAME *name,
|
||||
TPMS_AUTH_RESPONSE *authResponse);
|
||||
|
||||
+TPM_RC
|
||||
+TPM2_LoadExternal (const TPMS_AUTH_COMMAND *authCommand,
|
||||
+ const TPM2B_SENSITIVE *inPrivate,
|
||||
+ const TPM2B_PUBLIC *inPublic,
|
||||
+ const TPMI_RH_HIERARCHY hierarchy,
|
||||
+ TPM_HANDLE *objectHandle,
|
||||
+ TPM2B_NAME *name,
|
||||
+ TPMS_AUTH_RESPONSE *authResponse);
|
||||
+
|
||||
TPM_RC
|
||||
TPM2_Unseal (const TPMI_DH_OBJECT item_handle,
|
||||
const TPMS_AUTH_COMMAND *authCommand,
|
||||
@@ -114,4 +123,52 @@ TPM2_EvictControl (const TPMI_RH_PROVISION auth,
|
||||
const TPMI_DH_PERSISTENT persistentHandle,
|
||||
TPMS_AUTH_RESPONSE *authResponse);
|
||||
|
||||
+TPM_RC
|
||||
+TPM2_HashSequenceStart (const TPMS_AUTH_COMMAND *authCommand,
|
||||
+ const TPM2B_AUTH *auth,
|
||||
+ const TPMI_ALG_HASH hashAlg,
|
||||
+ TPMI_DH_OBJECT *sequenceHandle,
|
||||
+ TPMS_AUTH_RESPONSE *authResponse);
|
||||
+
|
||||
+TPM_RC
|
||||
+TPM2_SequenceUpdate (const TPMI_DH_OBJECT sequenceHandle,
|
||||
+ const TPMS_AUTH_COMMAND *authCommand,
|
||||
+ const TPM2B_MAX_BUFFER *buffer,
|
||||
+ TPMS_AUTH_RESPONSE *authResponse);
|
||||
+
|
||||
+TPM_RC
|
||||
+TPM2_SequenceComplete (const TPMI_DH_OBJECT sequenceHandle,
|
||||
+ const TPMS_AUTH_COMMAND *authCommand,
|
||||
+ const TPM2B_MAX_BUFFER *buffer,
|
||||
+ const TPMI_RH_HIERARCHY hierarchy,
|
||||
+ TPM2B_DIGEST *result,
|
||||
+ TPMT_TK_HASHCHECK *validation,
|
||||
+ TPMS_AUTH_RESPONSE *authResponse);
|
||||
+
|
||||
+TPM_RC
|
||||
+TPM2_Hash (const TPMS_AUTH_COMMAND *authCommand,
|
||||
+ const TPM2B_MAX_BUFFER *data,
|
||||
+ const TPMI_ALG_HASH hashAlg,
|
||||
+ const TPMI_RH_HIERARCHY hierarchy,
|
||||
+ TPM2B_DIGEST *outHash,
|
||||
+ TPMT_TK_HASHCHECK *validation,
|
||||
+ TPMS_AUTH_RESPONSE *authResponse);
|
||||
+
|
||||
+TPM_RC
|
||||
+TPM2_VerifySignature (const TPMI_DH_OBJECT keyHandle,
|
||||
+ const TPMS_AUTH_COMMAND *authCommand,
|
||||
+ const TPM2B_DIGEST *digest,
|
||||
+ const TPMT_SIGNATURE *signature,
|
||||
+ TPMT_TK_VERIFIED *validation,
|
||||
+ TPMS_AUTH_RESPONSE *authResponse);
|
||||
+
|
||||
+TPM_RC
|
||||
+TPM2_PolicyAuthorize (const TPMI_SH_POLICY policySession,
|
||||
+ const TPMS_AUTH_COMMAND *authCommand,
|
||||
+ const TPM2B_DIGEST *approvedPolicy,
|
||||
+ const TPM2B_NONCE *policyRef,
|
||||
+ const TPM2B_NAME *keySign,
|
||||
+ const TPMT_TK_VERIFIED *checkTicket,
|
||||
+ TPMS_AUTH_RESPONSE *authResponse);
|
||||
+
|
||||
#endif /* ! GRUB_TPM2_INTERNAL_FUNCTIONS_HEADER */
|
||||
--
|
||||
2.35.3
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From cf6b16f113b1b5e6efce79b569be1de3e504de8f Mon Sep 17 00:00:00 2001
|
||||
From: Rashmica Gupta <rashmica.g@gmail.com>
|
||||
Date: Thu, 11 Jun 2020 11:26:23 +1000
|
||||
Subject: [PATCH] Add suport for signing grub with an appended signature
|
||||
Subject: [PATCH 04/23] Add suport for signing grub with an appended signature
|
||||
|
||||
Add infrastructure to allow firmware to verify the integrity of grub
|
||||
by use of a Linux-kernel-module-style appended signature. We initially
|
||||
@ -43,19 +43,65 @@ that verifies these signatures. You can find one at:
|
||||
I will be proposing this for inclusion in a future Power Architecture
|
||||
Platform Reference (PAPR).
|
||||
---
|
||||
util/grub-install-common.c | 18 ++++++++++++++++--
|
||||
util/grub-mkimage.c | 15 +++++++++++++--
|
||||
util/grub-mkimagexx.c | 39 ++++++++++++++++++++++++++++++++++++++-
|
||||
util/mkimage.c | 13 +++++++------
|
||||
include/grub/util/install.h | 8 ++++++--
|
||||
include/grub/util/mkimage.h | 4 ++--
|
||||
6 files changed, 82 insertions(+), 15 deletions(-)
|
||||
util/grub-install-common.c | 15 +++++++++++---
|
||||
util/grub-mkimage.c | 11 +++++++++++
|
||||
util/grub-mkimagexx.c | 39 ++++++++++++++++++++++++++++++++++++-
|
||||
util/mkimage.c | 13 +++++++------
|
||||
6 files changed, 76 insertions(+), 14 deletions(-)
|
||||
|
||||
--- a/include/grub/util/install.h
|
||||
+++ b/include/grub/util/install.h
|
||||
@@ -67,6 +67,9 @@
|
||||
N_("SBAT metadata"), 0 }, \
|
||||
{ "disable-shim-lock", GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK, 0, 0, \
|
||||
N_("disable shim_lock verifier"), 0 }, \
|
||||
+ { "appended-signature-size", GRUB_INSTALL_OPTIONS_APPENDED_SIGNATURE_SIZE,\
|
||||
+ "SIZE", 0, N_("Add a note segment reserving SIZE bytes for an appended signature"), \
|
||||
+ 1}, \
|
||||
{ "verbose", 'v', 0, 0, \
|
||||
N_("print verbose messages."), 1 }
|
||||
|
||||
@@ -130,7 +133,8 @@
|
||||
GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS,
|
||||
GRUB_INSTALL_OPTIONS_DTB,
|
||||
GRUB_INSTALL_OPTIONS_SBAT,
|
||||
- GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK
|
||||
+ GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK,
|
||||
+ GRUB_INSTALL_OPTIONS_APPENDED_SIGNATURE_SIZE
|
||||
};
|
||||
|
||||
extern char *grub_install_source_directory;
|
||||
@@ -190,7 +194,7 @@
|
||||
size_t npubkeys,
|
||||
char *config_path,
|
||||
const struct grub_install_image_target_desc *image_target,
|
||||
- int note,
|
||||
+ int note, size_t appsig_size,
|
||||
grub_compression_t comp, const char *dtb_file,
|
||||
const char *sbat_path, const int disable_shim_lock);
|
||||
|
||||
--- a/include/grub/util/mkimage.h
|
||||
+++ b/include/grub/util/mkimage.h
|
||||
@@ -51,12 +51,12 @@
|
||||
const struct grub_install_image_target_desc *image_target);
|
||||
void
|
||||
grub_mkimage_generate_elf32 (const struct grub_install_image_target_desc *image_target,
|
||||
- int note, char **core_img, size_t *core_size,
|
||||
+ int note, size_t appsig_size, char **core_img, size_t *core_size,
|
||||
Elf32_Addr target_addr,
|
||||
struct grub_mkimage_layout *layout);
|
||||
void
|
||||
grub_mkimage_generate_elf64 (const struct grub_install_image_target_desc *image_target,
|
||||
- int note, char **core_img, size_t *core_size,
|
||||
+ int note, size_t appsig_size, char **core_img, size_t *core_size,
|
||||
Elf64_Addr target_addr,
|
||||
struct grub_mkimage_layout *layout);
|
||||
|
||||
diff --git a/util/grub-install-common.c b/util/grub-install-common.c
|
||||
index 4e212e690c5..aab2a941f85 100644
|
||||
--- a/util/grub-install-common.c
|
||||
+++ b/util/grub-install-common.c
|
||||
@@ -461,10 +461,12 @@ static size_t npubkeys;
|
||||
@@ -466,10 +466,12 @@
|
||||
static char *sbat;
|
||||
static int disable_shim_lock;
|
||||
static grub_compression_t compression;
|
||||
@ -67,8 +113,8 @@ index 4e212e690c5..aab2a941f85 100644
|
||||
+ const char *end;
|
||||
switch (key)
|
||||
{
|
||||
case 'C':
|
||||
@@ -562,6 +564,12 @@ grub_install_parse (int key, char *arg)
|
||||
case GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS:
|
||||
@@ -567,6 +569,12 @@
|
||||
grub_util_error (_("Unrecognized compression `%s'"), arg);
|
||||
case GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE:
|
||||
return 1;
|
||||
@ -81,22 +127,20 @@ index 4e212e690c5..aab2a941f85 100644
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@@ -665,7 +673,13 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix,
|
||||
dir, prefix,
|
||||
outname, dtb ? : "", sbat ? : "", mkimage_target,
|
||||
compnames[compression], note ? "--note" : "",
|
||||
- disable_shim_lock ? "--disable-shim-lock" : "", s);
|
||||
+ disable_shim_lock ? "--disable-shim-lock" : "",
|
||||
+ "--format '%s' --compression '%s' "
|
||||
+ "--appended-signature-size %zu %s %s\n",
|
||||
+ dir, prefix,
|
||||
+ outname, dtb ? : "", mkimage_target,
|
||||
+ compnames[compression], appsig_size,
|
||||
+ note ? "--note" : "", s);
|
||||
free (s);
|
||||
@@ -679,9 +687,11 @@
|
||||
*p = '\0';
|
||||
|
||||
tgt = grub_install_get_image_target (mkimage_target);
|
||||
@@ -675,7 +689,7 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix,
|
||||
grub_util_info ("grub-mkimage --directory '%s' --prefix '%s' --output '%s'"
|
||||
- " --format '%s' --compression '%s'%s%s%s\n",
|
||||
+ " --format '%s' --compression '%s'"
|
||||
+ " --appended-signature-size %zu%s%s%s\n",
|
||||
dir, prefix, outname,
|
||||
mkimage_target, compnames[compression],
|
||||
+ appsig_size,
|
||||
note ? " --note" : "",
|
||||
disable_shim_lock ? " --disable-shim-lock" : "", s);
|
||||
free (s);
|
||||
@@ -693,7 +703,7 @@
|
||||
grub_install_generate_image (dir, prefix, fp, outname,
|
||||
modules.entries, memdisk_path,
|
||||
pubkeys, npubkeys, config_path, tgt,
|
||||
@ -105,11 +149,9 @@ index 4e212e690c5..aab2a941f85 100644
|
||||
disable_shim_lock);
|
||||
while (dc--)
|
||||
grub_install_pop_module ();
|
||||
diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c
|
||||
index c0d55993702..8a53310548b 100644
|
||||
--- a/util/grub-mkimage.c
|
||||
+++ b/util/grub-mkimage.c
|
||||
@@ -84,6 +84,7 @@ static struct argp_option options[] = {
|
||||
@@ -84,6 +84,7 @@
|
||||
{"sbat", 's', N_("FILE"), 0, N_("SBAT metadata"), 0},
|
||||
{"disable-shim-lock", GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK, 0, 0, N_("disable shim_lock verifier"), 0},
|
||||
{"verbose", 'v', 0, 0, N_("print verbose messages."), 0},
|
||||
@ -117,7 +159,7 @@ index c0d55993702..8a53310548b 100644
|
||||
{ 0, 0, 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
@@ -128,6 +129,7 @@ struct arguments
|
||||
@@ -128,6 +129,7 @@
|
||||
char *sbat;
|
||||
int note;
|
||||
int disable_shim_lock;
|
||||
@ -125,7 +167,7 @@ index c0d55993702..8a53310548b 100644
|
||||
const struct grub_install_image_target_desc *image_target;
|
||||
grub_compression_t comp;
|
||||
};
|
||||
@@ -138,6 +140,7 @@ argp_parser (int key, char *arg, struct argp_state *state)
|
||||
@@ -138,6 +140,7 @@
|
||||
/* Get the input argument from argp_parse, which we
|
||||
know is a pointer to our arguments structure. */
|
||||
struct arguments *arguments = state->input;
|
||||
@ -133,7 +175,7 @@ index c0d55993702..8a53310548b 100644
|
||||
|
||||
switch (key)
|
||||
{
|
||||
@@ -170,6 +173,13 @@ argp_parser (int key, char *arg, struct argp_state *state)
|
||||
@@ -170,6 +173,13 @@
|
||||
arguments->note = 1;
|
||||
break;
|
||||
|
||||
@ -147,23 +189,17 @@ index c0d55993702..8a53310548b 100644
|
||||
case 'm':
|
||||
if (arguments->memdisk)
|
||||
free (arguments->memdisk);
|
||||
@@ -324,8 +334,9 @@ main (int argc, char *argv[])
|
||||
@@ -324,6 +334,7 @@
|
||||
arguments.memdisk, arguments.pubkeys,
|
||||
arguments.npubkeys, arguments.config,
|
||||
arguments.image_target, arguments.note,
|
||||
- arguments.comp, arguments.dtb,
|
||||
- arguments.sbat, arguments.disable_shim_lock);
|
||||
+ arguments.appsig_size, arguments.comp,
|
||||
+ arguments.dtb, arguments.sbat,
|
||||
+ arguments.disable_shim_lock);
|
||||
+ arguments.appsig_size,
|
||||
arguments.comp, arguments.dtb,
|
||||
arguments.sbat, arguments.disable_shim_lock);
|
||||
|
||||
if (grub_util_file_sync (fp) < 0)
|
||||
grub_util_error (_("cannot sync `%s': %s"), arguments.output ? : "stdout",
|
||||
diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c
|
||||
index d78fa3e5330..393119486d3 100644
|
||||
--- a/util/grub-mkimagexx.c
|
||||
+++ b/util/grub-mkimagexx.c
|
||||
@@ -84,6 +84,15 @@ struct grub_ieee1275_note
|
||||
@@ -85,6 +85,15 @@
|
||||
struct grub_ieee1275_note_desc descriptor;
|
||||
};
|
||||
|
||||
@ -179,7 +215,7 @@ index d78fa3e5330..393119486d3 100644
|
||||
#define GRUB_XEN_NOTE_NAME "Xen"
|
||||
|
||||
struct fixup_block_list
|
||||
@@ -207,7 +216,7 @@ grub_arm_reloc_jump24 (grub_uint32_t *target, Elf32_Addr sym_addr)
|
||||
@@ -208,7 +217,7 @@
|
||||
|
||||
void
|
||||
SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc *image_target,
|
||||
@ -188,7 +224,7 @@ index d78fa3e5330..393119486d3 100644
|
||||
Elf_Addr target_addr,
|
||||
struct grub_mkimage_layout *layout)
|
||||
{
|
||||
@@ -221,6 +230,12 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
|
||||
@@ -222,6 +231,12 @@
|
||||
int shnum = 4;
|
||||
int string_size = sizeof (".text") + sizeof ("mods") + 1;
|
||||
|
||||
@ -201,7 +237,7 @@ index d78fa3e5330..393119486d3 100644
|
||||
if (image_target->id != IMAGE_LOONGSON_ELF)
|
||||
phnum += 2;
|
||||
|
||||
@@ -484,6 +499,28 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc
|
||||
@@ -485,6 +500,28 @@
|
||||
phdr->p_offset = grub_host_to_target32 (header_size + program_size);
|
||||
}
|
||||
|
||||
@ -230,11 +266,9 @@ index d78fa3e5330..393119486d3 100644
|
||||
{
|
||||
char *str_start = (elf_img + sizeof (*ehdr) + phnum * sizeof (*phdr)
|
||||
+ shnum * sizeof (*shdr));
|
||||
diff --git a/util/mkimage.c b/util/mkimage.c
|
||||
index a26cf76f72f..bab12276010 100644
|
||||
--- a/util/mkimage.c
|
||||
+++ b/util/mkimage.c
|
||||
@@ -869,8 +869,9 @@ grub_install_generate_image (const char *dir, const char *prefix,
|
||||
@@ -885,8 +885,9 @@
|
||||
char *memdisk_path, char **pubkey_paths,
|
||||
size_t npubkeys, char *config_path,
|
||||
const struct grub_install_image_target_desc *image_target,
|
||||
@ -246,7 +280,7 @@ index a26cf76f72f..bab12276010 100644
|
||||
{
|
||||
char *kernel_img, *core_img;
|
||||
size_t total_module_size, core_size;
|
||||
@@ -1773,11 +1774,11 @@ grub_install_generate_image (const char *dir, const char *prefix,
|
||||
@@ -1810,11 +1811,11 @@
|
||||
else
|
||||
target_addr = image_target->link_addr;
|
||||
if (image_target->voidp_sizeof == 4)
|
||||
@ -262,55 +296,3 @@ index a26cf76f72f..bab12276010 100644
|
||||
}
|
||||
break;
|
||||
}
|
||||
diff --git a/include/grub/util/install.h b/include/grub/util/install.h
|
||||
index 7df3191f47e..cf4531e02b6 100644
|
||||
--- a/include/grub/util/install.h
|
||||
+++ b/include/grub/util/install.h
|
||||
@@ -67,6 +67,9 @@
|
||||
N_("SBAT metadata"), 0 }, \
|
||||
{ "disable-shim-lock", GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK, 0, 0, \
|
||||
N_("disable shim_lock verifier"), 0 }, \
|
||||
+ { "appended-signature-size", GRUB_INSTALL_OPTIONS_APPENDED_SIGNATURE_SIZE,\
|
||||
+ "SIZE", 0, N_("Add a note segment reserving SIZE bytes for an appended signature"), \
|
||||
+ 1}, \
|
||||
{ "verbose", 'v', 0, 0, \
|
||||
N_("print verbose messages."), 1 }
|
||||
|
||||
@@ -128,7 +131,8 @@ enum grub_install_options {
|
||||
GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS,
|
||||
GRUB_INSTALL_OPTIONS_DTB,
|
||||
GRUB_INSTALL_OPTIONS_SBAT,
|
||||
- GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK
|
||||
+ GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK,
|
||||
+ GRUB_INSTALL_OPTIONS_APPENDED_SIGNATURE_SIZE
|
||||
};
|
||||
|
||||
extern char *grub_install_source_directory;
|
||||
@@ -188,7 +192,7 @@ grub_install_generate_image (const char *dir, const char *prefix,
|
||||
size_t npubkeys,
|
||||
char *config_path,
|
||||
const struct grub_install_image_target_desc *image_target,
|
||||
- int note,
|
||||
+ int note, size_t appsig_size,
|
||||
grub_compression_t comp, const char *dtb_file,
|
||||
const char *sbat_path, const int disable_shim_lock);
|
||||
|
||||
diff --git a/include/grub/util/mkimage.h b/include/grub/util/mkimage.h
|
||||
index 3819a67441c..6f1da89b9b6 100644
|
||||
--- a/include/grub/util/mkimage.h
|
||||
+++ b/include/grub/util/mkimage.h
|
||||
@@ -51,12 +51,12 @@ grub_mkimage_load_image64 (const char *kernel_path,
|
||||
const struct grub_install_image_target_desc *image_target);
|
||||
void
|
||||
grub_mkimage_generate_elf32 (const struct grub_install_image_target_desc *image_target,
|
||||
- int note, char **core_img, size_t *core_size,
|
||||
+ int note, size_t appsig_size, char **core_img, size_t *core_size,
|
||||
Elf32_Addr target_addr,
|
||||
struct grub_mkimage_layout *layout);
|
||||
void
|
||||
grub_mkimage_generate_elf64 (const struct grub_install_image_target_desc *image_target,
|
||||
- int note, char **core_img, size_t *core_size,
|
||||
+ int note, size_t appsig_size, char **core_img, size_t *core_size,
|
||||
Elf64_Addr target_addr,
|
||||
struct grub_mkimage_layout *layout);
|
||||
|
||||
@ -1,983 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Matthew Garrett <mjg@redhat.com>
|
||||
Date: Tue, 10 Jul 2012 11:58:52 -0400
|
||||
Subject: [PATCH] Add support for Linux EFI stub loading.
|
||||
|
||||
Also:
|
||||
|
||||
commit 71c843745f22f81e16d259e2e19c99bf3c1855c1
|
||||
Author: Colin Watson <cjwatson@ubuntu.com>
|
||||
Date: Tue Oct 23 10:40:49 2012 -0400
|
||||
|
||||
Don't allow insmod when secure boot is enabled.
|
||||
|
||||
Hi,
|
||||
|
||||
Fedora's patch to forbid insmod in UEFI Secure Boot environments is fine
|
||||
as far as it goes. However, the insmod command is not the only way that
|
||||
modules can be loaded. In particular, the 'normal' command, which
|
||||
implements the usual GRUB menu and the fully-featured command prompt,
|
||||
will implicitly load commands not currently loaded into memory. This
|
||||
permits trivial Secure Boot violations by writing commands implementing
|
||||
whatever you want to do and pointing $prefix at the malicious code.
|
||||
|
||||
I'm currently test-building this patch (replacing your current
|
||||
grub-2.00-no-insmod-on-sb.patch), but this should be more correct. It
|
||||
moves the check into grub_dl_load_file.
|
||||
---
|
||||
grub-core/Makefile.core.def | 16 +-
|
||||
grub-core/kern/dl.c | 21 +++
|
||||
grub-core/kern/efi/efi.c | 28 ++++
|
||||
grub-core/kern/efi/mm.c | 32 ++++
|
||||
grub-core/loader/arm64/linux.c | 118 +++++++-------
|
||||
grub-core/loader/arm64/xen_boot.c | 1 -
|
||||
grub-core/loader/efi/linux.c | 70 ++++++++
|
||||
grub-core/loader/i386/efi/linux.c | 335 ++++++++++++++++++++++++++++++++++++++
|
||||
grub-core/loader/i386/pc/linux.c | 10 +-
|
||||
include/grub/arm/linux.h | 9 +
|
||||
include/grub/arm64/linux.h | 9 +
|
||||
include/grub/efi/efi.h | 7 +-
|
||||
include/grub/efi/linux.h | 31 ++++
|
||||
13 files changed, 618 insertions(+), 69 deletions(-)
|
||||
create mode 100644 grub-core/loader/efi/linux.c
|
||||
create mode 100644 grub-core/loader/i386/efi/linux.c
|
||||
create mode 100644 include/grub/efi/linux.h
|
||||
|
||||
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
|
||||
index 8022e1c0a79..45d3edaa4dc 100644
|
||||
--- a/grub-core/Makefile.core.def
|
||||
+++ b/grub-core/Makefile.core.def
|
||||
@@ -1734,13 +1734,6 @@ module = {
|
||||
enable = i386_pc;
|
||||
};
|
||||
|
||||
-
|
||||
-module = {
|
||||
- name = linux16;
|
||||
- common = loader/i386/pc/linux.c;
|
||||
- enable = x86;
|
||||
-};
|
||||
-
|
||||
module = {
|
||||
name = ntldr;
|
||||
i386_pc = loader/i386/pc/ntldr.c;
|
||||
@@ -1796,7 +1789,9 @@ module = {
|
||||
|
||||
module = {
|
||||
name = linux;
|
||||
- x86 = loader/i386/linux.c;
|
||||
+ i386_pc = loader/i386/pc/linux.c;
|
||||
+ x86_64_efi = loader/i386/efi/linux.c;
|
||||
+ i386_efi = loader/i386/efi/linux.c;
|
||||
i386_xen_pvh = loader/i386/linux.c;
|
||||
xen = loader/i386/xen.c;
|
||||
i386_pc = lib/i386/pc/vesa_modes_table.c;
|
||||
@@ -1811,9 +1806,14 @@ module = {
|
||||
arm64 = loader/arm64/linux.c;
|
||||
riscv32 = loader/riscv/linux.c;
|
||||
riscv64 = loader/riscv/linux.c;
|
||||
+ emu = loader/emu/linux.c;
|
||||
+ fdt = lib/fdt.c;
|
||||
+
|
||||
common = loader/linux.c;
|
||||
common = lib/cmdline.c;
|
||||
enable = noemu;
|
||||
+
|
||||
+ efi = loader/efi/linux.c;
|
||||
};
|
||||
|
||||
module = {
|
||||
diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c
|
||||
index 48f8a79073d..b7149370950 100644
|
||||
--- a/grub-core/kern/dl.c
|
||||
+++ b/grub-core/kern/dl.c
|
||||
@@ -38,6 +38,14 @@
|
||||
#define GRUB_MODULES_MACHINE_READONLY
|
||||
#endif
|
||||
|
||||
+#ifdef GRUB_MACHINE_EMU
|
||||
+#include <sys/mman.h>
|
||||
+#endif
|
||||
+
|
||||
+#ifdef GRUB_MACHINE_EFI
|
||||
+#include <grub/efi/efi.h>
|
||||
+#endif
|
||||
+
|
||||
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||
@@ -695,6 +703,19 @@ grub_dl_load_file (const char *filename)
|
||||
void *core = 0;
|
||||
grub_dl_t mod = 0;
|
||||
|
||||
+#ifdef GRUB_MACHINE_EFI
|
||||
+ if (grub_efi_secure_boot ())
|
||||
+ {
|
||||
+#if 0
|
||||
+ /* This is an error, but grub2-mkconfig still generates a pile of
|
||||
+ * insmod commands, so emitting it would be mostly just obnoxious. */
|
||||
+ grub_error (GRUB_ERR_ACCESS_DENIED,
|
||||
+ "Secure Boot forbids loading module from %s", filename);
|
||||
+#endif
|
||||
+ return 0;
|
||||
+ }
|
||||
+#endif
|
||||
+
|
||||
grub_boot_time ("Loading module %s", filename);
|
||||
|
||||
file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE);
|
||||
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
|
||||
index 8cff7be0289..35b8f670602 100644
|
||||
--- a/grub-core/kern/efi/efi.c
|
||||
+++ b/grub-core/kern/efi/efi.c
|
||||
@@ -286,6 +286,34 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
|
||||
return grub_efi_get_variable_with_attributes (var, guid, datasize_out, data_out, NULL);
|
||||
}
|
||||
|
||||
+grub_efi_boolean_t
|
||||
+grub_efi_secure_boot (void)
|
||||
+{
|
||||
+ grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
|
||||
+ grub_size_t datasize;
|
||||
+ char *secure_boot = NULL;
|
||||
+ char *setup_mode = NULL;
|
||||
+ grub_efi_boolean_t ret = 0;
|
||||
+
|
||||
+ secure_boot = grub_efi_get_variable("SecureBoot", &efi_var_guid, &datasize);
|
||||
+
|
||||
+ if (datasize != 1 || !secure_boot)
|
||||
+ goto out;
|
||||
+
|
||||
+ setup_mode = grub_efi_get_variable("SetupMode", &efi_var_guid, &datasize);
|
||||
+
|
||||
+ if (datasize != 1 || !setup_mode)
|
||||
+ goto out;
|
||||
+
|
||||
+ if (*secure_boot && !*setup_mode)
|
||||
+ ret = 1;
|
||||
+
|
||||
+ out:
|
||||
+ grub_free (secure_boot);
|
||||
+ grub_free (setup_mode);
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||
|
||||
/* Search the mods section from the PE32/PE32+ image. This code uses
|
||||
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
|
||||
index 9838fb2f50d..f6aef0ef649 100644
|
||||
--- a/grub-core/kern/efi/mm.c
|
||||
+++ b/grub-core/kern/efi/mm.c
|
||||
@@ -113,6 +113,38 @@ grub_efi_drop_alloc (grub_efi_physical_address_t address,
|
||||
}
|
||||
}
|
||||
|
||||
+/* Allocate pages below a specified address */
|
||||
+void *
|
||||
+grub_efi_allocate_pages_max (grub_efi_physical_address_t max,
|
||||
+ grub_efi_uintn_t pages)
|
||||
+{
|
||||
+ grub_efi_status_t status;
|
||||
+ grub_efi_boot_services_t *b;
|
||||
+ grub_efi_physical_address_t address = max;
|
||||
+
|
||||
+ if (max > 0xffffffff)
|
||||
+ return 0;
|
||||
+
|
||||
+ b = grub_efi_system_table->boot_services;
|
||||
+ status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_MAX_ADDRESS, GRUB_EFI_LOADER_DATA, pages, &address);
|
||||
+
|
||||
+ if (status != GRUB_EFI_SUCCESS)
|
||||
+ return 0;
|
||||
+
|
||||
+ if (address == 0)
|
||||
+ {
|
||||
+ /* Uggh, the address 0 was allocated... This is too annoying,
|
||||
+ so reallocate another one. */
|
||||
+ address = max;
|
||||
+ status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_MAX_ADDRESS, GRUB_EFI_LOADER_DATA, pages, &address);
|
||||
+ grub_efi_free_pages (0, pages);
|
||||
+ if (status != GRUB_EFI_SUCCESS)
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ return (void *) ((grub_addr_t) address);
|
||||
+}
|
||||
+
|
||||
/* Allocate pages. Return the pointer to the first of allocated pages. */
|
||||
void *
|
||||
grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
|
||||
diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
|
||||
index ef3e9f9444c..a312c668685 100644
|
||||
--- a/grub-core/loader/arm64/linux.c
|
||||
+++ b/grub-core/loader/arm64/linux.c
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <grub/efi/efi.h>
|
||||
#include <grub/efi/fdtload.h>
|
||||
#include <grub/efi/memory.h>
|
||||
+#include <grub/efi/linux.h>
|
||||
#include <grub/efi/pe32.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/lib/cmdline.h>
|
||||
@@ -41,6 +42,7 @@ static int loaded;
|
||||
|
||||
static void *kernel_addr;
|
||||
static grub_uint64_t kernel_size;
|
||||
+static grub_uint32_t handover_offset;
|
||||
|
||||
static char *linux_args;
|
||||
static grub_uint32_t cmdline_size;
|
||||
@@ -67,7 +69,8 @@ grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh)
|
||||
static grub_err_t
|
||||
finalize_params_linux (void)
|
||||
{
|
||||
- int node, retval;
|
||||
+ grub_efi_loaded_image_t *loaded_image = NULL;
|
||||
+ int node, retval, len;
|
||||
|
||||
void *fdt;
|
||||
|
||||
@@ -102,79 +105,70 @@ finalize_params_linux (void)
|
||||
if (grub_fdt_install() != GRUB_ERR_NONE)
|
||||
goto failure;
|
||||
|
||||
- return GRUB_ERR_NONE;
|
||||
-
|
||||
-failure:
|
||||
- grub_fdt_unload();
|
||||
- return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT");
|
||||
-}
|
||||
-
|
||||
-grub_err_t
|
||||
-grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
|
||||
-{
|
||||
- grub_efi_memory_mapped_device_path_t *mempath;
|
||||
- grub_efi_handle_t image_handle;
|
||||
- grub_efi_boot_services_t *b;
|
||||
- grub_efi_status_t status;
|
||||
- grub_efi_loaded_image_t *loaded_image;
|
||||
- int len;
|
||||
-
|
||||
- mempath = grub_malloc (2 * sizeof (grub_efi_memory_mapped_device_path_t));
|
||||
- if (!mempath)
|
||||
- return grub_errno;
|
||||
-
|
||||
- mempath[0].header.type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE;
|
||||
- mempath[0].header.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE;
|
||||
- mempath[0].header.length = grub_cpu_to_le16_compile_time (sizeof (*mempath));
|
||||
- mempath[0].memory_type = GRUB_EFI_LOADER_DATA;
|
||||
- mempath[0].start_address = addr;
|
||||
- mempath[0].end_address = addr + size;
|
||||
-
|
||||
- mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE;
|
||||
- mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
|
||||
- mempath[1].header.length = sizeof (grub_efi_device_path_t);
|
||||
-
|
||||
- b = grub_efi_system_table->boot_services;
|
||||
- status = b->load_image (0, grub_efi_image_handle,
|
||||
- (grub_efi_device_path_t *) mempath,
|
||||
- (void *) addr, size, &image_handle);
|
||||
- if (status != GRUB_EFI_SUCCESS)
|
||||
- return grub_error (GRUB_ERR_BAD_OS, "cannot load image");
|
||||
-
|
||||
- grub_dprintf ("linux", "linux command line: '%s'\n", args);
|
||||
+ grub_dprintf ("linux", "Installed/updated FDT configuration table @ %p\n",
|
||||
+ fdt);
|
||||
|
||||
/* Convert command line to UCS-2 */
|
||||
- loaded_image = grub_efi_get_loaded_image (image_handle);
|
||||
+ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
|
||||
+ if (!loaded_image)
|
||||
+ goto failure;
|
||||
+
|
||||
loaded_image->load_options_size = len =
|
||||
- (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t);
|
||||
+ (grub_strlen (linux_args) + 1) * sizeof (grub_efi_char16_t);
|
||||
loaded_image->load_options =
|
||||
grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
|
||||
if (!loaded_image->load_options)
|
||||
- return grub_errno;
|
||||
+ return grub_error(GRUB_ERR_BAD_OS, "failed to create kernel parameters");
|
||||
|
||||
loaded_image->load_options_size =
|
||||
2 * grub_utf8_to_utf16 (loaded_image->load_options, len,
|
||||
- (grub_uint8_t *) args, len, NULL);
|
||||
+ (grub_uint8_t *) linux_args, len, NULL);
|
||||
|
||||
- grub_dprintf ("linux", "starting image %p\n", image_handle);
|
||||
- status = b->start_image (image_handle, 0, NULL);
|
||||
+ return GRUB_ERR_NONE;
|
||||
|
||||
- /* When successful, not reached */
|
||||
- b->unload_image (image_handle);
|
||||
- grub_efi_free_pages ((grub_addr_t) loaded_image->load_options,
|
||||
- GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
|
||||
+failure:
|
||||
+ grub_fdt_unload();
|
||||
+ return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT");
|
||||
+}
|
||||
|
||||
- return grub_errno;
|
||||
+static void
|
||||
+free_params (void)
|
||||
+{
|
||||
+ grub_efi_loaded_image_t *loaded_image = NULL;
|
||||
+
|
||||
+ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
|
||||
+ if (loaded_image)
|
||||
+ {
|
||||
+ if (loaded_image->load_options)
|
||||
+ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_efi_uintn_t)loaded_image->load_options,
|
||||
+ GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
|
||||
+ loaded_image->load_options = NULL;
|
||||
+ loaded_image->load_options_size = 0;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+grub_err_t
|
||||
+grub_arch_efi_linux_boot_image (grub_addr_t addr, char *args)
|
||||
+{
|
||||
+ grub_err_t retval;
|
||||
+
|
||||
+ retval = finalize_params_linux ();
|
||||
+ if (retval != GRUB_ERR_NONE)
|
||||
+ return grub_errno;
|
||||
+
|
||||
+ grub_dprintf ("linux", "linux command line: '%s'\n", args);
|
||||
+
|
||||
+ retval = grub_efi_linux_boot ((char *)addr, handover_offset, (void *)addr);
|
||||
+
|
||||
+ /* Never reached... */
|
||||
+ free_params();
|
||||
+ return retval;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_linux_boot (void)
|
||||
{
|
||||
- if (finalize_params_linux () != GRUB_ERR_NONE)
|
||||
- return grub_errno;
|
||||
-
|
||||
- return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr,
|
||||
- kernel_size, linux_args));
|
||||
+ return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr, linux_args));
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
@@ -288,6 +282,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
{
|
||||
grub_file_t file = 0;
|
||||
struct linux_arch_kernel_header lh;
|
||||
+ struct grub_armxx_linux_pe_header *pe;
|
||||
grub_err_t err;
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
@@ -333,6 +328,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
grub_dprintf ("linux", "kernel @ %p\n", kernel_addr);
|
||||
|
||||
+ if (!grub_linuxefi_secure_validate (kernel_addr, kernel_size))
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), argv[0]);
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ pe = (void *)((unsigned long)kernel_addr + lh.hdr_offset);
|
||||
+ handover_offset = pe->opt.entry_addr;
|
||||
+
|
||||
cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE);
|
||||
linux_args = grub_malloc (cmdline_size);
|
||||
if (!linux_args)
|
||||
diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c
|
||||
index 22cc25eccd9..d9b7a9ba400 100644
|
||||
--- a/grub-core/loader/arm64/xen_boot.c
|
||||
+++ b/grub-core/loader/arm64/xen_boot.c
|
||||
@@ -266,7 +266,6 @@ xen_boot (void)
|
||||
return err;
|
||||
|
||||
return grub_arch_efi_linux_boot_image (xen_hypervisor->start,
|
||||
- xen_hypervisor->size,
|
||||
xen_hypervisor->cmdline);
|
||||
}
|
||||
|
||||
diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
|
||||
new file mode 100644
|
||||
index 00000000000..c24202a5dd1
|
||||
--- /dev/null
|
||||
+++ b/grub-core/loader/efi/linux.c
|
||||
@@ -0,0 +1,70 @@
|
||||
+/*
|
||||
+ * GRUB -- GRand Unified Bootloader
|
||||
+ * Copyright (C) 2014 Free Software Foundation, Inc.
|
||||
+ *
|
||||
+ * GRUB 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 3 of the License, or
|
||||
+ * (at your option) any later version.
|
||||
+ *
|
||||
+ * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
+ */
|
||||
+
|
||||
+#include <grub/err.h>
|
||||
+#include <grub/mm.h>
|
||||
+#include <grub/types.h>
|
||||
+#include <grub/cpu/linux.h>
|
||||
+#include <grub/efi/efi.h>
|
||||
+#include <grub/efi/pe32.h>
|
||||
+#include <grub/efi/linux.h>
|
||||
+
|
||||
+#define SHIM_LOCK_GUID \
|
||||
+ { 0x605dab50, 0xe046, 0x4300, {0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23} }
|
||||
+
|
||||
+struct grub_efi_shim_lock
|
||||
+{
|
||||
+ grub_efi_status_t (*verify) (void *buffer, grub_uint32_t size);
|
||||
+};
|
||||
+typedef struct grub_efi_shim_lock grub_efi_shim_lock_t;
|
||||
+
|
||||
+grub_efi_boolean_t
|
||||
+grub_linuxefi_secure_validate (void *data, grub_uint32_t size)
|
||||
+{
|
||||
+ grub_efi_guid_t guid = SHIM_LOCK_GUID;
|
||||
+ grub_efi_shim_lock_t *shim_lock;
|
||||
+
|
||||
+ shim_lock = grub_efi_locate_protocol(&guid, NULL);
|
||||
+
|
||||
+ if (!shim_lock)
|
||||
+ return 1;
|
||||
+
|
||||
+ if (shim_lock->verify(data, size) == GRUB_EFI_SUCCESS)
|
||||
+ return 1;
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+#pragma GCC diagnostic push
|
||||
+#pragma GCC diagnostic ignored "-Wcast-align"
|
||||
+
|
||||
+typedef void (*handover_func) (void *, grub_efi_system_table_t *, void *);
|
||||
+
|
||||
+grub_err_t
|
||||
+grub_efi_linux_boot (void *kernel_addr, grub_off_t offset,
|
||||
+ void *kernel_params)
|
||||
+{
|
||||
+ handover_func hf;
|
||||
+
|
||||
+ hf = (handover_func)((char *)kernel_addr + offset);
|
||||
+ hf (grub_efi_image_handle, grub_efi_system_table, kernel_params);
|
||||
+
|
||||
+ return GRUB_ERR_BUG;
|
||||
+}
|
||||
+
|
||||
+#pragma GCC diagnostic pop
|
||||
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
|
||||
new file mode 100644
|
||||
index 00000000000..bb2616a8092
|
||||
--- /dev/null
|
||||
+++ b/grub-core/loader/i386/efi/linux.c
|
||||
@@ -0,0 +1,335 @@
|
||||
+/*
|
||||
+ * GRUB -- GRand Unified Bootloader
|
||||
+ * Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
+ *
|
||||
+ * GRUB 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 3 of the License, or
|
||||
+ * (at your option) any later version.
|
||||
+ *
|
||||
+ * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
+ */
|
||||
+
|
||||
+#include <grub/loader.h>
|
||||
+#include <grub/file.h>
|
||||
+#include <grub/err.h>
|
||||
+#include <grub/types.h>
|
||||
+#include <grub/mm.h>
|
||||
+#include <grub/cpu/linux.h>
|
||||
+#include <grub/command.h>
|
||||
+#include <grub/i18n.h>
|
||||
+#include <grub/lib/cmdline.h>
|
||||
+#include <grub/efi/efi.h>
|
||||
+#include <grub/efi/linux.h>
|
||||
+
|
||||
+GRUB_MOD_LICENSE ("GPLv3+");
|
||||
+
|
||||
+static grub_dl_t my_mod;
|
||||
+static int loaded;
|
||||
+static void *kernel_mem;
|
||||
+static grub_uint64_t kernel_size;
|
||||
+static grub_uint8_t *initrd_mem;
|
||||
+static grub_uint32_t handover_offset;
|
||||
+struct linux_kernel_params *params;
|
||||
+static char *linux_cmdline;
|
||||
+
|
||||
+#define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12)
|
||||
+
|
||||
+static grub_err_t
|
||||
+grub_linuxefi_boot (void)
|
||||
+{
|
||||
+ int offset = 0;
|
||||
+
|
||||
+#ifdef __x86_64__
|
||||
+ offset = 512;
|
||||
+#endif
|
||||
+ asm volatile ("cli");
|
||||
+
|
||||
+ return grub_efi_linux_boot ((char *)kernel_mem, handover_offset + offset,
|
||||
+ params);
|
||||
+}
|
||||
+
|
||||
+static grub_err_t
|
||||
+grub_linuxefi_unload (void)
|
||||
+{
|
||||
+ grub_dl_unref (my_mod);
|
||||
+ loaded = 0;
|
||||
+ if (initrd_mem)
|
||||
+ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)initrd_mem,
|
||||
+ BYTES_TO_PAGES(params->ramdisk_size));
|
||||
+ if (linux_cmdline)
|
||||
+ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)
|
||||
+ linux_cmdline,
|
||||
+ BYTES_TO_PAGES(params->cmdline_size + 1));
|
||||
+ if (kernel_mem)
|
||||
+ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem,
|
||||
+ BYTES_TO_PAGES(kernel_size));
|
||||
+ if (params)
|
||||
+ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params,
|
||||
+ BYTES_TO_PAGES(16384));
|
||||
+ return GRUB_ERR_NONE;
|
||||
+}
|
||||
+
|
||||
+static grub_err_t
|
||||
+grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
+ int argc, char *argv[])
|
||||
+{
|
||||
+ grub_file_t *files = 0;
|
||||
+ int i, nfiles = 0;
|
||||
+ grub_size_t size = 0;
|
||||
+ grub_uint8_t *ptr;
|
||||
+
|
||||
+ if (argc == 0)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ if (!loaded)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_BAD_ARGUMENT, N_("you need to load the kernel first"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ files = grub_zalloc (argc * sizeof (files[0]));
|
||||
+ if (!files)
|
||||
+ goto fail;
|
||||
+
|
||||
+ for (i = 0; i < argc; i++)
|
||||
+ {
|
||||
+ files[i] = grub_file_open (argv[i], GRUB_FILE_TYPE_LINUX_INITRD | GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
+ if (! files[i])
|
||||
+ goto fail;
|
||||
+ nfiles++;
|
||||
+ size += ALIGN_UP (grub_file_size (files[i]), 4);
|
||||
+ }
|
||||
+
|
||||
+ initrd_mem = grub_efi_allocate_pages_max (0x3fffffff, BYTES_TO_PAGES(size));
|
||||
+ if (!initrd_mem)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate initrd"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ params->ramdisk_size = size;
|
||||
+ params->ramdisk_image = (grub_uint32_t)(grub_addr_t) initrd_mem;
|
||||
+
|
||||
+ ptr = initrd_mem;
|
||||
+
|
||||
+ for (i = 0; i < nfiles; i++)
|
||||
+ {
|
||||
+ grub_ssize_t cursize = grub_file_size (files[i]);
|
||||
+ if (grub_file_read (files[i], ptr, cursize) != cursize)
|
||||
+ {
|
||||
+ if (!grub_errno)
|
||||
+ grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
|
||||
+ argv[i]);
|
||||
+ goto fail;
|
||||
+ }
|
||||
+ ptr += cursize;
|
||||
+ grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4));
|
||||
+ ptr += ALIGN_UP_OVERHEAD (cursize, 4);
|
||||
+ }
|
||||
+
|
||||
+ params->ramdisk_size = size;
|
||||
+
|
||||
+ fail:
|
||||
+ for (i = 0; i < nfiles; i++)
|
||||
+ grub_file_close (files[i]);
|
||||
+ grub_free (files);
|
||||
+
|
||||
+ if (initrd_mem && grub_errno)
|
||||
+ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)initrd_mem,
|
||||
+ BYTES_TO_PAGES(size));
|
||||
+
|
||||
+ return grub_errno;
|
||||
+}
|
||||
+
|
||||
+static grub_err_t
|
||||
+grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
+ int argc, char *argv[])
|
||||
+{
|
||||
+ grub_file_t file = 0;
|
||||
+ struct linux_i386_kernel_header lh;
|
||||
+ grub_ssize_t len, start, filelen;
|
||||
+ void *kernel = NULL;
|
||||
+
|
||||
+ grub_dl_ref (my_mod);
|
||||
+
|
||||
+ if (argc == 0)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
|
||||
+ if (! file)
|
||||
+ goto fail;
|
||||
+
|
||||
+ filelen = grub_file_size (file);
|
||||
+
|
||||
+ kernel = grub_malloc(filelen);
|
||||
+
|
||||
+ if (!kernel)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel buffer"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ if (grub_file_read (file, kernel, filelen) != filelen)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_FILE_READ_ERROR, N_("Can't read kernel %s"), argv[0]);
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ if (! grub_linuxefi_secure_validate (kernel, filelen))
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"),
|
||||
+ argv[0]);
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ params = grub_efi_allocate_pages_max (0x3fffffff, BYTES_TO_PAGES(16384));
|
||||
+
|
||||
+ if (! params)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters");
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ grub_memset (params, 0, 16384);
|
||||
+
|
||||
+ grub_memcpy (&lh, kernel, sizeof (lh));
|
||||
+
|
||||
+ if (lh.boot_flag != grub_cpu_to_le16 (0xaa55))
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_BAD_OS, N_("invalid magic number"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ if (lh.setup_sects > GRUB_LINUX_MAX_SETUP_SECTS)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_BAD_OS, N_("too many setup sectors"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ if (lh.version < grub_cpu_to_le16 (0x020b))
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_BAD_OS, N_("kernel too old"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ if (!lh.handover_offset)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_BAD_OS, N_("kernel doesn't support EFI handover"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ grub_dprintf ("linux", "setting up cmdline\n");
|
||||
+ linux_cmdline = grub_efi_allocate_pages_max(0x3fffffff,
|
||||
+ BYTES_TO_PAGES(lh.cmdline_size + 1));
|
||||
+
|
||||
+ if (!linux_cmdline)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate cmdline"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
+ grub_create_loader_cmdline (argc, argv,
|
||||
+ linux_cmdline + sizeof (LINUX_IMAGE) - 1,
|
||||
+ lh.cmdline_size - (sizeof (LINUX_IMAGE) - 1),
|
||||
+ GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
+
|
||||
+ lh.cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline;
|
||||
+
|
||||
+ handover_offset = lh.handover_offset;
|
||||
+
|
||||
+ start = (lh.setup_sects + 1) * 512;
|
||||
+ len = grub_file_size(file) - start;
|
||||
+
|
||||
+ kernel_mem = grub_efi_allocate_pages_max(lh.pref_address,
|
||||
+ BYTES_TO_PAGES(lh.init_size));
|
||||
+
|
||||
+ if (!kernel_mem)
|
||||
+ kernel_mem = grub_efi_allocate_pages_max(0x3fffffff,
|
||||
+ BYTES_TO_PAGES(lh.init_size));
|
||||
+
|
||||
+ if (!kernel_mem)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate kernel"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ grub_memcpy (kernel_mem, (char *)kernel + start, len);
|
||||
+ grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0);
|
||||
+ loaded=1;
|
||||
+
|
||||
+ lh.code32_start = (grub_uint32_t)(grub_uint64_t) kernel_mem;
|
||||
+ grub_memcpy (params, &lh, 2 * 512);
|
||||
+
|
||||
+ params->type_of_loader = 0x21;
|
||||
+
|
||||
+ fail:
|
||||
+
|
||||
+ if (file)
|
||||
+ grub_file_close (file);
|
||||
+
|
||||
+ if (kernel)
|
||||
+ grub_free (kernel);
|
||||
+
|
||||
+ if (grub_errno != GRUB_ERR_NONE)
|
||||
+ {
|
||||
+ grub_dl_unref (my_mod);
|
||||
+ loaded = 0;
|
||||
+ }
|
||||
+
|
||||
+ if (linux_cmdline && !loaded)
|
||||
+ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)
|
||||
+ linux_cmdline,
|
||||
+ BYTES_TO_PAGES(lh.cmdline_size + 1));
|
||||
+
|
||||
+ if (kernel_mem && !loaded)
|
||||
+ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem,
|
||||
+ BYTES_TO_PAGES(kernel_size));
|
||||
+
|
||||
+ if (params && !loaded)
|
||||
+ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params,
|
||||
+ BYTES_TO_PAGES(16384));
|
||||
+
|
||||
+ return grub_errno;
|
||||
+}
|
||||
+
|
||||
+static grub_command_t cmd_linux, cmd_initrd;
|
||||
+static grub_command_t cmd_linuxefi, cmd_initrdefi;
|
||||
+
|
||||
+GRUB_MOD_INIT(linux)
|
||||
+{
|
||||
+ cmd_linux =
|
||||
+ grub_register_command ("linux", grub_cmd_linux,
|
||||
+ 0, N_("Load Linux."));
|
||||
+ cmd_linuxefi =
|
||||
+ grub_register_command ("linuxefi", grub_cmd_linux,
|
||||
+ 0, N_("Load Linux."));
|
||||
+ cmd_initrd =
|
||||
+ grub_register_command ("initrd", grub_cmd_initrd,
|
||||
+ 0, N_("Load initrd."));
|
||||
+ cmd_initrdefi =
|
||||
+ grub_register_command ("initrdefi", grub_cmd_initrd,
|
||||
+ 0, N_("Load initrd."));
|
||||
+ my_mod = mod;
|
||||
+}
|
||||
+
|
||||
+GRUB_MOD_FINI(linux)
|
||||
+{
|
||||
+ grub_unregister_command (cmd_linux);
|
||||
+ grub_unregister_command (cmd_linuxefi);
|
||||
+ grub_unregister_command (cmd_initrd);
|
||||
+ grub_unregister_command (cmd_initrdefi);
|
||||
+}
|
||||
diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c
|
||||
index 2a299520160..8be4c3b3f48 100644
|
||||
--- a/grub-core/loader/i386/pc/linux.c
|
||||
+++ b/grub-core/loader/i386/pc/linux.c
|
||||
@@ -474,14 +474,20 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
-static grub_command_t cmd_linux, cmd_initrd;
|
||||
+static grub_command_t cmd_linux, cmd_linux16, cmd_initrd, cmd_initrd16;
|
||||
|
||||
GRUB_MOD_INIT(linux16)
|
||||
{
|
||||
cmd_linux =
|
||||
+ grub_register_command ("linux", grub_cmd_linux,
|
||||
+ 0, N_("Load Linux."));
|
||||
+ cmd_linux16 =
|
||||
grub_register_command ("linux16", grub_cmd_linux,
|
||||
0, N_("Load Linux."));
|
||||
cmd_initrd =
|
||||
+ grub_register_command ("initrd", grub_cmd_initrd,
|
||||
+ 0, N_("Load initrd."));
|
||||
+ cmd_initrd16 =
|
||||
grub_register_command ("initrd16", grub_cmd_initrd,
|
||||
0, N_("Load initrd."));
|
||||
my_mod = mod;
|
||||
@@ -490,5 +496,7 @@ GRUB_MOD_INIT(linux16)
|
||||
GRUB_MOD_FINI(linux16)
|
||||
{
|
||||
grub_unregister_command (cmd_linux);
|
||||
+ grub_unregister_command (cmd_linux16);
|
||||
grub_unregister_command (cmd_initrd);
|
||||
+ grub_unregister_command (cmd_initrd16);
|
||||
}
|
||||
diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h
|
||||
index bcd5a7eb186..b582f67f661 100644
|
||||
--- a/include/grub/arm/linux.h
|
||||
+++ b/include/grub/arm/linux.h
|
||||
@@ -20,6 +20,7 @@
|
||||
#ifndef GRUB_ARM_LINUX_HEADER
|
||||
#define GRUB_ARM_LINUX_HEADER 1
|
||||
|
||||
+#include <grub/efi/pe32.h>
|
||||
#include "system.h"
|
||||
|
||||
#define GRUB_LINUX_ARM_MAGIC_SIGNATURE 0x016f2818
|
||||
@@ -34,9 +35,17 @@ struct linux_arm_kernel_header {
|
||||
grub_uint32_t hdr_offset;
|
||||
};
|
||||
|
||||
+struct grub_arm_linux_pe_header
|
||||
+{
|
||||
+ grub_uint32_t magic;
|
||||
+ struct grub_pe32_coff_header coff;
|
||||
+ struct grub_pe32_optional_header opt;
|
||||
+};
|
||||
+
|
||||
#if defined(__arm__)
|
||||
# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE
|
||||
# define linux_arch_kernel_header linux_arm_kernel_header
|
||||
+# define grub_armxx_linux_pe_header grub_arm_linux_pe_header
|
||||
#endif
|
||||
|
||||
#if defined GRUB_MACHINE_UBOOT
|
||||
diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h
|
||||
index 7e22b4ab699..ea030312df3 100644
|
||||
--- a/include/grub/arm64/linux.h
|
||||
+++ b/include/grub/arm64/linux.h
|
||||
@@ -19,6 +19,7 @@
|
||||
#ifndef GRUB_ARM64_LINUX_HEADER
|
||||
#define GRUB_ARM64_LINUX_HEADER 1
|
||||
|
||||
+#include <grub/efi/pe32.h>
|
||||
#include <grub/types.h>
|
||||
|
||||
#define GRUB_LINUX_ARM64_MAGIC_SIGNATURE 0x644d5241 /* 'ARM\x64' */
|
||||
@@ -38,9 +39,17 @@ struct linux_arm64_kernel_header
|
||||
grub_uint32_t hdr_offset; /* Offset of PE/COFF header */
|
||||
};
|
||||
|
||||
+struct grub_arm64_linux_pe_header
|
||||
+{
|
||||
+ grub_uint32_t magic;
|
||||
+ struct grub_pe32_coff_header coff;
|
||||
+ struct grub_pe64_optional_header opt;
|
||||
+};
|
||||
+
|
||||
#if defined(__aarch64__)
|
||||
# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE
|
||||
# define linux_arch_kernel_header linux_arm64_kernel_header
|
||||
+# define grub_armxx_linux_pe_header grub_arm64_linux_pe_header
|
||||
#endif
|
||||
|
||||
#endif /* ! GRUB_ARM64_LINUX_HEADER */
|
||||
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
|
||||
index 83d958f9945..6295df85f3f 100644
|
||||
--- a/include/grub/efi/efi.h
|
||||
+++ b/include/grub/efi/efi.h
|
||||
@@ -47,6 +47,9 @@ EXPORT_FUNC(grub_efi_allocate_fixed) (grub_efi_physical_address_t address,
|
||||
grub_efi_uintn_t pages);
|
||||
void *
|
||||
EXPORT_FUNC(grub_efi_allocate_any_pages) (grub_efi_uintn_t pages);
|
||||
+void *
|
||||
+EXPORT_FUNC(grub_efi_allocate_pages_max) (grub_efi_physical_address_t max,
|
||||
+ grub_efi_uintn_t pages);
|
||||
void EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address,
|
||||
grub_efi_uintn_t pages);
|
||||
grub_efi_uintn_t EXPORT_FUNC(grub_efi_find_mmap_size) (void);
|
||||
@@ -88,6 +91,7 @@ EXPORT_FUNC (grub_efi_set_variable) (const char *var,
|
||||
const grub_efi_guid_t *guid,
|
||||
void *data,
|
||||
grub_size_t datasize);
|
||||
+grub_efi_boolean_t EXPORT_FUNC (grub_efi_secure_boot) (void);
|
||||
int
|
||||
EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1,
|
||||
const grub_efi_device_path_t *dp2);
|
||||
@@ -101,8 +105,7 @@ void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void);
|
||||
grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *);
|
||||
#include <grub/cpu/linux.h>
|
||||
grub_err_t grub_arch_efi_linux_check_image(struct linux_arch_kernel_header *lh);
|
||||
-grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, grub_size_t size,
|
||||
- char *args);
|
||||
+grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, char *args);
|
||||
#endif
|
||||
|
||||
grub_addr_t grub_efi_modules_addr (void);
|
||||
diff --git a/include/grub/efi/linux.h b/include/grub/efi/linux.h
|
||||
new file mode 100644
|
||||
index 00000000000..d9ede36773b
|
||||
--- /dev/null
|
||||
+++ b/include/grub/efi/linux.h
|
||||
@@ -0,0 +1,31 @@
|
||||
+/*
|
||||
+ * GRUB -- GRand Unified Bootloader
|
||||
+ * Copyright (C) 2014 Free Software Foundation, Inc.
|
||||
+ *
|
||||
+ * GRUB 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 3 of the License, or
|
||||
+ * (at your option) any later version.
|
||||
+ *
|
||||
+ * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
+ */
|
||||
+#ifndef GRUB_EFI_LINUX_HEADER
|
||||
+#define GRUB_EFI_LINUX_HEADER 1
|
||||
+
|
||||
+#include <grub/efi/api.h>
|
||||
+#include <grub/err.h>
|
||||
+#include <grub/symbol.h>
|
||||
+
|
||||
+grub_efi_boolean_t
|
||||
+EXPORT_FUNC(grub_linuxefi_secure_validate) (void *data, grub_uint32_t size);
|
||||
+grub_err_t
|
||||
+EXPORT_FUNC(grub_efi_linux_boot) (void *kernel_address, grub_off_t offset,
|
||||
+ void *kernel_param);
|
||||
+
|
||||
+#endif /* ! GRUB_EFI_LINUX_HEADER */
|
||||
279
0004-Introduce-prep_load_env-command.patch
Normal file
279
0004-Introduce-prep_load_env-command.patch
Normal file
@ -0,0 +1,279 @@
|
||||
From 3cf4fdf8d17423dea4e5913ab14fb6305f3c2571 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Fri, 18 Feb 2022 21:43:38 +0800
|
||||
Subject: [PATCH 4/5] Introduce prep_load_env command
|
||||
|
||||
This command will accept grub disk device and perform load_env for
|
||||
environment block located at end of PReP partition which belongs to that
|
||||
input disk device. All variables read from that environment block are
|
||||
exported to grub as environment variables.
|
||||
|
||||
Please note there's no support for whitelist variables and also
|
||||
--skip-sig option compared to ordinary load_env command.
|
||||
|
||||
v2:
|
||||
To avoid disrupting the boot process with errors, it's important to log
|
||||
any errors that may occur and always return GRUB_ERR_NONE.
|
||||
|
||||
v3:
|
||||
Making the new module powerpc_ieee1275 specific.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/Makefile.core.def | 5 +
|
||||
grub-core/commands/prep_loadenv.c | 227 ++++++++++++++++++++++++++++++
|
||||
2 files changed, 232 insertions(+)
|
||||
create mode 100644 grub-core/commands/prep_loadenv.c
|
||||
|
||||
--- a/grub-core/Makefile.core.def
|
||||
+++ b/grub-core/Makefile.core.def
|
||||
@@ -2679,3 +2679,9 @@
|
||||
common = lib/libtasn1_wrap/tests/Test_strings.c;
|
||||
common = lib/libtasn1_wrap/wrap_tests.c;
|
||||
};
|
||||
+
|
||||
+module = {
|
||||
+ name = prep_loadenv;
|
||||
+ common = commands/prep_loadenv.c;
|
||||
+ enable = powerpc_ieee1275;
|
||||
+};
|
||||
--- /dev/null
|
||||
+++ b/grub-core/commands/prep_loadenv.c
|
||||
@@ -0,0 +1,237 @@
|
||||
+#include <grub/dl.h>
|
||||
+#include <grub/mm.h>
|
||||
+#include <grub/file.h>
|
||||
+#include <grub/disk.h>
|
||||
+#include <grub/misc.h>
|
||||
+#include <grub/err.h>
|
||||
+#include <grub/env.h>
|
||||
+#include <grub/partition.h>
|
||||
+#include <grub/lib/envblk.h>
|
||||
+#include <grub/extcmd.h>
|
||||
+#include <grub/i18n.h>
|
||||
+#include <grub/gpt_partition.h>
|
||||
+
|
||||
+GRUB_MOD_LICENSE ("GPLv3+");
|
||||
+
|
||||
+static char *
|
||||
+match_substr (regmatch_t *match, const char *str)
|
||||
+{
|
||||
+ if (match->rm_so != -1)
|
||||
+ {
|
||||
+ char *substr;
|
||||
+ regoff_t sz = match->rm_eo - match->rm_so;
|
||||
+
|
||||
+ if (!sz)
|
||||
+ return NULL;
|
||||
+ substr = grub_malloc (1 + sz);
|
||||
+ if (!substr)
|
||||
+ {
|
||||
+ grub_print_error ();
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ grub_memcpy (substr, str + match->rm_so, sz);
|
||||
+ substr[sz] = '\0';
|
||||
+ return substr;
|
||||
+ }
|
||||
+
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
+static int
|
||||
+is_prep_partition (grub_device_t dev)
|
||||
+{
|
||||
+ if (!dev->disk)
|
||||
+ return 0;
|
||||
+ if (!dev->disk->partition)
|
||||
+ return 0;
|
||||
+ if (grub_strcmp (dev->disk->partition->partmap->name, "msdos") == 0)
|
||||
+ return (dev->disk->partition->msdostype == 0x41);
|
||||
+
|
||||
+ if (grub_strcmp (dev->disk->partition->partmap->name, "gpt") == 0)
|
||||
+ {
|
||||
+ struct grub_gpt_partentry gptdata;
|
||||
+ grub_partition_t p = dev->disk->partition;
|
||||
+ int ret = 0;
|
||||
+ dev->disk->partition = dev->disk->partition->parent;
|
||||
+
|
||||
+ if (grub_disk_read (dev->disk, p->offset, p->index,
|
||||
+ sizeof (gptdata), &gptdata) == 0)
|
||||
+ {
|
||||
+ const grub_guid_t template = {
|
||||
+ grub_cpu_to_le32_compile_time (0x9e1a2d38),
|
||||
+ grub_cpu_to_le16_compile_time (0xc612),
|
||||
+ grub_cpu_to_le16_compile_time (0x4316),
|
||||
+ { 0xaa, 0x26, 0x8b, 0x49, 0x52, 0x1e, 0x5a, 0x8b }
|
||||
+ };
|
||||
+
|
||||
+ ret = grub_memcmp (&template, &gptdata.type,
|
||||
+ sizeof (template)) == 0;
|
||||
+ }
|
||||
+ dev->disk->partition = p;
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int
|
||||
+part_hook (grub_disk_t disk, const grub_partition_t partition, void *data)
|
||||
+{
|
||||
+ char **ret = data;
|
||||
+ char *partition_name, *devname;
|
||||
+ grub_device_t dev;
|
||||
+
|
||||
+ partition_name = grub_partition_get_name (partition);
|
||||
+ if (! partition_name)
|
||||
+ return 2;
|
||||
+
|
||||
+ devname = grub_xasprintf ("%s,%s", disk->name, partition_name);
|
||||
+ grub_free (partition_name);
|
||||
+ if (!devname)
|
||||
+ return 2;
|
||||
+
|
||||
+ dev = grub_device_open (devname);
|
||||
+ if (!dev)
|
||||
+ {
|
||||
+ grub_free (devname);
|
||||
+ return 2;
|
||||
+ }
|
||||
+ if (is_prep_partition (dev))
|
||||
+ {
|
||||
+ *ret = devname;
|
||||
+ return 1;
|
||||
+ }
|
||||
+ grub_free (devname);
|
||||
+ grub_device_close (dev);
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int
|
||||
+set_var (const char *name, const char *value,
|
||||
+ void *hook_data __attribute__ ((unused)))
|
||||
+{
|
||||
+ grub_env_set (name, value);
|
||||
+ grub_env_export (name);
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static grub_err_t
|
||||
+prep_read_envblk (const char *devname)
|
||||
+{
|
||||
+ char *buf = NULL;
|
||||
+ grub_device_t dev = NULL;
|
||||
+ grub_envblk_t envblk = NULL;
|
||||
+
|
||||
+ dev = grub_device_open (devname);
|
||||
+ if (!dev)
|
||||
+ return grub_errno;
|
||||
+
|
||||
+ if (!dev->disk || !dev->disk->partition)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_BAD_DEVICE, "disk device required");
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ buf = grub_malloc (GRUB_ENVBLK_PREP_SIZE);
|
||||
+ if (!buf)
|
||||
+ goto fail;
|
||||
+
|
||||
+ if (grub_disk_read (dev->disk, dev->disk->partition->len - (GRUB_ENVBLK_PREP_SIZE >> GRUB_DISK_SECTOR_BITS), 0, GRUB_ENVBLK_PREP_SIZE, buf))
|
||||
+ goto fail;
|
||||
+
|
||||
+ envblk = grub_envblk_open (buf, GRUB_ENVBLK_PREP_SIZE);
|
||||
+ if (!envblk)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid environment block");
|
||||
+ goto fail;
|
||||
+ }
|
||||
+ grub_envblk_iterate (envblk, NULL, set_var);
|
||||
+
|
||||
+ fail:
|
||||
+ if (envblk)
|
||||
+ grub_envblk_close (envblk);
|
||||
+ else
|
||||
+ grub_free (buf);
|
||||
+ if (dev)
|
||||
+ grub_device_close (dev);
|
||||
+ return grub_errno;
|
||||
+}
|
||||
+
|
||||
+static grub_err_t
|
||||
+prep_partname (const char *devname, char **prep)
|
||||
+{
|
||||
+ grub_device_t dev = NULL;
|
||||
+ grub_err_t err;
|
||||
+ int ret;
|
||||
+
|
||||
+ dev = grub_device_open (devname);
|
||||
+ if (!dev)
|
||||
+ return grub_errno;
|
||||
+
|
||||
+ /* Only needed for disk device */
|
||||
+ if (!dev->disk)
|
||||
+ {
|
||||
+ err = GRUB_ERR_NONE;
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ ret = grub_partition_iterate (dev->disk, part_hook, prep);
|
||||
+ if (ret == 1 && *prep)
|
||||
+ {
|
||||
+ err = GRUB_ERR_NONE;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ else if (ret == 0 && grub_errno == GRUB_ERR_NONE)
|
||||
+ err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "no prep partition");
|
||||
+ else
|
||||
+ err = grub_errno;
|
||||
+
|
||||
+ out:
|
||||
+ grub_device_close (dev);
|
||||
+ return err;
|
||||
+}
|
||||
+
|
||||
+static grub_err_t
|
||||
+grub_cmd_prep_loadenv (grub_command_t cmd __attribute__ ((unused)),
|
||||
+ int argc,
|
||||
+ char **argv)
|
||||
+{
|
||||
+ char *devname, *prep = NULL;
|
||||
+ grub_err_t err;
|
||||
+
|
||||
+ if (argc < 1)
|
||||
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
|
||||
+
|
||||
+ devname = grub_file_get_device_name(argv[0]);
|
||||
+ if (!devname)
|
||||
+ return grub_errno;
|
||||
+
|
||||
+ err = prep_partname (devname, &prep);
|
||||
+ if (prep == NULL || err != GRUB_ERR_NONE)
|
||||
+ goto out;
|
||||
+
|
||||
+ err = prep_read_envblk (prep);
|
||||
+
|
||||
+ out:
|
||||
+ grub_free (devname);
|
||||
+ grub_free (prep);
|
||||
+
|
||||
+ if (err)
|
||||
+ grub_print_error ();
|
||||
+ return GRUB_ERR_NONE;
|
||||
+}
|
||||
+
|
||||
+static grub_command_t cmd_prep_load;
|
||||
+
|
||||
+GRUB_MOD_INIT(prep_loadenv)
|
||||
+{
|
||||
+ cmd_prep_load =
|
||||
+ grub_register_command("prep_load_env", grub_cmd_prep_loadenv,
|
||||
+ "DEVICE",
|
||||
+ N_("Load variables from environment block file."));
|
||||
+}
|
||||
+
|
||||
+GRUB_MOD_FINI(prep_loadenv)
|
||||
+{
|
||||
+ grub_unregister_command (cmd_prep_load);
|
||||
+}
|
||||
91
0004-Key-revocation-on-out-of-bound-file-access.patch
Normal file
91
0004-Key-revocation-on-out-of-bound-file-access.patch
Normal file
@ -0,0 +1,91 @@
|
||||
From 6547d22fc9e20720d1a896be82b2d50d842f86b0 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Mon, 20 Nov 2023 09:25:53 +0800
|
||||
Subject: [PATCH 4/4] Key revocation on out of bound file access
|
||||
|
||||
After successful disk unlocking, grub now takes on the responsibility of
|
||||
safeguarding passwords or TPM keys exclusively within authenticated
|
||||
cryptodisk files. Any attempt to access boot-related files outside this
|
||||
trust realm triggers immediate key revocation, preventing potential
|
||||
compromise by out of bound access.
|
||||
|
||||
This patch strengthens security measures by restricting grub's access to
|
||||
system boot files, except for essential internal processes like memdisk
|
||||
and procfs, ensuring key protection against potential breaches due to
|
||||
inadvertent customizations in grub.cfg.
|
||||
|
||||
Signed-Off-by Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/commands/crypttab.c | 36 +++++++++++++++++++++++++++++++++++
|
||||
include/grub/file.h | 1 +
|
||||
2 files changed, 37 insertions(+)
|
||||
|
||||
diff --git a/grub-core/commands/crypttab.c b/grub-core/commands/crypttab.c
|
||||
index d3acc4b59..e09296c57 100644
|
||||
--- a/grub-core/commands/crypttab.c
|
||||
+++ b/grub-core/commands/crypttab.c
|
||||
@@ -121,6 +121,41 @@ grub_cryptokey_tpmkey_discard (void)
|
||||
grub_cryptokey_discard();
|
||||
}
|
||||
|
||||
+static grub_file_t
|
||||
+grub_distrust_open (grub_file_t io,
|
||||
+ enum grub_file_type type __attribute__ ((unused)))
|
||||
+{
|
||||
+ grub_disk_t disk = io->device->disk;
|
||||
+
|
||||
+ if (io->device->disk &&
|
||||
+ (io->device->disk->dev->id == GRUB_DISK_DEVICE_MEMDISK_ID
|
||||
+ || io->device->disk->dev->id == GRUB_DISK_DEVICE_PROCFS_ID))
|
||||
+ return io;
|
||||
+
|
||||
+ /* Ensure second stage files is in a protected location or grub won't hand
|
||||
+ * over the key and discards it */
|
||||
+ switch (type & GRUB_FILE_TYPE_MASK)
|
||||
+ {
|
||||
+ case GRUB_FILE_TYPE_ACPI_TABLE:
|
||||
+ case GRUB_FILE_TYPE_CONFIG:
|
||||
+ case GRUB_FILE_TYPE_DEVICE_TREE_IMAGE:
|
||||
+ case GRUB_FILE_TYPE_FONT:
|
||||
+ case GRUB_FILE_TYPE_GRUB_MODULE:
|
||||
+ case GRUB_FILE_TYPE_GRUB_MODULE_LIST:
|
||||
+ case GRUB_FILE_TYPE_LINUX_KERNEL:
|
||||
+ case GRUB_FILE_TYPE_LINUX_INITRD:
|
||||
+ case GRUB_FILE_TYPE_LOADENV:
|
||||
+ case GRUB_FILE_TYPE_THEME:
|
||||
+ if (!disk || !grub_disk_is_crypto (disk))
|
||||
+ grub_cryptokey_discard ();
|
||||
+ break;
|
||||
+ default:
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ return io;
|
||||
+}
|
||||
+
|
||||
static grub_err_t
|
||||
grub_cmd_crypttab_entry (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char **argv)
|
||||
@@ -153,6 +188,7 @@ GRUB_MOD_INIT(crypttab)
|
||||
{
|
||||
cmd = grub_register_command ("crypttab_entry", grub_cmd_crypttab_entry,
|
||||
N_("VOLUME-NAME ENCRYPTED-DEVICE KEY-FILE") , N_("No description"));
|
||||
+ grub_file_filter_register (GRUB_FILE_FILTER_DISTRUST, grub_distrust_open);
|
||||
grub_dl_set_persistent (mod);
|
||||
}
|
||||
|
||||
diff --git a/include/grub/file.h b/include/grub/file.h
|
||||
index fcfd32ce2..daf23a9c9 100644
|
||||
--- a/include/grub/file.h
|
||||
+++ b/include/grub/file.h
|
||||
@@ -185,6 +185,7 @@ extern grub_disk_read_hook_t EXPORT_VAR(grub_file_progress_hook);
|
||||
/* Filters with lower ID are executed first. */
|
||||
typedef enum grub_file_filter_id
|
||||
{
|
||||
+ GRUB_FILE_FILTER_DISTRUST,
|
||||
GRUB_FILE_FILTER_NOCAT,
|
||||
GRUB_FILE_FILTER_VERIFY,
|
||||
GRUB_FILE_FILTER_GZIO,
|
||||
--
|
||||
2.42.1
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From 384763d7990f769839ca74d6756fbd85580873d4 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Jones <pjones@redhat.com>
|
||||
Date: Thu, 11 Jul 2019 17:17:02 +0200
|
||||
Subject: [PATCH] Try to pick better locations for kernel and initrd
|
||||
Subject: [PATCH 04/11] Try to pick better locations for kernel and initrd
|
||||
|
||||
- Don't limit allocations on 64-bit platforms to < 0x[37f]fffffff if
|
||||
we're using the "large" code model ; use __UINTPTR_MAX__.
|
||||
@ -23,25 +23,19 @@ Additionally, we now try to locate kernel+initrd+cmdline+etc below
|
||||
we try a higher address.
|
||||
|
||||
Signed-off-by: Peter Jones <pjones@redhat.com>
|
||||
[david.abdurachmanov: fix macro for riscv64]
|
||||
Signed-off-by: David Abdurachmanov <david.abdurachmanov@sifive.com>
|
||||
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
|
||||
---
|
||||
grub-core/kern/efi/mm.c | 8 ++++----
|
||||
grub-core/loader/i386/efi/linux.c | 24 +++++++++++++++++-------
|
||||
grub-core/loader/i386/efi/linux.c | 25 +++++++++++++++++--------
|
||||
include/grub/arm/efi/memory.h | 1 +
|
||||
include/grub/arm64/efi/memory.h | 1 +
|
||||
include/grub/i386/efi/memory.h | 1 +
|
||||
include/grub/ia64/efi/memory.h | 1 +
|
||||
include/grub/riscv64/efi/memory.h | 1 +
|
||||
include/grub/x86_64/efi/memory.h | 4 +++-
|
||||
8 files changed, 29 insertions(+), 12 deletions(-)
|
||||
7 files changed, 28 insertions(+), 13 deletions(-)
|
||||
|
||||
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
|
||||
index 85ad4b4494c..e84961d078c 100644
|
||||
--- a/grub-core/kern/efi/mm.c
|
||||
+++ b/grub-core/kern/efi/mm.c
|
||||
@@ -122,7 +122,7 @@ grub_efi_allocate_pages_max (grub_efi_physical_address_t max,
|
||||
@@ -121,7 +121,7 @@
|
||||
grub_efi_boot_services_t *b;
|
||||
grub_efi_physical_address_t address = max;
|
||||
|
||||
@ -50,7 +44,7 @@ index 85ad4b4494c..e84961d078c 100644
|
||||
return 0;
|
||||
|
||||
b = grub_efi_system_table->boot_services;
|
||||
@@ -480,7 +480,7 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map,
|
||||
@@ -481,7 +481,7 @@
|
||||
{
|
||||
if (desc->type == GRUB_EFI_CONVENTIONAL_MEMORY
|
||||
#if 1
|
||||
@ -59,7 +53,7 @@ index 85ad4b4494c..e84961d078c 100644
|
||||
#endif
|
||||
&& desc->physical_start + PAGES_TO_BYTES (desc->num_pages) > 0x100000
|
||||
&& desc->num_pages != 0)
|
||||
@@ -498,9 +498,9 @@ filter_memory_map (grub_efi_memory_descriptor_t *memory_map,
|
||||
@@ -499,9 +499,9 @@
|
||||
#if 1
|
||||
if (BYTES_TO_PAGES (filtered_desc->physical_start)
|
||||
+ filtered_desc->num_pages
|
||||
@ -71,8 +65,6 @@ index 85ad4b4494c..e84961d078c 100644
|
||||
- BYTES_TO_PAGES (filtered_desc->physical_start));
|
||||
#endif
|
||||
|
||||
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
|
||||
index 3017d0f3e52..33e981e76e7 100644
|
||||
--- a/grub-core/loader/i386/efi/linux.c
|
||||
+++ b/grub-core/loader/i386/efi/linux.c
|
||||
@@ -27,6 +27,7 @@
|
||||
@ -83,18 +75,19 @@ index 3017d0f3e52..33e981e76e7 100644
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -106,7 +107,9 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -102,8 +103,9 @@
|
||||
size += ALIGN_UP (grub_file_size (files[i]), 4);
|
||||
}
|
||||
|
||||
- initrd_mem = grub_efi_allocate_pages_max (0x3fffffff, BYTES_TO_PAGES(size));
|
||||
-
|
||||
+ initrd_mem = grub_efi_allocate_pages_max (GRUB_EFI_MAX_ALLOCATION_ADDRESS, BYTES_TO_PAGES(size));
|
||||
+ if (!initrd_mem)
|
||||
+ initrd_mem = grub_efi_allocate_pages_max (GRUB_EFI_MAX_USABLE_ADDRESS, BYTES_TO_PAGES(size));
|
||||
if (!initrd_mem)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate initrd"));
|
||||
@@ -202,8 +205,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -187,8 +189,11 @@
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -107,7 +100,7 @@ index 3017d0f3e52..33e981e76e7 100644
|
||||
if (! params)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters");
|
||||
@@ -273,8 +279,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -258,8 +263,11 @@
|
||||
#endif
|
||||
|
||||
grub_dprintf ("linux", "setting up cmdline\n");
|
||||
@ -121,7 +114,7 @@ index 3017d0f3e52..33e981e76e7 100644
|
||||
if (!linux_cmdline)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate cmdline"));
|
||||
@@ -301,11 +310,12 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -285,11 +293,12 @@
|
||||
|
||||
kernel_mem = grub_efi_allocate_pages_max(lh->pref_address,
|
||||
BYTES_TO_PAGES(lh->init_size));
|
||||
@ -137,8 +130,6 @@ index 3017d0f3e52..33e981e76e7 100644
|
||||
if (!kernel_mem)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate kernel"));
|
||||
diff --git a/include/grub/arm/efi/memory.h b/include/grub/arm/efi/memory.h
|
||||
index 2c64918e3f7..a4c2ec83502 100644
|
||||
--- a/include/grub/arm/efi/memory.h
|
||||
+++ b/include/grub/arm/efi/memory.h
|
||||
@@ -2,5 +2,6 @@
|
||||
@ -148,8 +139,6 @@ index 2c64918e3f7..a4c2ec83502 100644
|
||||
+#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS
|
||||
|
||||
#endif /* ! GRUB_MEMORY_CPU_HEADER */
|
||||
diff --git a/include/grub/arm64/efi/memory.h b/include/grub/arm64/efi/memory.h
|
||||
index c6cb3241714..acb61dca44b 100644
|
||||
--- a/include/grub/arm64/efi/memory.h
|
||||
+++ b/include/grub/arm64/efi/memory.h
|
||||
@@ -2,5 +2,6 @@
|
||||
@ -159,8 +148,6 @@ index c6cb3241714..acb61dca44b 100644
|
||||
+#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS
|
||||
|
||||
#endif /* ! GRUB_MEMORY_CPU_HEADER */
|
||||
diff --git a/include/grub/i386/efi/memory.h b/include/grub/i386/efi/memory.h
|
||||
index 2c64918e3f7..a4c2ec83502 100644
|
||||
--- a/include/grub/i386/efi/memory.h
|
||||
+++ b/include/grub/i386/efi/memory.h
|
||||
@@ -2,5 +2,6 @@
|
||||
@ -170,8 +157,6 @@ index 2c64918e3f7..a4c2ec83502 100644
|
||||
+#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS
|
||||
|
||||
#endif /* ! GRUB_MEMORY_CPU_HEADER */
|
||||
diff --git a/include/grub/ia64/efi/memory.h b/include/grub/ia64/efi/memory.h
|
||||
index 2c64918e3f7..a4c2ec83502 100644
|
||||
--- a/include/grub/ia64/efi/memory.h
|
||||
+++ b/include/grub/ia64/efi/memory.h
|
||||
@@ -2,5 +2,6 @@
|
||||
@ -181,19 +166,6 @@ index 2c64918e3f7..a4c2ec83502 100644
|
||||
+#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS
|
||||
|
||||
#endif /* ! GRUB_MEMORY_CPU_HEADER */
|
||||
diff --git a/include/grub/riscv64/efi/memory.h b/include/grub/riscv64/efi/memory.h
|
||||
index c6cb3241714..acb61dca44b 100644
|
||||
--- a/include/grub/riscv64/efi/memory.h
|
||||
+++ b/include/grub/riscv64/efi/memory.h
|
||||
@@ -2,5 +2,6 @@
|
||||
#include <grub/efi/memory.h>
|
||||
|
||||
#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL
|
||||
+#define GRUB_EFI_MAX_ALLOCATION_ADDRESS GRUB_EFI_MAX_USABLE_ADDRESS
|
||||
|
||||
#endif /* ! GRUB_MEMORY_CPU_HEADER */
|
||||
diff --git a/include/grub/x86_64/efi/memory.h b/include/grub/x86_64/efi/memory.h
|
||||
index 46e9145a308..e81cfb32213 100644
|
||||
--- a/include/grub/x86_64/efi/memory.h
|
||||
+++ b/include/grub/x86_64/efi/memory.h
|
||||
@@ -2,9 +2,11 @@
|
||||
@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From 5d417346956bc3108183020a8a9f20ddda034b48 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Jones <pjones@redhat.com>
|
||||
Date: Thu, 11 Jul 2019 14:38:57 +0200
|
||||
Subject: [PATCH] arm/arm64 loader: Better memory allocation and error
|
||||
Subject: [PATCH 4/9] arm/arm64 loader: Better memory allocation and error
|
||||
messages.
|
||||
|
||||
On mustang, our memory map looks like:
|
||||
@ -65,16 +65,21 @@ time, rather than interposing GRUB_EFI_MAX_USABLE_ADDRESS there, so that any
|
||||
per-platform constraints on its given address are maintained.
|
||||
|
||||
Signed-off-by: Peter Jones <pjones@redhat.com>
|
||||
---
|
||||
grub-core/kern/efi/mm.c | 33 +++++++++++++++-----
|
||||
grub-core/loader/arm64/linux.c | 68 +++++++++++++++++++++++++++++++-----------
|
||||
2 files changed, 76 insertions(+), 25 deletions(-)
|
||||
|
||||
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
|
||||
index f6aef0ef649..85ad4b4494c 100644
|
||||
squash! arm/arm64 loader: Better memory allocation and error messages.
|
||||
|
||||
Use PRIxGRUB_* conversion specifier in printf's format string to
|
||||
correspond properly to the data type of arguments.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/kern/efi/mm.c | 33 ++++++++++---
|
||||
grub-core/loader/arm64/efi/linux.c | 78 ++++++++++++++++++++++--------
|
||||
2 files changed, 84 insertions(+), 27 deletions(-)
|
||||
|
||||
--- a/grub-core/kern/efi/mm.c
|
||||
+++ b/grub-core/kern/efi/mm.c
|
||||
@@ -154,6 +154,7 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
|
||||
@@ -153,6 +153,7 @@
|
||||
{
|
||||
grub_efi_status_t status;
|
||||
grub_efi_boot_services_t *b;
|
||||
@ -82,16 +87,16 @@ index f6aef0ef649..85ad4b4494c 100644
|
||||
|
||||
/* Limit the memory access to less than 4GB for 32-bit platforms. */
|
||||
if (address > GRUB_EFI_MAX_USABLE_ADDRESS)
|
||||
@@ -170,19 +171,22 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
|
||||
@@ -169,19 +170,22 @@
|
||||
}
|
||||
|
||||
b = grub_efi_system_table->boot_services;
|
||||
- status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
|
||||
+ status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &ret);
|
||||
- status = b->allocate_pages (alloctype, memtype, pages, &address);
|
||||
+ status = b->allocate_pages (alloctype, memtype, pages, &ret);
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
{
|
||||
+ grub_dprintf ("efi",
|
||||
+ "allocate_pages(%d, %d, 0x%0lx, 0x%016lx) = 0x%016lx\n",
|
||||
+ "allocate_pages(%d, %d, 0x%0" PRIxGRUB_SIZE ", 0x%016" PRIxGRUB_UINT64_T ") = 0x%016" PRIxGRUB_SIZE "\n",
|
||||
+ alloctype, memtype, pages, address, status);
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
|
||||
return NULL;
|
||||
@ -103,13 +108,13 @@ index f6aef0ef649..85ad4b4494c 100644
|
||||
/* Uggh, the address 0 was allocated... This is too annoying,
|
||||
so reallocate another one. */
|
||||
- address = GRUB_EFI_MAX_USABLE_ADDRESS;
|
||||
- status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
|
||||
- status = b->allocate_pages (alloctype, memtype, pages, &address);
|
||||
+ ret = address;
|
||||
+ status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &ret);
|
||||
+ status = b->allocate_pages (alloctype, memtype, pages, &ret);
|
||||
grub_efi_free_pages (0, pages);
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
{
|
||||
@@ -191,9 +195,9 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
|
||||
@@ -190,9 +194,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +126,7 @@ index f6aef0ef649..85ad4b4494c 100644
|
||||
}
|
||||
|
||||
void *
|
||||
@@ -713,8 +717,21 @@ grub_efi_get_ram_base(grub_addr_t *base_addr)
|
||||
@@ -711,8 +715,21 @@
|
||||
for (desc = memory_map, *base_addr = GRUB_EFI_MAX_USABLE_ADDRESS;
|
||||
(grub_addr_t) desc < ((grub_addr_t) memory_map + memory_map_size);
|
||||
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size))
|
||||
@ -132,24 +137,22 @@ index f6aef0ef649..85ad4b4494c 100644
|
||||
+ (desc->attribute & GRUB_EFI_MEMORY_WB))
|
||||
+ {
|
||||
+ *base_addr = grub_min (*base_addr, desc->physical_start);
|
||||
+ grub_dprintf ("efi", "setting base_addr=0x%016lx\n", *base_addr);
|
||||
+ grub_dprintf ("efi", "setting base_addr=0x%016" PRIxGRUB_ADDR "\n", *base_addr);
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ grub_dprintf ("efi", "ignoring address 0x%016lx\n", desc->physical_start);
|
||||
+ grub_dprintf ("efi", "ignoring address 0x%016" PRIxGRUB_UINT64_T "\n", desc->physical_start);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (*base_addr == GRUB_EFI_MAX_USABLE_ADDRESS)
|
||||
+ grub_dprintf ("efi", "base_addr 0x%016lx is probably wrong.\n", *base_addr);
|
||||
+ grub_dprintf ("efi", "base_addr 0x%016" PRIxGRUB_ADDR " is probably wrong.\n", *base_addr);
|
||||
|
||||
grub_free(memory_map);
|
||||
|
||||
diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
|
||||
index 04994d5c67d..70a0075ec5e 100644
|
||||
--- a/grub-core/loader/arm64/linux.c
|
||||
+++ b/grub-core/loader/arm64/linux.c
|
||||
@@ -71,20 +71,25 @@ finalize_params_linux (void)
|
||||
--- a/grub-core/loader/arm64/efi/linux.c
|
||||
+++ b/grub-core/loader/arm64/efi/linux.c
|
||||
@@ -89,13 +89,15 @@
|
||||
{
|
||||
grub_efi_loaded_image_t *loaded_image = NULL;
|
||||
int node, retval, len;
|
||||
@ -168,7 +171,26 @@ index 04994d5c67d..70a0075ec5e 100644
|
||||
|
||||
node = grub_fdt_find_subnode (fdt, 0, "chosen");
|
||||
if (node < 0)
|
||||
node = grub_fdt_add_subnode (fdt, 0, "chosen");
|
||||
@@ -106,17 +108,26 @@
|
||||
*/
|
||||
retval = grub_fdt_set_prop32(fdt, 0, "#address-cells", 2);
|
||||
if (retval)
|
||||
- goto failure;
|
||||
+ {
|
||||
+ err = grub_error(retval, "Could not find #address-cells");
|
||||
+ goto failure;
|
||||
+ }
|
||||
|
||||
retval = grub_fdt_set_prop32(fdt, 0, "#size-cells", 2);
|
||||
if (retval)
|
||||
- goto failure;
|
||||
+ {
|
||||
+ err = grub_error(retval, "Could not find #size-cells");
|
||||
+ goto failure;
|
||||
+ }
|
||||
|
||||
node = grub_fdt_add_subnode (fdt, 0, "chosen");
|
||||
}
|
||||
|
||||
if (node < 1)
|
||||
- goto failure;
|
||||
@ -179,7 +201,7 @@ index 04994d5c67d..70a0075ec5e 100644
|
||||
|
||||
/* Set initrd info */
|
||||
if (initrd_start && initrd_end > initrd_start)
|
||||
@@ -95,15 +100,26 @@ finalize_params_linux (void)
|
||||
@@ -127,15 +138,26 @@
|
||||
retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-start",
|
||||
initrd_start);
|
||||
if (retval)
|
||||
@ -209,8 +231,8 @@ index 04994d5c67d..70a0075ec5e 100644
|
||||
+ }
|
||||
|
||||
grub_dprintf ("linux", "Installed/updated FDT configuration table @ %p\n",
|
||||
fdt);
|
||||
@@ -111,14 +127,20 @@ finalize_params_linux (void)
|
||||
fdt);
|
||||
@@ -143,14 +165,20 @@
|
||||
/* Convert command line to UCS-2 */
|
||||
loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
|
||||
if (!loaded_image)
|
||||
@ -233,7 +255,7 @@ index 04994d5c67d..70a0075ec5e 100644
|
||||
|
||||
loaded_image->load_options_size =
|
||||
2 * grub_utf8_to_utf16 (loaded_image->load_options, len,
|
||||
@@ -128,7 +150,7 @@ finalize_params_linux (void)
|
||||
@@ -160,7 +188,7 @@
|
||||
|
||||
failure:
|
||||
grub_fdt_unload();
|
||||
@ -242,7 +264,7 @@ index 04994d5c67d..70a0075ec5e 100644
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -212,16 +234,28 @@ grub_linux_unload (void)
|
||||
@@ -246,16 +274,28 @@
|
||||
static void *
|
||||
allocate_initrd_mem (int initrd_pages)
|
||||
{
|
||||
@ -250,16 +272,16 @@ index 04994d5c67d..70a0075ec5e 100644
|
||||
+ grub_addr_t max_addr = 0;
|
||||
+ grub_err_t err;
|
||||
+ void *ret;
|
||||
|
||||
- if (grub_efi_get_ram_base (&max_addr) != GRUB_ERR_NONE)
|
||||
- return NULL;
|
||||
+
|
||||
+ err = grub_efi_get_ram_base (&max_addr);
|
||||
+ if (err != GRUB_ERR_NONE)
|
||||
+ {
|
||||
+ grub_error (err, "grub_efi_get_ram_base() failed");
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
|
||||
- if (grub_efi_get_ram_base (&max_addr) != GRUB_ERR_NONE)
|
||||
- return NULL;
|
||||
+ grub_dprintf ("linux", "max_addr: 0x%016lx, INITRD_MAX_ADDRESS_OFFSET: 0x%016llx\n",
|
||||
+ max_addr, INITRD_MAX_ADDRESS_OFFSET);
|
||||
|
||||
342
0004-cryptodisk-Support-key-protectors.patch
Normal file
342
0004-cryptodisk-Support-key-protectors.patch
Normal file
@ -0,0 +1,342 @@
|
||||
From 9888bf40d960339a59dc18fb6e1df5f65b4668e3 Mon Sep 17 00:00:00 2001
|
||||
From: Hernan Gatta <hegatta@linux.microsoft.com>
|
||||
Date: Tue, 1 Feb 2022 05:02:56 -0800
|
||||
Subject: [PATCH 13/14] cryptodisk: Support key protectors
|
||||
|
||||
Add a new parameter to cryptomount to support the key protectors framework: -k.
|
||||
The parameter is used to automatically retrieve a key from specified key
|
||||
protectors. The parameter may be repeated to specify any number of key
|
||||
protectors. These are tried in order until one provides a usable key for any
|
||||
given disk.
|
||||
|
||||
Signed-off-by: <Hernan Gatta hegatta@linux.microsoft.com>
|
||||
---
|
||||
Makefile.util.def | 1 +
|
||||
grub-core/disk/cryptodisk.c | 166 +++++++++++++++++++++++++++++-------
|
||||
include/grub/cryptodisk.h | 14 +++
|
||||
3 files changed, 151 insertions(+), 30 deletions(-)
|
||||
|
||||
--- a/Makefile.util.def
|
||||
+++ b/Makefile.util.def
|
||||
@@ -35,6 +35,7 @@
|
||||
common = grub-core/kern/list.c;
|
||||
common = grub-core/kern/misc.c;
|
||||
common = grub-core/kern/partition.c;
|
||||
+ common = grub-core/kern/protectors.c;
|
||||
common = grub-core/lib/crypto.c;
|
||||
common = grub-core/lib/json/json.c;
|
||||
common = grub-core/disk/luks.c;
|
||||
--- a/grub-core/disk/cryptodisk.c
|
||||
+++ b/grub-core/disk/cryptodisk.c
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <grub/file.h>
|
||||
#include <grub/procfs.h>
|
||||
#include <grub/partition.h>
|
||||
+#include <grub/protector.h>
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
#include <grub/emu/hostdisk.h>
|
||||
@@ -44,7 +45,8 @@
|
||||
OPTION_KEYFILE,
|
||||
OPTION_KEYFILE_OFFSET,
|
||||
OPTION_KEYFILE_SIZE,
|
||||
- OPTION_HEADER
|
||||
+ OPTION_HEADER,
|
||||
+ OPTION_PROTECTOR
|
||||
};
|
||||
|
||||
static const struct grub_arg_option options[] =
|
||||
@@ -58,6 +60,8 @@
|
||||
{"keyfile-offset", 'O', 0, N_("Key file offset (bytes)"), 0, ARG_TYPE_INT},
|
||||
{"keyfile-size", 'S', 0, N_("Key file data size (bytes)"), 0, ARG_TYPE_INT},
|
||||
{"header", 'H', 0, N_("Read header from file"), 0, ARG_TYPE_STRING},
|
||||
+ {"protector", 'P', GRUB_ARG_OPTION_REPEATABLE,
|
||||
+ N_("Unlock volume(s) using key protector(s)."), 0, ARG_TYPE_STRING},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
@@ -1061,6 +1065,7 @@
|
||||
grub_err_t ret = GRUB_ERR_NONE;
|
||||
grub_cryptodisk_t dev;
|
||||
grub_cryptodisk_dev_t cr;
|
||||
+ int i;
|
||||
struct cryptodisk_read_hook_ctx read_hook_data = {0};
|
||||
int askpass = 0;
|
||||
char *part = NULL;
|
||||
@@ -1113,41 +1118,112 @@
|
||||
goto error_no_close;
|
||||
if (!dev)
|
||||
continue;
|
||||
+ break;
|
||||
+ }
|
||||
|
||||
- if (!cargs->key_len)
|
||||
- {
|
||||
- /* Get the passphrase from the user, if no key data. */
|
||||
- askpass = 1;
|
||||
- part = grub_partition_get_name (source->partition);
|
||||
- grub_printf_ (N_("Enter passphrase for %s%s%s (%s): "), source->name,
|
||||
- source->partition != NULL ? "," : "",
|
||||
- part != NULL ? part : N_("UNKNOWN"),
|
||||
- dev->uuid);
|
||||
- grub_free (part);
|
||||
-
|
||||
- cargs->key_data = grub_malloc (GRUB_CRYPTODISK_MAX_PASSPHRASE);
|
||||
- if (cargs->key_data == NULL)
|
||||
- goto error_no_close;
|
||||
+ if (dev == NULL)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_BAD_MODULE,
|
||||
+ "no cryptodisk module can handle this device");
|
||||
+ goto error_no_close;
|
||||
+ }
|
||||
|
||||
- if (!grub_password_get ((char *) cargs->key_data, GRUB_CRYPTODISK_MAX_PASSPHRASE))
|
||||
- {
|
||||
- grub_error (GRUB_ERR_BAD_ARGUMENT, "passphrase not supplied");
|
||||
- goto error;
|
||||
- }
|
||||
- cargs->key_len = grub_strlen ((char *) cargs->key_data);
|
||||
- }
|
||||
+ if (cargs->protectors)
|
||||
+ {
|
||||
+ for (i = 0; cargs->protectors[i]; i++)
|
||||
+ {
|
||||
+ if (cargs->key_cache[i].invalid)
|
||||
+ continue;
|
||||
|
||||
- ret = cr->recover_key (source, dev, cargs);
|
||||
- if (ret != GRUB_ERR_NONE)
|
||||
- goto error;
|
||||
+ if (cargs->key_cache[i].key == NULL)
|
||||
+ {
|
||||
+ ret = grub_key_protector_recover_key (cargs->protectors[i],
|
||||
+ &cargs->key_cache[i].key,
|
||||
+ &cargs->key_cache[i].key_len);
|
||||
+ if (ret != GRUB_ERR_NONE)
|
||||
+ {
|
||||
+ if (grub_errno)
|
||||
+ {
|
||||
+ grub_print_error ();
|
||||
+ grub_errno = GRUB_ERR_NONE;
|
||||
+ }
|
||||
+
|
||||
+ grub_dprintf ("cryptodisk",
|
||||
+ "failed to recover a key from key protector "
|
||||
+ "%s, will not try it again for any other "
|
||||
+ "disks, if any, during this invocation of "
|
||||
+ "cryptomount\n",
|
||||
+ cargs->protectors[i]);
|
||||
+
|
||||
+ cargs->key_cache[i].invalid = 1;
|
||||
+ continue;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ cargs->key_data = cargs->key_cache[i].key;
|
||||
+ cargs->key_len = cargs->key_cache[i].key_len;
|
||||
+
|
||||
+ ret = cr->recover_key (source, dev, cargs);
|
||||
+ if (ret != GRUB_ERR_NONE)
|
||||
+ {
|
||||
+ part = grub_partition_get_name (source->partition);
|
||||
+ grub_dprintf ("cryptodisk",
|
||||
+ "recovered a key from key protector %s but it "
|
||||
+ "failed to unlock %s%s%s (%s)\n",
|
||||
+ cargs->protectors[i], source->name,
|
||||
+ source->partition != NULL ? "," : "",
|
||||
+ part != NULL ? part : N_("UNKNOWN"), dev->uuid);
|
||||
+ grub_free (part);
|
||||
+ continue;
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ ret = grub_cryptodisk_insert (dev, name, source);
|
||||
+ if (ret != GRUB_ERR_NONE)
|
||||
+ goto error;
|
||||
+ goto cleanup;
|
||||
+ }
|
||||
+ }
|
||||
|
||||
- ret = grub_cryptodisk_insert (dev, name, source);
|
||||
- if (ret != GRUB_ERR_NONE)
|
||||
+ part = grub_partition_get_name (source->partition);
|
||||
+ grub_error (GRUB_ERR_ACCESS_DENIED,
|
||||
+ N_("no key protector provided a usable key for %s%s%s (%s)"),
|
||||
+ source->name, source->partition != NULL ? "," : "",
|
||||
+ part != NULL ? part : N_("UNKNOWN"), dev->uuid);
|
||||
+ grub_free (part);
|
||||
goto error;
|
||||
+ }
|
||||
+
|
||||
+ if (!cargs->key_len)
|
||||
+ {
|
||||
+ /* Get the passphrase from the user, if no key data. */
|
||||
+ askpass = 1;
|
||||
+ part = grub_partition_get_name (source->partition);
|
||||
+ grub_printf_ (N_("Enter passphrase for %s%s%s (%s): "), source->name,
|
||||
+ source->partition != NULL ? "," : "",
|
||||
+ part != NULL ? part : N_("UNKNOWN"), dev->uuid);
|
||||
+ grub_free (part);
|
||||
+
|
||||
+ cargs->key_data = grub_malloc (GRUB_CRYPTODISK_MAX_PASSPHRASE);
|
||||
+ if (cargs->key_data == NULL)
|
||||
+ goto error;
|
||||
+
|
||||
+ if (!grub_password_get ((char *) cargs->key_data, GRUB_CRYPTODISK_MAX_PASSPHRASE))
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_BAD_ARGUMENT, "passphrase not supplied");
|
||||
+ goto error;
|
||||
+ }
|
||||
+ cargs->key_len = grub_strlen ((char *) cargs->key_data);
|
||||
+ }
|
||||
+
|
||||
+ ret = cr->recover_key (source, dev, cargs);
|
||||
+ if (ret != GRUB_ERR_NONE)
|
||||
+ goto error;
|
||||
+
|
||||
+ ret = grub_cryptodisk_insert (dev, name, source);
|
||||
+ if (ret != GRUB_ERR_NONE)
|
||||
+ goto error;
|
||||
|
||||
- goto cleanup;
|
||||
- }
|
||||
- grub_error (GRUB_ERR_BAD_MODULE, "no cryptodisk module can handle this device");
|
||||
goto cleanup;
|
||||
|
||||
error:
|
||||
@@ -1258,6 +1334,20 @@
|
||||
return ret;
|
||||
}
|
||||
|
||||
+static void
|
||||
+grub_cryptodisk_clear_key_cache (struct grub_cryptomount_args *cargs)
|
||||
+{
|
||||
+ int i;
|
||||
+
|
||||
+ if (cargs->key_cache == NULL || cargs->protectors == NULL)
|
||||
+ return;
|
||||
+
|
||||
+ for (i = 0; cargs->protectors[i]; i++)
|
||||
+ grub_free (cargs->key_cache[i].key);
|
||||
+
|
||||
+ grub_free (cargs->key_cache);
|
||||
+}
|
||||
+
|
||||
static grub_err_t
|
||||
grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||
{
|
||||
@@ -1270,6 +1360,10 @@
|
||||
if (grub_cryptodisk_list == NULL)
|
||||
return grub_error (GRUB_ERR_BAD_MODULE, "no cryptodisk modules loaded");
|
||||
|
||||
+ if (state[OPTION_PASSWORD].set && state[OPTION_PROTECTOR].set) /* password and key protector */
|
||||
+ return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
+ "a password and a key protector cannot both be set");
|
||||
+
|
||||
if (state[OPTION_PASSWORD].set) /* password */
|
||||
{
|
||||
cargs.key_data = (grub_uint8_t *) state[OPTION_PASSWORD].arg;
|
||||
@@ -1362,6 +1456,15 @@
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
+ if (state[OPTION_PROTECTOR].set) /* key protector(s) */
|
||||
+ {
|
||||
+ cargs.key_cache = grub_zalloc (state[OPTION_PROTECTOR].set * sizeof (*cargs.key_cache));
|
||||
+ if (cargs.key_cache == NULL)
|
||||
+ return grub_error (GRUB_ERR_OUT_OF_MEMORY,
|
||||
+ "no memory for key protector key cache");
|
||||
+ cargs.protectors = state[OPTION_PROTECTOR].args;
|
||||
+ }
|
||||
+
|
||||
if (state[OPTION_UUID].set) /* uuid */
|
||||
{
|
||||
int found_uuid;
|
||||
@@ -1370,6 +1473,7 @@
|
||||
dev = grub_cryptodisk_get_by_uuid (args[0]);
|
||||
if (dev)
|
||||
{
|
||||
+ grub_cryptodisk_clear_key_cache (&cargs);
|
||||
grub_dprintf ("cryptodisk",
|
||||
"already mounted as crypto%lu\n", dev->id);
|
||||
return GRUB_ERR_NONE;
|
||||
@@ -1378,6 +1482,7 @@
|
||||
cargs.check_boot = state[OPTION_BOOT].set;
|
||||
cargs.search_uuid = args[0];
|
||||
found_uuid = grub_device_iterate (&grub_cryptodisk_scan_device, &cargs);
|
||||
+ grub_cryptodisk_clear_key_cache (&cargs);
|
||||
|
||||
if (found_uuid)
|
||||
return GRUB_ERR_NONE;
|
||||
@@ -1397,6 +1502,7 @@
|
||||
{
|
||||
cargs.check_boot = state[OPTION_BOOT].set;
|
||||
grub_device_iterate (&grub_cryptodisk_scan_device, &cargs);
|
||||
+ grub_cryptodisk_clear_key_cache (&cargs);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
else
|
||||
@@ -1420,6 +1526,7 @@
|
||||
disk = grub_disk_open (diskname);
|
||||
if (!disk)
|
||||
{
|
||||
+ grub_cryptodisk_clear_key_cache (&cargs);
|
||||
if (disklast)
|
||||
*disklast = ')';
|
||||
return grub_errno;
|
||||
@@ -1430,12 +1537,14 @@
|
||||
{
|
||||
grub_dprintf ("cryptodisk", "already mounted as crypto%lu\n", dev->id);
|
||||
grub_disk_close (disk);
|
||||
+ grub_cryptodisk_clear_key_cache (&cargs);
|
||||
if (disklast)
|
||||
*disklast = ')';
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
dev = grub_cryptodisk_scan_device_real (diskname, disk, &cargs);
|
||||
+ grub_cryptodisk_clear_key_cache (&cargs);
|
||||
|
||||
grub_disk_close (disk);
|
||||
if (disklast)
|
||||
@@ -1576,6 +1685,7 @@
|
||||
cmd = grub_register_extcmd ("cryptomount", grub_cmd_cryptomount, 0,
|
||||
N_("[ [-p password] | [-k keyfile"
|
||||
" [-O keyoffset] [-S keysize] ] ] [-H file]"
|
||||
+ " [-P protector [-P protector ...]]"
|
||||
" <SOURCE|-u UUID|-a|-b>"),
|
||||
N_("Mount a crypto device."), options);
|
||||
grub_procfs_register ("luks_script", &luks_script);
|
||||
--- a/include/grub/cryptodisk.h
|
||||
+++ b/include/grub/cryptodisk.h
|
||||
@@ -70,6 +70,18 @@
|
||||
(*grub_cryptodisk_rekey_func_t) (struct grub_cryptodisk *dev,
|
||||
grub_uint64_t zoneno);
|
||||
|
||||
+struct grub_cryptomount_cached_key
|
||||
+{
|
||||
+ grub_uint8_t *key;
|
||||
+ grub_size_t key_len;
|
||||
+
|
||||
+ /*
|
||||
+ * The key protector associated with this cache entry failed, so avoid it
|
||||
+ * even if the cached entry (an instance of this structure) is empty.
|
||||
+ */
|
||||
+ int invalid;
|
||||
+};
|
||||
+
|
||||
struct grub_cryptomount_args
|
||||
{
|
||||
/* scan: Flag to indicate that only bootable volumes should be decrypted */
|
||||
@@ -81,6 +93,10 @@
|
||||
/* recover_key: Length of key_data */
|
||||
grub_size_t key_len;
|
||||
grub_file_t hdr_file;
|
||||
+ /* recover_key: Names of the key protectors to use (NULL-terminated) */
|
||||
+ char **protectors;
|
||||
+ /* recover_key: Key cache to avoid invoking the same key protector twice */
|
||||
+ struct grub_cryptomount_cached_key *key_cache;
|
||||
};
|
||||
typedef struct grub_cryptomount_args *grub_cryptomount_args_t;
|
||||
|
||||
89
0004-diskfilter-look-up-cryptodisk-devices-first.patch
Normal file
89
0004-diskfilter-look-up-cryptodisk-devices-first.patch
Normal file
@ -0,0 +1,89 @@
|
||||
From b7e2fb6a680447b7bb7eb18bb7570afa8d2b7f09 Mon Sep 17 00:00:00 2001
|
||||
From: Gary Lin <glin@suse.com>
|
||||
Date: Thu, 10 Aug 2023 10:19:29 +0800
|
||||
Subject: [PATCH 4/4] diskfilter: look up cryptodisk devices first
|
||||
|
||||
When using disk auto-unlocking with TPM 2.0, the typical grub.cfg may
|
||||
look like this:
|
||||
|
||||
tpm2_key_protector_init --tpm2key=(hd0,gpt1)/boot/grub2/sealed.tpm
|
||||
cryptomount -u <PART-UUID> -P tpm2
|
||||
search --fs-uuid --set=root <FS-UUID>
|
||||
|
||||
Since the disk search order is based on the order of module loading, the
|
||||
attacker could insert a malicious disk with the same FS-UUID root to
|
||||
trick grub2 to boot into th malicious root and further dump memory to
|
||||
steal the unsealed key.
|
||||
|
||||
To defend such attack, we can specify the hint provided by 'grub-probe'
|
||||
to search the encrypted partition first:
|
||||
|
||||
search --fs-uuid --set=root --hint='cryptouuid/<PART-UUID>' <FS-UUID>
|
||||
|
||||
However, for LVM on a encrypted partition, the search hint provided by
|
||||
'grub-probe' is:
|
||||
|
||||
--hint='lvmid/<VG-UUID>/<LV-UUID>'
|
||||
|
||||
It doesn't guarantee to look up the logical volume from the encrypted
|
||||
partition, so the attacker may have the chance to fool grub2 to boot
|
||||
into the malicious disk.
|
||||
|
||||
To mininize the attack surface, this commit tweaks the disk device search
|
||||
in diskfilter to look up cryptodisk devices first and then others, so
|
||||
that the auto-unlocked disk will be found first, not the attacker's disk.
|
||||
|
||||
Signed-off-by: Gary Lin <glin@suse.com>
|
||||
---
|
||||
grub-core/disk/diskfilter.c | 35 ++++++++++++++++++++++++++---------
|
||||
1 file changed, 26 insertions(+), 9 deletions(-)
|
||||
|
||||
diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c
|
||||
index 61a311efd..94832c8dd 100644
|
||||
--- a/grub-core/disk/diskfilter.c
|
||||
+++ b/grub-core/disk/diskfilter.c
|
||||
@@ -226,15 +226,32 @@ scan_devices (const char *arname)
|
||||
int need_rescan;
|
||||
|
||||
for (pull = 0; pull < GRUB_DISK_PULL_MAX; pull++)
|
||||
- for (p = grub_disk_dev_list; p; p = p->next)
|
||||
- if (p->id != GRUB_DISK_DEVICE_DISKFILTER_ID
|
||||
- && p->disk_iterate)
|
||||
- {
|
||||
- if ((p->disk_iterate) (scan_disk_hook, NULL, pull))
|
||||
- return;
|
||||
- if (arname && is_lv_readable (find_lv (arname), 1))
|
||||
- return;
|
||||
- }
|
||||
+ {
|
||||
+ /* look up the crytodisk devices first */
|
||||
+ for (p = grub_disk_dev_list; p; p = p->next)
|
||||
+ if (p->id == GRUB_DISK_DEVICE_CRYPTODISK_ID
|
||||
+ && p->disk_iterate)
|
||||
+ {
|
||||
+ if ((p->disk_iterate) (scan_disk_hook, NULL, pull))
|
||||
+ return;
|
||||
+ if (arname && is_lv_readable (find_lv (arname), 1))
|
||||
+ return;
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ /* check the devices other than crytodisk */
|
||||
+ for (p = grub_disk_dev_list; p; p = p->next)
|
||||
+ if (p->id == GRUB_DISK_DEVICE_CRYPTODISK_ID)
|
||||
+ continue;
|
||||
+ else if (p->id != GRUB_DISK_DEVICE_DISKFILTER_ID
|
||||
+ && p->disk_iterate)
|
||||
+ {
|
||||
+ if ((p->disk_iterate) (scan_disk_hook, NULL, pull))
|
||||
+ return;
|
||||
+ if (arname && is_lv_readable (find_lv (arname), 1))
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
|
||||
scan_depth = 0;
|
||||
need_rescan = 1;
|
||||
--
|
||||
2.35.3
|
||||
|
||||
116
0004-efinet-UEFI-IPv6-PXE-support.patch
Normal file
116
0004-efinet-UEFI-IPv6-PXE-support.patch
Normal file
@ -0,0 +1,116 @@
|
||||
From ca482c7c1efe5faf792bf0912a116ea8e0642e24 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Wed, 15 Apr 2015 14:48:30 +0800
|
||||
Subject: [PATCH 4/8] efinet: UEFI IPv6 PXE support
|
||||
|
||||
When grub2 image is booted from UEFI IPv6 PXE, the DHCPv6 Reply packet is
|
||||
cached in firmware buffer which can be obtained by PXE Base Code protocol. The
|
||||
network interface can be setup through the parameters in that obtained packet.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
Signed-off-by: Ken Lin <ken.lin@hpe.com>
|
||||
---
|
||||
grub-core/net/drivers/efi/efinet.c | 24 +++++++++++++----
|
||||
include/grub/efi/api.h | 55 +++++++++++++++++++++++++++++++++++++-
|
||||
2 files changed, 73 insertions(+), 6 deletions(-)
|
||||
|
||||
--- a/grub-core/net/drivers/efi/efinet.c
|
||||
+++ b/grub-core/net/drivers/efi/efinet.c
|
||||
@@ -400,6 +400,18 @@
|
||||
continue;
|
||||
pxe_mode = pxe->mode;
|
||||
|
||||
+ if (pxe_mode->using_ipv6)
|
||||
+ {
|
||||
+ grub_net_configure_by_dhcpv6_reply (card->name, card, 0,
|
||||
+ (struct grub_net_dhcp6_packet *)
|
||||
+ &pxe_mode->dhcp_ack,
|
||||
+ sizeof (pxe_mode->dhcp_ack),
|
||||
+ 1, device, path);
|
||||
+ if (grub_errno)
|
||||
+ grub_print_error ();
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
inter = grub_net_configure_by_dhcp_ack (card->name, card, 0,
|
||||
(struct grub_net_bootp_packet *)
|
||||
&pxe_mode->dhcp_ack,
|
||||
@@ -428,6 +440,7 @@
|
||||
vlan_dp = (grub_efi_device_path_t *) ((grub_efi_uint8_t *) vlan_dp + vlan_dp_len);
|
||||
}
|
||||
}
|
||||
+ }
|
||||
return;
|
||||
}
|
||||
}
|
||||
--- a/include/grub/efi/api.h
|
||||
+++ b/include/grub/efi/api.h
|
||||
@@ -1523,14 +1523,67 @@
|
||||
|
||||
typedef grub_uint8_t grub_efi_pxe_packet_t[1472];
|
||||
|
||||
+typedef struct {
|
||||
+ grub_uint8_t addr[4];
|
||||
+} grub_efi_pxe_ipv4_address_t;
|
||||
+
|
||||
+typedef struct {
|
||||
+ grub_uint8_t addr[16];
|
||||
+} grub_efi_pxe_ipv6_address_t;
|
||||
+
|
||||
+typedef struct {
|
||||
+ grub_uint8_t addr[32];
|
||||
+} grub_efi_pxe_mac_address_t;
|
||||
+
|
||||
+typedef union {
|
||||
+ grub_uint32_t addr[4];
|
||||
+ grub_efi_pxe_ipv4_address_t v4;
|
||||
+ grub_efi_pxe_ipv6_address_t v6;
|
||||
+} grub_efi_pxe_ip_address_t;
|
||||
+
|
||||
+#define GRUB_EFI_PXE_BASE_CODE_MAX_IPCNT 8
|
||||
+typedef struct {
|
||||
+ grub_uint8_t filters;
|
||||
+ grub_uint8_t ip_cnt;
|
||||
+ grub_uint16_t reserved;
|
||||
+ grub_efi_pxe_ip_address_t ip_list[GRUB_EFI_PXE_BASE_CODE_MAX_IPCNT];
|
||||
+} grub_efi_pxe_ip_filter_t;
|
||||
+
|
||||
+typedef struct {
|
||||
+ grub_efi_pxe_ip_address_t ip_addr;
|
||||
+ grub_efi_pxe_mac_address_t mac_addr;
|
||||
+} grub_efi_pxe_arp_entry_t;
|
||||
+
|
||||
+typedef struct {
|
||||
+ grub_efi_pxe_ip_address_t ip_addr;
|
||||
+ grub_efi_pxe_ip_address_t subnet_mask;
|
||||
+ grub_efi_pxe_ip_address_t gw_addr;
|
||||
+} grub_efi_pxe_route_entry_t;
|
||||
+
|
||||
+
|
||||
+#define GRUB_EFI_PXE_BASE_CODE_MAX_ARP_ENTRIES 8
|
||||
+#define GRUB_EFI_PXE_BASE_CODE_MAX_ROUTE_ENTRIES 8
|
||||
+
|
||||
typedef struct grub_efi_pxe_mode
|
||||
{
|
||||
- grub_uint8_t unused[52];
|
||||
+ grub_uint8_t started;
|
||||
+ grub_uint8_t ipv6_available;
|
||||
+ grub_uint8_t ipv6_supported;
|
||||
+ grub_uint8_t using_ipv6;
|
||||
+ grub_uint8_t unused[16];
|
||||
+ grub_efi_pxe_ip_address_t station_ip;
|
||||
+ grub_efi_pxe_ip_address_t subnet_mask;
|
||||
grub_efi_pxe_packet_t dhcp_discover;
|
||||
grub_efi_pxe_packet_t dhcp_ack;
|
||||
grub_efi_pxe_packet_t proxy_offer;
|
||||
grub_efi_pxe_packet_t pxe_discover;
|
||||
grub_efi_pxe_packet_t pxe_reply;
|
||||
+ grub_efi_pxe_packet_t pxe_bis_reply;
|
||||
+ grub_efi_pxe_ip_filter_t ip_filter;
|
||||
+ grub_uint32_t arp_cache_entries;
|
||||
+ grub_efi_pxe_arp_entry_t arp_cache[GRUB_EFI_PXE_BASE_CODE_MAX_ARP_ENTRIES];
|
||||
+ grub_uint32_t route_table_entries;
|
||||
+ grub_efi_pxe_route_entry_t route_table[GRUB_EFI_PXE_BASE_CODE_MAX_ROUTE_ENTRIES];
|
||||
} grub_efi_pxe_mode_t;
|
||||
|
||||
typedef struct grub_efi_pxe
|
||||
28
0004-ofpath-controller-name-update.patch
Normal file
28
0004-ofpath-controller-name-update.patch
Normal file
@ -0,0 +1,28 @@
|
||||
From 7717cd9c27f18703287403af1a955588e3d0261f Mon Sep 17 00:00:00 2001
|
||||
From: mamatha <mainamdar@in.ibm.com>
|
||||
Date: Sat, 24 Sep 2022 11:22:39 +0530
|
||||
Subject: [PATCH 4/4] ofpath controller name update
|
||||
|
||||
patch to update ofpath controller name
|
||||
|
||||
Signed-off-by: mamatha <mainamdar@in.ibm.com>
|
||||
---
|
||||
grub-core/osdep/linux/ofpath.c | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
|
||||
diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
|
||||
index 212782d3f..7d31cfd0f 100644
|
||||
--- a/grub-core/osdep/linux/ofpath.c
|
||||
+++ b/grub-core/osdep/linux/ofpath.c
|
||||
@@ -483,6 +483,8 @@ of_path_get_nvmeof_adapter_info(char* sysfs_path,
|
||||
buf3=strchr(buf2,'-')+1;
|
||||
buf3=strchr(buf3,'-')+1;
|
||||
nvmeof_info->target_wwpn = buf3;
|
||||
+ buf3=strchr(buf3,'x')+1;
|
||||
+ nvmeof_info->target_wwpn = buf3;
|
||||
buf3 = strchr(nvmeof_info->target_wwpn,',');
|
||||
*buf3 = '\0';
|
||||
|
||||
--
|
||||
2.35.3
|
||||
|
||||
170
0004-tpm2-Support-authorized-policy.patch
Normal file
170
0004-tpm2-Support-authorized-policy.patch
Normal file
@ -0,0 +1,170 @@
|
||||
From 542c4fc6e067e04e8b96f798882ae968c59f4948 Mon Sep 17 00:00:00 2001
|
||||
From: Gary Lin <glin@suse.com>
|
||||
Date: Thu, 6 Apr 2023 16:00:25 +0800
|
||||
Subject: [PATCH v7 16/20] tpm2: Support authorized policy
|
||||
|
||||
This commit handles the TPM2_PolicyAuthorize command from the key file
|
||||
in TPM 2.0 Key File format.
|
||||
|
||||
TPM2_PolicyAuthorize is the essential command to support authorized
|
||||
policy which allows the users to sign TPM policies with their own keys.
|
||||
Per TPM 2.0 Key File(*1), CommandPolicy for TPM2_PolicyAuthorize
|
||||
comprises 'TPM2B_PUBLIC pubkey', 'TPM2B_DIGEST policy_ref', and
|
||||
'TPMT_SIGNATURE signature'. To verify the signature, the current policy
|
||||
digest is hashed with the hash algorithm written in 'signature', and then
|
||||
'signature' is verified with the hashed policy digest and 'pubkey'. Once
|
||||
TPM accepts 'signature', TPM2_PolicyAuthorize is invoked to authorize the
|
||||
signed policy.
|
||||
|
||||
To create the key file with authorized policy, here are the pcr-oracle(*2)
|
||||
commands:
|
||||
|
||||
# Generate the RSA key and create the authorized policy file
|
||||
$ pcr-oracle \
|
||||
--rsa-generate-key \
|
||||
--private-key policy-key.pem \
|
||||
--auth authorized.policy \
|
||||
create-authorized-policy 0,2,4,7,9
|
||||
|
||||
# Seal the secret with the authorized policy
|
||||
$ pcr-oracle \
|
||||
--key-format tpm2.0 \
|
||||
--auth authorized.policy \
|
||||
--input disk-secret.txt \
|
||||
--output sealed.key \
|
||||
seal-secret
|
||||
|
||||
# Sign the predicted PCR policy
|
||||
$ pcr-oracle \
|
||||
--key-format tpm2.0 \
|
||||
--private-key policy-key.pem \
|
||||
--from eventlog \
|
||||
--stop-event "grub-file=grub.cfg" \
|
||||
--after \
|
||||
--input sealed.key \
|
||||
--output sealed.tpm \
|
||||
sign 0,2,4,7.9
|
||||
|
||||
Then specify the key file and the key protector to grub.cfg in the EFI
|
||||
system partition:
|
||||
|
||||
tpm2_key_protector_init --tpm2key=(hd0,gpt1)/boot/grub2/sealed.tpm
|
||||
cryptomount -u <PART_UUID> -P tpm2
|
||||
|
||||
For any change in the boot components, just run the 'sign' command again
|
||||
to update the signature in sealed.tpm, and TPM can unseal the key file
|
||||
with the updated PCR policy.
|
||||
|
||||
(*1) https://www.hansenpartnership.com/draft-bottomley-tpm2-keys.html
|
||||
(*2) https://github.com/okirch/pcr-oracle
|
||||
|
||||
Signed-off-by: Gary Lin <glin@suse.com>
|
||||
---
|
||||
grub-core/tpm2/module.c | 84 +++++++++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 84 insertions(+)
|
||||
|
||||
diff --git a/grub-core/tpm2/module.c b/grub-core/tpm2/module.c
|
||||
index df0727215..0cbfd06e8 100644
|
||||
--- a/grub-core/tpm2/module.c
|
||||
+++ b/grub-core/tpm2/module.c
|
||||
@@ -453,6 +453,87 @@ grub_tpm2_protector_policypcr (TPMI_SH_AUTH_SESSION session,
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
+static grub_err_t
|
||||
+grub_tpm2_protector_policyauthorize (TPMI_SH_AUTH_SESSION session,
|
||||
+ struct grub_tpm2_buffer *cmd_buf)
|
||||
+{
|
||||
+ TPM2B_PUBLIC pubkey;
|
||||
+ TPM2B_DIGEST policy_ref;
|
||||
+ TPMT_SIGNATURE signature;
|
||||
+ TPM2B_DIGEST pcr_policy;
|
||||
+ TPM2B_DIGEST pcr_policy_hash;
|
||||
+ TPMI_ALG_HASH sig_hash;
|
||||
+ TPMT_TK_VERIFIED verification_ticket;
|
||||
+ TPM_HANDLE pubkey_handle = 0;
|
||||
+ TPM2B_NAME pubname;
|
||||
+ TPM_RC rc;
|
||||
+ grub_err_t err;
|
||||
+
|
||||
+ grub_tpm2_mu_TPM2B_PUBLIC_Unmarshal (cmd_buf, &pubkey);
|
||||
+ grub_tpm2_mu_TPM2B_DIGEST_Unmarshal (cmd_buf, &policy_ref);
|
||||
+ grub_tpm2_mu_TPMT_SIGNATURE_Unmarshal (cmd_buf, &signature);
|
||||
+ if (cmd_buf->error != 0)
|
||||
+ return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
+ N_("Failed to unmarshal the buffer for TPM2_PolicyAuthorize"));
|
||||
+
|
||||
+ /* Retrieve Policy Digest */
|
||||
+ rc = TPM2_PolicyGetDigest (session, NULL, &pcr_policy, NULL);
|
||||
+ if (rc != TPM_RC_SUCCESS)
|
||||
+ return grub_error (GRUB_ERR_BAD_DEVICE,
|
||||
+ N_("Failed to get policy digest (TPM2_PolicyGetDigest: 0x%x)."),
|
||||
+ rc);
|
||||
+
|
||||
+ /* Calculate the digest of the polcy for VerifySignature */
|
||||
+ sig_hash = TPMT_SIGNATURE_get_hash_alg (&signature);
|
||||
+ if (sig_hash == TPM_ALG_NULL)
|
||||
+ return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
+ N_("Failed to get the hash algorithm of the signature"));
|
||||
+
|
||||
+ rc = TPM2_Hash (NULL, (TPM2B_MAX_BUFFER *)&pcr_policy, sig_hash,
|
||||
+ TPM_RH_NULL, &pcr_policy_hash, NULL, NULL);
|
||||
+ if (rc != TPM_RC_SUCCESS)
|
||||
+ return grub_error (GRUB_ERR_BAD_DEVICE,
|
||||
+ N_("Failed to create PCR policy hash (TPM2_Hash: 0x%x)"),
|
||||
+ rc);
|
||||
+
|
||||
+ /* Load the public key */
|
||||
+ rc = TPM2_LoadExternal (NULL, NULL, &pubkey, TPM_RH_OWNER,
|
||||
+ &pubkey_handle, &pubname, NULL);
|
||||
+ if (rc != TPM_RC_SUCCESS)
|
||||
+ return grub_error (GRUB_ERR_BAD_DEVICE,
|
||||
+ N_("Failed to load public key (TPM2_LoadExternal: 0x%x)"),
|
||||
+ rc);
|
||||
+
|
||||
+ /* Verify the signature against the public key and the policy digest */
|
||||
+ rc = TPM2_VerifySignature (pubkey_handle, NULL, &pcr_policy_hash, &signature,
|
||||
+ &verification_ticket, NULL);
|
||||
+ if (rc != TPM_RC_SUCCESS)
|
||||
+ {
|
||||
+ err = grub_error (GRUB_ERR_BAD_DEVICE,
|
||||
+ N_("Failed to verify signature (TPM2_VerifySignature: 0x%x)"),
|
||||
+ rc);
|
||||
+ goto error;
|
||||
+ }
|
||||
+
|
||||
+ /* Authorize the signed policy with the public key and the verification ticket */
|
||||
+ rc = TPM2_PolicyAuthorize (session, NULL, &pcr_policy, &policy_ref, &pubname,
|
||||
+ &verification_ticket, NULL);
|
||||
+ if (rc != TPM_RC_SUCCESS)
|
||||
+ {
|
||||
+ err = grub_error (GRUB_ERR_BAD_DEVICE,
|
||||
+ N_("Failed to authorize PCR policy (TPM2_PolicyAuthorize: 0x%x)"),
|
||||
+ rc);
|
||||
+ goto error;
|
||||
+ }
|
||||
+
|
||||
+ err = GRUB_ERR_NONE;
|
||||
+
|
||||
+error:
|
||||
+ TPM2_FlushContext (pubkey_handle);
|
||||
+
|
||||
+ return err;
|
||||
+}
|
||||
+
|
||||
static grub_err_t
|
||||
grub_tpm2_protector_enforce_policy (tpm2key_policy_t policy, TPMI_SH_AUTH_SESSION session)
|
||||
{
|
||||
@@ -472,6 +553,9 @@ grub_tpm2_protector_enforce_policy (tpm2key_policy_t policy, TPMI_SH_AUTH_SESSIO
|
||||
case TPM_CC_PolicyPCR:
|
||||
err = grub_tpm2_protector_policypcr (session, &buf);
|
||||
break;
|
||||
+ case TPM_CC_PolicyAuthorize:
|
||||
+ err = grub_tpm2_protector_policyauthorize (session, &buf);
|
||||
+ break;
|
||||
default:
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
N_("Unknown TPM Command: 0x%x"), policy->cmd_code);
|
||||
--
|
||||
2.35.3
|
||||
|
||||
@ -1,109 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Matthew Garrett <mjg59@coreos.com>
|
||||
Date: Sun, 9 Aug 2015 16:12:39 -0700
|
||||
Subject: [PATCH] Rework linux command
|
||||
|
||||
We want a single buffer that contains the entire kernel image in order to
|
||||
perform a TPM measurement. Allocate one and copy the entire kernel into it
|
||||
before pulling out the individual blocks later on.
|
||||
|
||||
Signed-off-by: Matthew Garrett <mjg59@coreos.com>
|
||||
---
|
||||
grub-core/loader/i386/linux.c | 35 +++++++++++++++++++++++------------
|
||||
1 file changed, 23 insertions(+), 12 deletions(-)
|
||||
|
||||
diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
|
||||
index 9f74a96b19a..dccf3bb3005 100644
|
||||
--- a/grub-core/loader/i386/linux.c
|
||||
+++ b/grub-core/loader/i386/linux.c
|
||||
@@ -649,13 +649,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
{
|
||||
grub_file_t file = 0;
|
||||
struct linux_i386_kernel_header lh;
|
||||
+ grub_uint8_t *linux_params_ptr;
|
||||
grub_uint8_t setup_sects;
|
||||
- grub_size_t real_size, prot_size, prot_file_size;
|
||||
+ grub_size_t real_size, prot_size, prot_file_size, kernel_offset;
|
||||
grub_ssize_t len;
|
||||
int i;
|
||||
grub_size_t align, min_align;
|
||||
int relocatable;
|
||||
grub_uint64_t preferred_address = GRUB_LINUX_BZIMAGE_ADDR;
|
||||
+ grub_uint8_t *kernel = NULL;
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
|
||||
@@ -669,7 +671,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
- if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
|
||||
+ len = grub_file_size (file);
|
||||
+ kernel = grub_malloc (len);
|
||||
+ if (!kernel)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel buffer"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ if (grub_file_read (file, kernel, len) != len)
|
||||
{
|
||||
if (!grub_errno)
|
||||
grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
||||
@@ -677,6 +687,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
goto fail;
|
||||
}
|
||||
|
||||
+ grub_memcpy (&lh, kernel, sizeof (lh));
|
||||
+ kernel_offset = sizeof (lh);
|
||||
+
|
||||
if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55))
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_OS, "invalid magic number");
|
||||
@@ -784,13 +797,11 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
/* We've already read lh so there is no need to read it second time. */
|
||||
len -= sizeof(lh);
|
||||
|
||||
- if ((len > 0) &&
|
||||
- (grub_file_read (file, (char *) &linux_params + sizeof (lh), len) != len))
|
||||
+ linux_params_ptr = (void *)&linux_params;
|
||||
+ if (len > 0)
|
||||
{
|
||||
- if (!grub_errno)
|
||||
- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
||||
- argv[0]);
|
||||
- goto fail;
|
||||
+ grub_memcpy (linux_params_ptr + sizeof (lh), kernel + kernel_offset, len);
|
||||
+ kernel_offset += len;
|
||||
}
|
||||
|
||||
linux_params.code32_start = prot_mode_target + lh.code32_start - GRUB_LINUX_BZIMAGE_ADDR;
|
||||
@@ -853,7 +864,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
/* The other parameters are filled when booting. */
|
||||
|
||||
- grub_file_seek (file, real_size + GRUB_DISK_SECTOR_SIZE);
|
||||
+ kernel_offset = real_size + GRUB_DISK_SECTOR_SIZE;
|
||||
|
||||
grub_dprintf ("linux", "bzImage, setup=0x%x, size=0x%x\n",
|
||||
(unsigned) real_size, (unsigned) prot_size);
|
||||
@@ -1007,9 +1018,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
}
|
||||
|
||||
len = prot_file_size;
|
||||
- if (grub_file_read (file, prot_mode_mem, len) != len && !grub_errno)
|
||||
- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
||||
- argv[0]);
|
||||
+ grub_memcpy (prot_mode_mem, kernel + kernel_offset, len);
|
||||
|
||||
if (grub_errno == GRUB_ERR_NONE)
|
||||
{
|
||||
@@ -1020,6 +1029,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
fail:
|
||||
|
||||
+ grub_free (kernel);
|
||||
+
|
||||
if (file)
|
||||
grub_file_close (file);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From f7b9580133cf346d77f345d175fa5cb8a591be16 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Axtens <dja@axtens.net>
|
||||
Date: Sat, 15 Aug 2020 02:00:57 +1000
|
||||
Subject: [PATCH] docs/grub: Document signing grub under UEFI
|
||||
Subject: [PATCH 05/23] docs/grub: Document signing grub under UEFI
|
||||
|
||||
Before adding information about how grub is signed with an appended
|
||||
signature scheme, it's worth adding some information about how it
|
||||
@ -12,11 +12,9 @@ Signed-off-by: Daniel Axtens <dja@axtens.net>
|
||||
docs/grub.texi | 22 +++++++++++++++++++++-
|
||||
1 file changed, 21 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/docs/grub.texi b/docs/grub.texi
|
||||
index 4870faaa00a..365d1d6931b 100644
|
||||
--- a/docs/grub.texi
|
||||
+++ b/docs/grub.texi
|
||||
@@ -5817,6 +5817,7 @@ environment variables and commands are listed in the same order.
|
||||
@@ -6345,6 +6345,7 @@
|
||||
* Secure Boot Advanced Targeting:: Embedded information for generation number based revocation
|
||||
* Measured Boot:: Measuring boot components
|
||||
* Lockdown:: Lockdown when booting on a secure setup
|
||||
@ -24,7 +22,7 @@ index 4870faaa00a..365d1d6931b 100644
|
||||
@end menu
|
||||
|
||||
@node Authentication and authorisation
|
||||
@@ -5895,7 +5896,7 @@ commands.
|
||||
@@ -6423,7 +6424,7 @@
|
||||
|
||||
GRUB's @file{core.img} can optionally provide enforcement that all files
|
||||
subsequently read from disk are covered by a valid digital signature.
|
||||
@ -33,7 +31,7 @@ index 4870faaa00a..365d1d6931b 100644
|
||||
platform's firmware (e.g., Coreboot) validates @file{core.img}.
|
||||
|
||||
If environment variable @code{check_signatures}
|
||||
@@ -6067,6 +6068,25 @@ be restricted and some operations/commands cannot be executed.
|
||||
@@ -6586,6 +6587,25 @@
|
||||
The @samp{lockdown} variable is set to @samp{y} when the GRUB is locked down.
|
||||
Otherwise it does not exit.
|
||||
|
||||
164
0005-export-environment-at-start-up.patch
Normal file
164
0005-export-environment-at-start-up.patch
Normal file
@ -0,0 +1,164 @@
|
||||
From 496b6b20cbce3fc27228d1d8290089fb7107b8de Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Fri, 18 Feb 2022 21:51:16 +0800
|
||||
Subject: [PATCH 5/5] export environment at start up
|
||||
|
||||
If the prep_loadenv module is built into the core image, it will read
|
||||
the environment block automatically during start up and export all
|
||||
variables. The will ease integration with those without early scripts to
|
||||
running the command.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/Makefile.core.def | 2 +
|
||||
grub-core/commands/prep_loadenv.c | 77 +++++++++++++++++++++++++++++++
|
||||
grub-core/kern/env.c | 2 +
|
||||
grub-core/kern/main.c | 3 ++
|
||||
include/grub/env.h | 1 +
|
||||
5 files changed, 85 insertions(+)
|
||||
|
||||
--- a/grub-core/Makefile.core.def
|
||||
+++ b/grub-core/Makefile.core.def
|
||||
@@ -2678,4 +2678,6 @@
|
||||
name = prep_loadenv;
|
||||
common = commands/prep_loadenv.c;
|
||||
enable = powerpc_ieee1275;
|
||||
+ cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)';
|
||||
+ cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB)';
|
||||
};
|
||||
--- a/grub-core/commands/prep_loadenv.c
|
||||
+++ b/grub-core/commands/prep_loadenv.c
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <grub/extcmd.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/gpt_partition.h>
|
||||
+#include <regex.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -185,6 +186,65 @@
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
+boot_disk_prep_partname (char **name)
|
||||
+{
|
||||
+ regex_t regex;
|
||||
+ int ret;
|
||||
+ grub_size_t s;
|
||||
+ char *comperr;
|
||||
+ const char *cmdpath;
|
||||
+ regmatch_t *matches = NULL;
|
||||
+ grub_err_t err = GRUB_ERR_NONE;
|
||||
+
|
||||
+ *name = NULL;
|
||||
+
|
||||
+ cmdpath = grub_env_get ("cmdpath");
|
||||
+ if (!cmdpath)
|
||||
+ return GRUB_ERR_NONE;
|
||||
+
|
||||
+ ret = regcomp (®ex, "\\(([^,]+)(,?.*)?\\)(.*)", REG_EXTENDED);
|
||||
+ if (ret)
|
||||
+ goto fail;
|
||||
+
|
||||
+ matches = grub_calloc (regex.re_nsub + 1, sizeof (*matches));
|
||||
+ if (! matches)
|
||||
+ goto fail;
|
||||
+
|
||||
+ ret = regexec (®ex, cmdpath, regex.re_nsub + 1, matches, 0);
|
||||
+ if (!ret)
|
||||
+ {
|
||||
+ char *devname = devname = match_substr (matches + 1, cmdpath);
|
||||
+ if (!devname)
|
||||
+ {
|
||||
+ err = grub_error (GRUB_ERR_FILE_NOT_FOUND, "%s contains no disk name", cmdpath);
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ err = prep_partname (devname, name);
|
||||
+ out:
|
||||
+ grub_free (devname);
|
||||
+ regfree (®ex);
|
||||
+ grub_free (matches);
|
||||
+ return err;
|
||||
+ }
|
||||
+
|
||||
+ fail:
|
||||
+ grub_free (matches);
|
||||
+ s = regerror (ret, ®ex, 0, 0);
|
||||
+ comperr = grub_malloc (s);
|
||||
+ if (!comperr)
|
||||
+ {
|
||||
+ regfree (®ex);
|
||||
+ return grub_errno;
|
||||
+ }
|
||||
+ regerror (ret, ®ex, comperr, s);
|
||||
+ err = grub_error (GRUB_ERR_TEST_FAILURE, "%s", comperr);
|
||||
+ regfree (®ex);
|
||||
+ grub_free (comperr);
|
||||
+ return err;
|
||||
+}
|
||||
+
|
||||
+static grub_err_t
|
||||
grub_cmd_prep_loadenv (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc,
|
||||
char **argv)
|
||||
@@ -214,10 +274,27 @@
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
+static void
|
||||
+early_prep_loadenv (void)
|
||||
+{
|
||||
+ grub_err_t err;
|
||||
+ char *prep;
|
||||
+
|
||||
+ err = boot_disk_prep_partname (&prep);
|
||||
+ if (err == GRUB_ERR_NONE && prep)
|
||||
+ err = prep_read_envblk (prep);
|
||||
+ if (err == GRUB_ERR_BAD_FILE_TYPE || err == GRUB_ERR_FILE_NOT_FOUND)
|
||||
+ grub_error_pop ();
|
||||
+ if (err != GRUB_ERR_NONE)
|
||||
+ grub_print_error ();
|
||||
+ grub_free (prep);
|
||||
+}
|
||||
+
|
||||
static grub_command_t cmd_prep_load;
|
||||
|
||||
GRUB_MOD_INIT(prep_loadenv)
|
||||
{
|
||||
+ early_env_hook = early_prep_loadenv;
|
||||
cmd_prep_load =
|
||||
grub_register_command("prep_load_env", grub_cmd_prep_loadenv,
|
||||
"DEVICE",
|
||||
--- a/grub-core/kern/env.c
|
||||
+++ b/grub-core/kern/env.c
|
||||
@@ -28,6 +28,8 @@
|
||||
/* The current context. */
|
||||
struct grub_env_context *grub_current_context = &initial_context;
|
||||
|
||||
+void (*early_env_hook) (void) = NULL;
|
||||
+
|
||||
/* Return the hash representation of the string S. */
|
||||
static unsigned int
|
||||
grub_env_hashval (const char *s)
|
||||
--- a/grub-core/kern/main.c
|
||||
+++ b/grub-core/kern/main.c
|
||||
@@ -309,6 +309,9 @@
|
||||
|
||||
grub_boot_time ("Before execution of embedded config.");
|
||||
|
||||
+ if (early_env_hook != NULL)
|
||||
+ early_env_hook ();
|
||||
+
|
||||
if (load_config)
|
||||
grub_parser_execute (load_config);
|
||||
|
||||
--- a/include/grub/env.h
|
||||
+++ b/include/grub/env.h
|
||||
@@ -69,5 +69,6 @@
|
||||
grub_err_t
|
||||
grub_env_extractor_close (int source);
|
||||
|
||||
+extern void (*EXPORT_VAR (early_env_hook)) (void);
|
||||
|
||||
#endif /* ! GRUB_ENV_HEADER */
|
||||
@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From 2c997c8c058b41d3a59a81f2bf654288b7cdf8f2 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Tue, 5 May 2015 14:19:24 +0800
|
||||
Subject: [PATCH] grub.texi: Add net_bootp6 doument
|
||||
Subject: [PATCH 5/8] grub.texi: Add net_bootp6 doument
|
||||
|
||||
Update grub documentation for net_bootp6 command.
|
||||
|
||||
@ -11,11 +11,9 @@ Signed-off-by: Ken Lin <ken.lin@hpe.com>
|
||||
docs/grub.texi | 17 +++++++++++++++++
|
||||
1 file changed, 17 insertions(+)
|
||||
|
||||
diff --git a/docs/grub.texi b/docs/grub.texi
|
||||
index 0615d0ed97e..04ed6ac1f07 100644
|
||||
--- a/docs/grub.texi
|
||||
+++ b/docs/grub.texi
|
||||
@@ -5487,6 +5487,7 @@ This command is only available on AArch64 systems.
|
||||
@@ -5894,6 +5894,7 @@
|
||||
* net_add_dns:: Add a DNS server
|
||||
* net_add_route:: Add routing entry
|
||||
* net_bootp:: Perform a bootp/DHCP autoconfiguration
|
||||
@ -23,10 +21,11 @@ index 0615d0ed97e..04ed6ac1f07 100644
|
||||
* net_del_addr:: Remove IP address from interface
|
||||
* net_del_dns:: Remove a DNS server
|
||||
* net_del_route:: Remove a route entry
|
||||
@@ -5611,6 +5612,22 @@ Sets environment variable @samp{net_}@var{<card>}@samp{_boot_file}
|
||||
@@ -5951,6 +5952,24 @@
|
||||
|
||||
@end deffn
|
||||
|
||||
+
|
||||
+@node net_bootp6
|
||||
+@subsection net_bootp6
|
||||
+
|
||||
@ -43,6 +42,7 @@ index 0615d0ed97e..04ed6ac1f07 100644
|
||||
+@end table
|
||||
+
|
||||
+@end deffn
|
||||
+
|
||||
|
||||
@node net_get_dhcp_option
|
||||
@subsection net_get_dhcp_option
|
||||
@node net_del_addr
|
||||
@subsection net_del_addr
|
||||
1620
0005-util-grub-protect-Add-new-tool.patch
Normal file
1620
0005-util-grub-protect-Add-new-tool.patch
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,18 +1,19 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From a33acb675fe0d0464637175e4f06176e4c329025 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Jones <pjones@redhat.com>
|
||||
Date: Fri, 12 Jul 2019 09:53:32 +0200
|
||||
Subject: [PATCH] x86-efi: Use bounce buffers for reading to addresses > 4GB
|
||||
Subject: [PATCH 05/11] x86-efi: Use bounce buffers for reading to addresses >
|
||||
4GB
|
||||
|
||||
Lots of machines apparently can't DMA correctly above 4GB during UEFI,
|
||||
so use bounce buffers for the initramfs read.
|
||||
|
||||
Signed-off-by: Peter Jones <pjones@redhat.com>
|
||||
---
|
||||
grub-core/loader/i386/efi/linux.c | 52 +++++++++++++++++++++++++++++++++------
|
||||
grub-core/loader/i386/efi/linux.c | 52 ++++++++++++++++++++++++++-----
|
||||
1 file changed, 45 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
|
||||
index 33e981e76e7..2f0336809e7 100644
|
||||
index f3abbd025..d6bed4fb4 100644
|
||||
--- a/grub-core/loader/i386/efi/linux.c
|
||||
+++ b/grub-core/loader/i386/efi/linux.c
|
||||
@@ -35,11 +35,16 @@ static grub_dl_t my_mod;
|
||||
@ -33,7 +34,7 @@ index 33e981e76e7..2f0336809e7 100644
|
||||
#define BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> 12)
|
||||
|
||||
static grub_err_t
|
||||
@@ -73,6 +78,44 @@ grub_linuxefi_unload (void)
|
||||
@@ -68,6 +73,44 @@ grub_linuxefi_unload (void)
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
@ -78,7 +79,7 @@ index 33e981e76e7..2f0336809e7 100644
|
||||
static grub_err_t
|
||||
grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char *argv[])
|
||||
@@ -126,7 +169,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -120,7 +163,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
for (i = 0; i < nfiles; i++)
|
||||
{
|
||||
grub_ssize_t cursize = grub_file_size (files[i]);
|
||||
@ -87,7 +88,7 @@ index 33e981e76e7..2f0336809e7 100644
|
||||
{
|
||||
if (!grub_errno)
|
||||
grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
|
||||
@@ -152,11 +195,6 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -145,11 +188,6 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
@ -99,3 +100,6 @@ index 33e981e76e7..2f0336809e7 100644
|
||||
static grub_err_t
|
||||
grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char *argv[])
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,99 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Matthew Garrett <mjg59@coreos.com>
|
||||
Date: Sun, 9 Aug 2015 16:20:58 -0700
|
||||
Subject: [PATCH] Rework linux16 command
|
||||
|
||||
We want a single buffer that contains the entire kernel image in order to
|
||||
perform a TPM measurement. Allocate one and copy the entire kernel int it
|
||||
before pulling out the individual blocks later on.
|
||||
|
||||
Signed-off-by: Matthew Garrett <mjg59@coreos.com>
|
||||
---
|
||||
grub-core/loader/i386/pc/linux.c | 33 +++++++++++++++++++++------------
|
||||
1 file changed, 21 insertions(+), 12 deletions(-)
|
||||
|
||||
diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c
|
||||
index 8be4c3b3f48..4b1750e360e 100644
|
||||
--- a/grub-core/loader/i386/pc/linux.c
|
||||
+++ b/grub-core/loader/i386/pc/linux.c
|
||||
@@ -124,13 +124,14 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
grub_file_t file = 0;
|
||||
struct linux_i386_kernel_header lh;
|
||||
grub_uint8_t setup_sects;
|
||||
- grub_size_t real_size;
|
||||
+ grub_size_t real_size, kernel_offset = 0;
|
||||
grub_ssize_t len;
|
||||
int i;
|
||||
char *grub_linux_prot_chunk;
|
||||
int grub_linux_is_bzimage;
|
||||
grub_addr_t grub_linux_prot_target;
|
||||
grub_err_t err;
|
||||
+ grub_uint8_t *kernel = NULL;
|
||||
|
||||
grub_dl_ref (my_mod);
|
||||
|
||||
@@ -144,7 +145,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
- if (grub_file_read (file, &lh, sizeof (lh)) != sizeof (lh))
|
||||
+ len = grub_file_size (file);
|
||||
+ kernel = grub_malloc (len);
|
||||
+ if (!kernel)
|
||||
+ {
|
||||
+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel buffer"));
|
||||
+ goto fail;
|
||||
+ }
|
||||
+
|
||||
+ if (grub_file_read (file, kernel, len) != len)
|
||||
{
|
||||
if (!grub_errno)
|
||||
grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
||||
@@ -152,6 +161,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
goto fail;
|
||||
}
|
||||
|
||||
+ grub_memcpy (&lh, kernel, sizeof (lh));
|
||||
+ kernel_offset = sizeof (lh);
|
||||
+
|
||||
if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55))
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_OS, "invalid magic number");
|
||||
@@ -320,13 +332,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
grub_memmove (grub_linux_real_chunk, &lh, sizeof (lh));
|
||||
|
||||
len = real_size + GRUB_DISK_SECTOR_SIZE - sizeof (lh);
|
||||
- if (grub_file_read (file, grub_linux_real_chunk + sizeof (lh), len) != len)
|
||||
- {
|
||||
- if (!grub_errno)
|
||||
- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
||||
- argv[0]);
|
||||
- goto fail;
|
||||
- }
|
||||
+ grub_memcpy (grub_linux_real_chunk + sizeof (lh), kernel + kernel_offset,
|
||||
+ len);
|
||||
+ kernel_offset += len;
|
||||
|
||||
if (lh.header != grub_cpu_to_le32_compile_time (GRUB_LINUX_I386_MAGIC_SIGNATURE)
|
||||
|| grub_le_to_cpu16 (lh.version) < 0x0200)
|
||||
@@ -364,9 +372,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
}
|
||||
|
||||
len = grub_linux16_prot_size;
|
||||
- if (grub_file_read (file, grub_linux_prot_chunk, len) != len && !grub_errno)
|
||||
- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
|
||||
- argv[0]);
|
||||
+ grub_memcpy (grub_linux_prot_chunk, kernel + kernel_offset, len);
|
||||
+ kernel_offset += len;
|
||||
|
||||
if (grub_errno == GRUB_ERR_NONE)
|
||||
{
|
||||
@@ -376,6 +383,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
fail:
|
||||
|
||||
+ grub_free (kernel);
|
||||
+
|
||||
if (file)
|
||||
grub_file_close (file);
|
||||
|
||||
@ -0,0 +1,98 @@
|
||||
From 8191aae462f8b755972a0a801f4adbdd6ecaa66c Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Thu, 14 Jul 2016 18:45:14 +0800
|
||||
Subject: [PATCH 6/8] bootp: Add processing DHCPACK packet from HTTP Boot
|
||||
|
||||
The vendor class identifier with the string "HTTPClient" is used to denote the
|
||||
packet as responding to HTTP boot request. In DHCP4 config, the filename for
|
||||
HTTP boot is the URL of the boot file while for PXE boot it is the path to the
|
||||
boot file. As a consequence, the next-server becomes obseleted because the HTTP
|
||||
URL already contains the server address for the boot file. For DHCP6 config,
|
||||
there's no difference definition in existing config as dhcp6.bootfile-url can
|
||||
be used to specify URL for both HTTP and PXE boot file.
|
||||
|
||||
This patch adds processing for "HTTPClient" vendor class identifier in DHCPACK
|
||||
packet by treating it as HTTP format, not as the PXE format.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
Signed-off-by: Ken Lin <ken.lin@hpe.com>
|
||||
---
|
||||
grub-core/net/bootp.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++--
|
||||
include/grub/net.h | 1 +
|
||||
2 files changed, 66 insertions(+), 2 deletions(-)
|
||||
|
||||
--- a/grub-core/net/bootp.c
|
||||
+++ b/grub-core/net/bootp.c
|
||||
@@ -352,6 +352,53 @@
|
||||
if (!inter)
|
||||
return 0;
|
||||
|
||||
+ /* FIXME: Introduce new http flag for better synergy with existing tftp code base */
|
||||
+ if (size > OFFSET_OF (vendor, bp))
|
||||
+ {
|
||||
+ char *cidvar;
|
||||
+ const char *cid;
|
||||
+
|
||||
+ opt = find_dhcp_option (bp, size, GRUB_NET_BOOTP_VENDOR_CLASS_IDENTIFIER, &opt_len);
|
||||
+ if (opt && opt_len)
|
||||
+ grub_env_set_net_property (name, "vendor_class_identifier", (const char *) opt, opt_len);
|
||||
+ cidvar = grub_xasprintf ("net_%s_%s", name, "vendor_class_identifier");
|
||||
+ cid = grub_env_get (cidvar);
|
||||
+ grub_free (cidvar);
|
||||
+
|
||||
+ if (cid && grub_strcmp (cid, "HTTPClient") == 0)
|
||||
+ {
|
||||
+ char *proto, *ip, *pa;
|
||||
+
|
||||
+ /* FIXME: Provide better URL function that returns in place pointers
|
||||
+ * so that we don't have to free them.
|
||||
+ */
|
||||
+ if (!dissect_url (bp->boot_file, &proto, &ip, &pa))
|
||||
+ return inter;
|
||||
+
|
||||
+ if (is_def)
|
||||
+ {
|
||||
+ grub_net_default_server = grub_strdup (ip);
|
||||
+ grub_env_set ("net_default_interface", name);
|
||||
+ grub_env_export ("net_default_interface");
|
||||
+ }
|
||||
+ if (device && !*device)
|
||||
+ {
|
||||
+ *device = grub_xasprintf ("%s,%s", proto, ip);
|
||||
+ grub_print_error ();
|
||||
+ }
|
||||
+
|
||||
+ boot_file = pa;
|
||||
+ boot_file_len = grub_strlen (pa);
|
||||
+
|
||||
+ /* FIXME: Don't use malloc buffer here */
|
||||
+ grub_free (proto);
|
||||
+ grub_free (ip);
|
||||
+
|
||||
+ /* FIXME: NEED TO FREE boot_file */
|
||||
+ goto boot_file;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
opt = find_dhcp_option (bp, size, GRUB_NET_DHCP_OVERLOAD, &opt_len);
|
||||
if (opt && opt_len == 1)
|
||||
overload = *opt;
|
||||
@@ -428,6 +475,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
+boot_file:
|
||||
+
|
||||
if (boot_file)
|
||||
{
|
||||
grub_env_set_net_property (name, "boot_file", boot_file, boot_file_len);
|
||||
--- a/include/grub/net.h
|
||||
+++ b/include/grub/net.h
|
||||
@@ -530,6 +530,7 @@
|
||||
GRUB_NET_DHCP_MESSAGE_TYPE = 53,
|
||||
GRUB_NET_DHCP_SERVER_IDENTIFIER = 54,
|
||||
GRUB_NET_DHCP_PARAMETER_REQUEST_LIST = 55,
|
||||
+ GRUB_NET_BOOTP_VENDOR_CLASS_IDENTIFIER = 60,
|
||||
GRUB_NET_BOOTP_CLIENT_ID = 61,
|
||||
GRUB_NET_DHCP_TFTP_SERVER_NAME = 66,
|
||||
GRUB_NET_DHCP_BOOTFILE_NAME = 67,
|
||||
@ -1,7 +1,8 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From ac539a315495792cd75fe8ab1c474f26e0a78852 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Axtens <dja@axtens.net>
|
||||
Date: Sat, 15 Aug 2020 02:19:36 +1000
|
||||
Subject: [PATCH] docs/grub: Document signing grub with an appended signature
|
||||
Subject: [PATCH 06/23] docs/grub: Document signing grub with an appended
|
||||
signature
|
||||
|
||||
Signing grub for firmware that verifies an appended signature is a
|
||||
bit fiddly. I don't want people to have to figure it out from scratch
|
||||
@ -12,21 +13,19 @@ Signed-off-by: Daniel Axtens <dja@axtens.net>
|
||||
docs/grub.texi | 42 ++++++++++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 42 insertions(+)
|
||||
|
||||
diff --git a/docs/grub.texi b/docs/grub.texi
|
||||
index 365d1d6931b..afbde7c1f7b 100644
|
||||
--- a/docs/grub.texi
|
||||
+++ b/docs/grub.texi
|
||||
@@ -6087,6 +6087,48 @@ image works under UEFI secure boot and can maintain the secure-boot chain. It
|
||||
@@ -6606,6 +6606,48 @@
|
||||
will also be necessary to enrol the public key used into a relevant firmware
|
||||
key database.
|
||||
|
||||
+@section Signing GRUB with an appended signature
|
||||
+
|
||||
+The @file{core.elf} itself can be signed with a Linux kernel module-style
|
||||
+The @file{core.img} itself can be signed with a Linux kernel module-style
|
||||
+appended signature.
|
||||
+
|
||||
+To support IEEE1275 platforms where the boot image is often loaded directly
|
||||
+from a disk partition rather than from a file system, the @file{core.elf}
|
||||
+from a disk partition rather than from a file system, the @file{core.img}
|
||||
+can specify the size and location of the appended signature with an ELF
|
||||
+note added by @command{grub-install}.
|
||||
+
|
||||
@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From 3741c6807923ae97b0d87e61c59c8de8af544484 Mon Sep 17 00:00:00 2001
|
||||
From: Javier Martinez Canillas <javierm@redhat.com>
|
||||
Date: Thu, 23 Apr 2020 15:06:46 +0200
|
||||
Subject: [PATCH] efi: Set image base address before jumping to the PE/COFF
|
||||
Subject: [PATCH 6/9] efi: Set image base address before jumping to the PE/COFF
|
||||
entry point
|
||||
|
||||
Upstream GRUB uses the EFI LoadImage() and StartImage() to boot the Linux
|
||||
@ -21,28 +21,23 @@ and print the following warning message:
|
||||
|
||||
EFI stub: ERROR: FIRMWARE BUG: efi_loaded_image_t::image_base has bogus value
|
||||
|
||||
Resolves: rhbz#1814690
|
||||
Resolves: rhbz#1825411
|
||||
|
||||
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
|
||||
---
|
||||
grub-core/loader/efi/linux.c | 14 ++++++++++++++
|
||||
1 file changed, 14 insertions(+)
|
||||
grub-core/loader/arm64/efi/linux.c | 12 ++++++++++++
|
||||
1 file changed, 12 insertions(+)
|
||||
|
||||
diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
|
||||
index 0622dfa48d4..e8b9ecb17f6 100644
|
||||
--- a/grub-core/loader/efi/linux.c
|
||||
+++ b/grub-core/loader/efi/linux.c
|
||||
@@ -72,6 +72,7 @@ grub_err_t
|
||||
grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset,
|
||||
Index: grub-2.06~rc1/grub-core/loader/arm64/efi/linux.c
|
||||
===================================================================
|
||||
--- grub-2.06~rc1.orig/grub-core/loader/arm64/efi/linux.c
|
||||
+++ grub-2.06~rc1/grub-core/loader/arm64/efi/linux.c
|
||||
@@ -58,9 +58,24 @@ static grub_err_t
|
||||
grub_efi_linux_boot (void *kernel_address, grub_off_t offset,
|
||||
void *kernel_params)
|
||||
{
|
||||
+ grub_efi_loaded_image_t *loaded_image = NULL;
|
||||
handover_func hf;
|
||||
int offset = 0;
|
||||
|
||||
@@ -79,6 +80,19 @@ grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset,
|
||||
offset = 512;
|
||||
#endif
|
||||
|
||||
+ /*
|
||||
+ * Since the EFI loader is not calling the LoadImage() and StartImage()
|
||||
@ -56,7 +51,9 @@ index 0622dfa48d4..e8b9ecb17f6 100644
|
||||
+ grub_dprintf ("linux", "Loaded Image base address could not be set\n");
|
||||
+
|
||||
+ grub_dprintf ("linux", "kernel_addr: %p handover_offset: %p params: %p\n",
|
||||
+ kernel_addr, (void *)(grub_efi_uintn_t)handover_offset, kernel_params);
|
||||
hf = (handover_func)((char *)kernel_addr + handover_offset + offset);
|
||||
+ kernel_address, (void *)(grub_efi_uintn_t)offset, kernel_params);
|
||||
hf = (handover_func)((char *)kernel_address + offset);
|
||||
+ grub_dprintf ("linux", "handover_func() = %p\n", hf);
|
||||
hf (grub_efi_image_handle, grub_efi_system_table, kernel_params);
|
||||
|
||||
return GRUB_ERR_BUG;
|
||||
@ -1,20 +1,20 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From 24b5c0a3788c5c02b72ea61312f5cf8c39429db1 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Jones <pjones@redhat.com>
|
||||
Date: Thu, 13 Sep 2018 14:42:34 -0400
|
||||
Subject: [PATCH] x86-efi: Re-arrange grub_cmd_linux() a little bit.
|
||||
Subject: [PATCH 06/11] x86-efi: Re-arrange grub_cmd_linux() a little bit.
|
||||
|
||||
This just helps the next patch be easier to read.
|
||||
|
||||
Signed-off-by: Peter Jones <pjones@redhat.com>
|
||||
---
|
||||
grub-core/loader/i386/efi/linux.c | 75 +++++++++++++++++++++------------------
|
||||
1 file changed, 41 insertions(+), 34 deletions(-)
|
||||
grub-core/loader/i386/efi/linux.c | 73 +++++++++++++++++--------------
|
||||
1 file changed, 40 insertions(+), 33 deletions(-)
|
||||
|
||||
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
|
||||
index 2f0336809e7..5f48fa55619 100644
|
||||
index d6bed4fb4..096a52eb5 100644
|
||||
--- a/grub-core/loader/i386/efi/linux.c
|
||||
+++ b/grub-core/loader/i386/efi/linux.c
|
||||
@@ -243,32 +243,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -227,32 +227,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -28,13 +28,13 @@ index 2f0336809e7..5f48fa55619 100644
|
||||
- grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate kernel parameters");
|
||||
- goto fail;
|
||||
- }
|
||||
+ lh = (struct linux_i386_kernel_header *)kernel;
|
||||
+ grub_dprintf ("linux", "original lh is at %p\n", kernel);
|
||||
|
||||
-
|
||||
- grub_dprintf ("linux", "params = %p\n", params);
|
||||
-
|
||||
- grub_memset (params, 0, sizeof(*params));
|
||||
-
|
||||
+ lh = (struct linux_i386_kernel_header *)kernel;
|
||||
+ grub_dprintf ("linux", "original lh is at %p\n", kernel);
|
||||
|
||||
- setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201);
|
||||
- grub_dprintf ("linux", "copying %lu bytes from %p to %p\n",
|
||||
- MIN((grub_size_t)0x202+setup_header_end_offset,
|
||||
@ -49,7 +49,7 @@ index 2f0336809e7..5f48fa55619 100644
|
||||
grub_dprintf ("linux", "checking lh->boot_flag\n");
|
||||
if (lh->boot_flag != grub_cpu_to_le16 (0xaa55))
|
||||
{
|
||||
@@ -316,6 +293,34 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -300,6 +277,34 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -69,7 +69,7 @@ index 2f0336809e7..5f48fa55619 100644
|
||||
+ grub_memset (params, 0, sizeof(*params));
|
||||
+
|
||||
+ setup_header_end_offset = *((grub_uint8_t *)kernel + 0x201);
|
||||
+ grub_dprintf ("linux", "copying %lu bytes from %p to %p\n",
|
||||
+ grub_dprintf ("linux", "copying %" PRIuGRUB_SIZE " bytes from %p to %p\n",
|
||||
+ MIN((grub_size_t)0x202+setup_header_end_offset,
|
||||
+ sizeof (*params)) - 0x1f1,
|
||||
+ (grub_uint8_t *)kernel + 0x1f1,
|
||||
@ -84,7 +84,7 @@ index 2f0336809e7..5f48fa55619 100644
|
||||
grub_dprintf ("linux", "setting up cmdline\n");
|
||||
linux_cmdline = grub_efi_allocate_pages_max(GRUB_EFI_MAX_ALLOCATION_ADDRESS,
|
||||
BYTES_TO_PAGES(lh->cmdline_size + 1));
|
||||
@@ -341,8 +346,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -324,8 +329,8 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
grub_dprintf ("linux", "setting lh->cmd_line_ptr\n");
|
||||
lh->cmd_line_ptr = (grub_uint32_t)(grub_addr_t)linux_cmdline;
|
||||
|
||||
@ -94,7 +94,7 @@ index 2f0336809e7..5f48fa55619 100644
|
||||
|
||||
start = (lh->setup_sects + 1) * 512;
|
||||
|
||||
@@ -359,26 +364,28 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -342,24 +347,26 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate kernel"));
|
||||
goto fail;
|
||||
}
|
||||
@ -126,8 +126,8 @@ index 2f0336809e7..5f48fa55619 100644
|
||||
+ "setting lh->ext_loader_{type,ver} = {0x%02x,0x%02x}\n",
|
||||
+ params->ext_loader_type, params->ext_loader_ver);
|
||||
|
||||
- fail:
|
||||
+fail:
|
||||
if (file)
|
||||
grub_file_close (file);
|
||||
fail:
|
||||
|
||||
--
|
||||
2.31.1
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,8 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From 4773f90bdefb72dde55fb5961f7f37b467307016 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Axtens <dja@axtens.net>
|
||||
Date: Thu, 30 Jul 2020 00:13:21 +1000
|
||||
Subject: [PATCH] dl: provide a fake grub_dl_set_persistent for the emu target
|
||||
Subject: [PATCH 07/23] dl: provide a fake grub_dl_set_persistent for the emu
|
||||
target
|
||||
|
||||
Trying to start grub-emu with a module that calls grub_dl_set_persistent
|
||||
will crash because grub-emu fakes modules and passes NULL to the module
|
||||
@ -15,11 +16,9 @@ Signed-off-by: Daniel Axtens <dja@axtens.net>
|
||||
include/grub/dl.h | 11 +++++++++++
|
||||
1 file changed, 11 insertions(+)
|
||||
|
||||
diff --git a/include/grub/dl.h b/include/grub/dl.h
|
||||
index 2f76e6b0437..20d870f2a47 100644
|
||||
--- a/include/grub/dl.h
|
||||
+++ b/include/grub/dl.h
|
||||
@@ -245,11 +245,22 @@ grub_dl_get (const char *name)
|
||||
@@ -242,11 +242,22 @@
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From 369df8e3006000a4acacc674f5882d8729781811 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Sun, 10 Jul 2016 23:46:31 +0800
|
||||
Subject: [PATCH] efinet: Setting network from UEFI device path
|
||||
Subject: [PATCH 7/8] efinet: Setting network from UEFI device path
|
||||
|
||||
The PXE Base Code protocol used to obtain cached PXE DHCPACK packet is no
|
||||
longer provided for HTTP Boot. Instead, we have to get the HTTP boot
|
||||
@ -27,23 +27,21 @@ the same way it used to be.
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
Signed-off-by: Ken Lin <ken.lin@hpe.com>
|
||||
---
|
||||
grub-core/net/drivers/efi/efinet.c | 284 +++++++++++++++++++++++++++++++++++--
|
||||
grub-core/net/drivers/efi/efinet.c | 268 +++++++++++++++++++++++++++++++++++--
|
||||
include/grub/efi/api.h | 11 ++
|
||||
2 files changed, 280 insertions(+), 15 deletions(-)
|
||||
2 files changed, 270 insertions(+), 9 deletions(-)
|
||||
|
||||
diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c
|
||||
index 014e5bf9802..8171ecaa5e4 100644
|
||||
--- a/grub-core/net/drivers/efi/efinet.c
|
||||
+++ b/grub-core/net/drivers/efi/efinet.c
|
||||
@@ -26,6 +26,7 @@
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <grub/efi/api.h>
|
||||
#include <grub/efi/efi.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/lib/hexdump.h>
|
||||
#include <grub/types.h>
|
||||
+#include <grub/net/netbuff.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -331,6 +332,227 @@ grub_efinet_findcards (void)
|
||||
@@ -341,6 +342,221 @@
|
||||
grub_free (handles);
|
||||
}
|
||||
|
||||
@ -57,9 +55,6 @@ index 014e5bf9802..8171ecaa5e4 100644
|
||||
+ grub_err_t err;
|
||||
+
|
||||
+ ddp = grub_efi_duplicate_device_path (dp);
|
||||
+ if (!ddp)
|
||||
+ return NULL;
|
||||
+
|
||||
+ ldp = grub_efi_find_last_device_path (ddp);
|
||||
+
|
||||
+ if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE
|
||||
@ -95,10 +90,7 @@ index 014e5bf9802..8171ecaa5e4 100644
|
||||
+
|
||||
+ nb = grub_netbuff_alloc (512);
|
||||
+ if (!nb)
|
||||
+ {
|
||||
+ grub_free (ddp);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ return NULL;
|
||||
+
|
||||
+ if (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) == GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE)
|
||||
+ {
|
||||
@ -271,21 +263,20 @@ index 014e5bf9802..8171ecaa5e4 100644
|
||||
static void
|
||||
grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
|
||||
char **path)
|
||||
@@ -346,7 +568,11 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
|
||||
{
|
||||
@@ -361,6 +577,11 @@
|
||||
grub_efi_device_path_t *cdp;
|
||||
struct grub_efi_pxe *pxe;
|
||||
- struct grub_efi_pxe_mode *pxe_mode;
|
||||
+ struct grub_efi_pxe_mode *pxe_mode = NULL;
|
||||
struct grub_efi_pxe_mode *pxe_mode;
|
||||
+ grub_uint8_t *packet_buf;
|
||||
+ grub_size_t packet_bufsz ;
|
||||
+ int ipv6;
|
||||
+ struct grub_net_buff *nb = NULL;
|
||||
|
||||
+
|
||||
if (card->driver != &efidriver)
|
||||
continue;
|
||||
@@ -370,11 +596,21 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
|
||||
*/
|
||||
cdp = grub_efi_get_device_path (card->efi_handle);
|
||||
@@ -380,11 +601,21 @@
|
||||
ldp = grub_efi_find_last_device_path (dp);
|
||||
if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) != GRUB_EFI_MESSAGING_DEVICE_PATH_TYPE
|
||||
|| (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV4_DEVICE_PATH_SUBTYPE
|
||||
- && GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) != GRUB_EFI_IPV6_DEVICE_PATH_SUBTYPE))
|
||||
@ -307,12 +298,13 @@ index 014e5bf9802..8171ecaa5e4 100644
|
||||
dup_ldp = grub_efi_find_last_device_path (dup_dp);
|
||||
dup_ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE;
|
||||
dup_ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
|
||||
@@ -387,23 +623,37 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
|
||||
|
||||
@@ -396,16 +627,31 @@
|
||||
}
|
||||
pxe = grub_efi_open_protocol (hnd, &pxe_io_guid,
|
||||
GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL);
|
||||
- if (! pxe)
|
||||
- continue;
|
||||
- pxe_mode = pxe->mode;
|
||||
+ if (!pxe)
|
||||
+ {
|
||||
+ nb = grub_efinet_create_dhcp_ack_from_device_path (dp, &ipv6);
|
||||
@ -332,21 +324,9 @@ index 014e5bf9802..8171ecaa5e4 100644
|
||||
+ ipv6 = pxe_mode->using_ipv6;
|
||||
+ }
|
||||
|
||||
- pxe_mode = pxe->mode;
|
||||
- if (pxe_mode->using_ipv6)
|
||||
+ if (ipv6)
|
||||
{
|
||||
grub_dprintf ("efinet", "using ipv6 and dhcpv6\n");
|
||||
- grub_dprintf ("efinet", "dhcp_ack_received: %s%s\n",
|
||||
- pxe_mode->dhcp_ack_received ? "yes" : "no",
|
||||
- pxe_mode->dhcp_ack_received ? "" : " cannot continue");
|
||||
- if (!pxe_mode->dhcp_ack_received)
|
||||
- continue;
|
||||
+ if (pxe_mode)
|
||||
+ grub_dprintf ("efinet", "dhcp_ack_received: %s%s\n",
|
||||
+ pxe_mode->dhcp_ack_received ? "yes" : "no",
|
||||
+ pxe_mode->dhcp_ack_received ? "" : " cannot continue");
|
||||
|
||||
grub_net_configure_by_dhcpv6_reply (card->name, card, 0,
|
||||
(struct grub_net_dhcp6_packet *)
|
||||
- &pxe_mode->dhcp_ack,
|
||||
@ -356,16 +336,20 @@ index 014e5bf9802..8171ecaa5e4 100644
|
||||
1, device, path);
|
||||
if (grub_errno)
|
||||
grub_print_error ();
|
||||
@@ -417,11 +667,15 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
|
||||
grub_dprintf ("efinet", "using ipv4 and dhcp\n");
|
||||
grub_net_configure_by_dhcp_ack (card->name, card, 0,
|
||||
(struct grub_net_bootp_packet *)
|
||||
- &pxe_mode->dhcp_ack,
|
||||
- sizeof (pxe_mode->dhcp_ack),
|
||||
+ packet_buf,
|
||||
+ packet_bufsz,
|
||||
1, device, path);
|
||||
grub_dprintf ("efinet", "device: `%s' path: `%s'\n", *device, *path);
|
||||
@@ -414,8 +660,8 @@
|
||||
{
|
||||
inter = grub_net_configure_by_dhcp_ack (card->name, card, 0,
|
||||
(struct grub_net_bootp_packet *)
|
||||
- &pxe_mode->dhcp_ack,
|
||||
- sizeof (pxe_mode->dhcp_ack),
|
||||
+ packet_buf,
|
||||
+ packet_bufsz,
|
||||
1, device, path);
|
||||
|
||||
if (inter != NULL)
|
||||
@@ -441,6 +687,10 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
+
|
||||
+ if (nb)
|
||||
@ -374,11 +358,9 @@ index 014e5bf9802..8171ecaa5e4 100644
|
||||
return;
|
||||
}
|
||||
}
|
||||
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
|
||||
index 91ab528e4d0..4a51667adb1 100644
|
||||
--- a/include/grub/efi/api.h
|
||||
+++ b/include/grub/efi/api.h
|
||||
@@ -864,6 +864,8 @@ struct grub_efi_ipv4_device_path
|
||||
@@ -876,6 +876,8 @@
|
||||
grub_efi_uint16_t remote_port;
|
||||
grub_efi_uint16_t protocol;
|
||||
grub_efi_uint8_t static_ip_address;
|
||||
@ -387,9 +369,9 @@ index 91ab528e4d0..4a51667adb1 100644
|
||||
} GRUB_PACKED;
|
||||
typedef struct grub_efi_ipv4_device_path grub_efi_ipv4_device_path_t;
|
||||
|
||||
@@ -918,6 +920,15 @@ struct grub_efi_sata_device_path
|
||||
@@ -939,6 +941,15 @@
|
||||
} GRUB_PACKED;
|
||||
typedef struct grub_efi_sata_device_path grub_efi_sata_device_path_t;
|
||||
typedef struct grub_efi_vlan_device_path grub_efi_vlan_device_path_t;
|
||||
|
||||
+#define GRUB_EFI_URI_DEVICE_PATH_SUBTYPE 24
|
||||
+
|
||||
@ -1,17 +1,17 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From 2a84f1a50c6f8770808fd4ec590eb8cff4228aed Mon Sep 17 00:00:00 2001
|
||||
From: Peter Jones <pjones@redhat.com>
|
||||
Date: Wed, 12 Sep 2018 16:03:55 -0400
|
||||
Subject: [PATCH] x86-efi: Make our own allocator for kernel stuff
|
||||
Subject: [PATCH 07/11] x86-efi: Make our own allocator for kernel stuff
|
||||
|
||||
This helps enable allocations above 4GB.
|
||||
|
||||
Signed-off-by: Peter Jones <pjones@redhat.com>
|
||||
---
|
||||
grub-core/loader/i386/efi/linux.c | 167 +++++++++++++++++++++-----------------
|
||||
1 file changed, 94 insertions(+), 73 deletions(-)
|
||||
grub-core/loader/i386/efi/linux.c | 155 ++++++++++++++++++------------
|
||||
1 file changed, 94 insertions(+), 61 deletions(-)
|
||||
|
||||
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
|
||||
index 5f48fa55619..3e4f7ef39f4 100644
|
||||
index 096a52eb5..d284db5d1 100644
|
||||
--- a/grub-core/loader/i386/efi/linux.c
|
||||
+++ b/grub-core/loader/i386/efi/linux.c
|
||||
@@ -47,6 +47,65 @@ static char *linux_cmdline;
|
||||
@ -55,8 +55,8 @@ index 5f48fa55619..3e4f7ef39f4 100644
|
||||
+ continue;
|
||||
+
|
||||
+ pages = BYTES_TO_PAGES(size);
|
||||
+ grub_dprintf ("linux", "Trying to allocate %lu pages from %p\n",
|
||||
+ pages, (void *)max);
|
||||
+ grub_dprintf ("linux", "Trying to allocate %" PRIuGRUB_SIZE" pages from %p\n",
|
||||
+ pages, (void *)(grub_addr_t)max);
|
||||
+
|
||||
+ prev_max = max;
|
||||
+ addr = grub_efi_allocate_pages_real (max, pages,
|
||||
@ -80,23 +80,18 @@ index 5f48fa55619..3e4f7ef39f4 100644
|
||||
static grub_err_t
|
||||
grub_linuxefi_boot (void)
|
||||
{
|
||||
@@ -62,19 +121,12 @@ grub_linuxefi_unload (void)
|
||||
@@ -62,14 +121,12 @@ grub_linuxefi_unload (void)
|
||||
{
|
||||
grub_dl_unref (my_mod);
|
||||
loaded = 0;
|
||||
- if (initrd_mem)
|
||||
- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)initrd_mem,
|
||||
- BYTES_TO_PAGES(params->ramdisk_size));
|
||||
- grub_efi_free_pages((grub_efi_physical_address_t)(grub_addr_t)initrd_mem, BYTES_TO_PAGES(params->ramdisk_size));
|
||||
- if (linux_cmdline)
|
||||
- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)
|
||||
- linux_cmdline,
|
||||
- BYTES_TO_PAGES(params->cmdline_size + 1));
|
||||
- grub_efi_free_pages((grub_efi_physical_address_t)(grub_addr_t)linux_cmdline, BYTES_TO_PAGES(params->cmdline_size + 1));
|
||||
- if (kernel_mem)
|
||||
- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem,
|
||||
- BYTES_TO_PAGES(kernel_size));
|
||||
- grub_efi_free_pages((grub_efi_physical_address_t)(grub_addr_t)kernel_mem, BYTES_TO_PAGES(kernel_size));
|
||||
- if (params)
|
||||
- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params,
|
||||
- BYTES_TO_PAGES(16384));
|
||||
- grub_efi_free_pages((grub_efi_physical_address_t)(grub_addr_t)params, BYTES_TO_PAGES(16384));
|
||||
+
|
||||
+ kernel_free(initrd_mem, params->ramdisk_size);
|
||||
+ kernel_free(linux_cmdline, params->cmdline_size + 1);
|
||||
@ -106,7 +101,7 @@ index 5f48fa55619..3e4f7ef39f4 100644
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
@@ -150,19 +202,13 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -146,17 +203,13 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
size += ALIGN_UP (grub_file_size (files[i]), 4);
|
||||
}
|
||||
|
||||
@ -118,8 +113,6 @@ index 5f48fa55619..3e4f7ef39f4 100644
|
||||
- grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate initrd"));
|
||||
- goto fail;
|
||||
- }
|
||||
-
|
||||
- grub_dprintf ("linux", "initrd_mem = %lx\n", (unsigned long) initrd_mem);
|
||||
+ initrd_mem = kernel_alloc(size, N_("can't allocate initrd"));
|
||||
+ if (initrd_mem == NULL)
|
||||
+ goto fail;
|
||||
@ -131,7 +124,7 @@ index 5f48fa55619..3e4f7ef39f4 100644
|
||||
|
||||
ptr = initrd_mem;
|
||||
|
||||
@@ -221,7 +267,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -214,7 +267,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
filelen = grub_file_size (file);
|
||||
|
||||
kernel = grub_malloc(filelen);
|
||||
@ -139,7 +132,7 @@ index 5f48fa55619..3e4f7ef39f4 100644
|
||||
if (!kernel)
|
||||
{
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate kernel buffer"));
|
||||
@@ -274,7 +319,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -258,7 +310,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -148,7 +141,7 @@ index 5f48fa55619..3e4f7ef39f4 100644
|
||||
grub_dprintf ("linux", "checking lh->xloadflags\n");
|
||||
if (!(lh->xloadflags & LINUX_XLF_KERNEL_64))
|
||||
{
|
||||
@@ -293,17 +338,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -277,17 +329,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -168,7 +161,7 @@ index 5f48fa55619..3e4f7ef39f4 100644
|
||||
grub_dprintf ("linux", "params = %p\n", params);
|
||||
|
||||
grub_memset (params, 0, sizeof(*params));
|
||||
@@ -322,19 +359,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -306,16 +350,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
grub_dprintf ("linux", "new lh is at %p\n", lh);
|
||||
|
||||
grub_dprintf ("linux", "setting up cmdline\n");
|
||||
@ -183,16 +176,13 @@ index 5f48fa55619..3e4f7ef39f4 100644
|
||||
- grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("can't allocate cmdline"));
|
||||
- goto fail;
|
||||
- }
|
||||
-
|
||||
- grub_dprintf ("linux", "linux_cmdline = %lx\n",
|
||||
- (unsigned long)linux_cmdline);
|
||||
+ goto fail;
|
||||
+ grub_dprintf ("linux", "linux_cmdline = %p\n", linux_cmdline);
|
||||
|
||||
grub_memcpy (linux_cmdline, LINUX_IMAGE, sizeof (LINUX_IMAGE));
|
||||
grub_create_loader_cmdline (argc, argv,
|
||||
@@ -343,27 +371,24 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
GRUB_VERIFY_KERNEL_CMDLINE);
|
||||
err = grub_create_loader_cmdline (argc, argv,
|
||||
@@ -326,27 +364,24 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
goto fail;
|
||||
|
||||
grub_dprintf ("linux", "cmdline:%s\n", linux_cmdline);
|
||||
- grub_dprintf ("linux", "setting lh->cmd_line_ptr\n");
|
||||
@ -230,7 +220,7 @@ index 5f48fa55619..3e4f7ef39f4 100644
|
||||
grub_dprintf("linux", "kernel_mem = %p\n", kernel_mem);
|
||||
|
||||
grub_loader_set (grub_linuxefi_boot, grub_linuxefi_unload, 0);
|
||||
@@ -398,18 +423,14 @@ fail:
|
||||
@@ -382,16 +417,14 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
loaded = 0;
|
||||
}
|
||||
|
||||
@ -238,21 +228,22 @@ index 5f48fa55619..3e4f7ef39f4 100644
|
||||
- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)
|
||||
- linux_cmdline,
|
||||
- BYTES_TO_PAGES(lh->cmdline_size + 1));
|
||||
-
|
||||
- if (kernel_mem && !loaded)
|
||||
- grub_efi_free_pages((grub_efi_physical_address_t)(grub_addr_t)kernel_mem, BYTES_TO_PAGES(kernel_size));
|
||||
+ if (!loaded)
|
||||
+ {
|
||||
+ if (lh)
|
||||
+ kernel_free (linux_cmdline, lh->cmdline_size + 1);
|
||||
|
||||
- if (kernel_mem && !loaded)
|
||||
- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)kernel_mem,
|
||||
- BYTES_TO_PAGES(kernel_size));
|
||||
-
|
||||
- if (params && !loaded)
|
||||
- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_addr_t)params,
|
||||
- BYTES_TO_PAGES(16384));
|
||||
- grub_efi_free_pages((grub_efi_physical_address_t)(grub_addr_t)params, BYTES_TO_PAGES(16384));
|
||||
+ kernel_free (kernel_mem, kernel_size);
|
||||
+ kernel_free (params, sizeof(*params));
|
||||
+ }
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
--
|
||||
2.31.1
|
||||
|
||||
@ -1,390 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Jones <pjones@redhat.com>
|
||||
Date: Tue, 6 Oct 2015 16:09:25 -0400
|
||||
Subject: [PATCH] Make any of the loaders that link in efi mode honor secure
|
||||
boot.
|
||||
|
||||
And in this case "honor" means "even if somebody does link this in, they
|
||||
won't register commands if SB is enabled."
|
||||
|
||||
Signed-off-by: Peter Jones <pjones@redhat.com>
|
||||
---
|
||||
grub-core/commands/iorw.c | 7 +++++++
|
||||
grub-core/commands/memrw.c | 7 +++++++
|
||||
grub-core/kern/dl.c | 3 ++-
|
||||
grub-core/kern/efi/efi.c | 34 ----------------------------------
|
||||
grub-core/loader/efi/appleloader.c | 7 +++++++
|
||||
grub-core/loader/efi/chainloader.c | 1 +
|
||||
grub-core/loader/i386/bsd.c | 7 +++++++
|
||||
grub-core/loader/i386/linux.c | 7 +++++++
|
||||
grub-core/loader/i386/pc/linux.c | 7 +++++++
|
||||
grub-core/loader/multiboot.c | 7 +++++++
|
||||
grub-core/loader/xnu.c | 7 +++++++
|
||||
include/grub/efi/efi.h | 1 -
|
||||
include/grub/ia64/linux.h | 0
|
||||
include/grub/mips/linux.h | 0
|
||||
include/grub/powerpc/linux.h | 0
|
||||
include/grub/sparc64/linux.h | 0
|
||||
16 files changed, 59 insertions(+), 36 deletions(-)
|
||||
create mode 100644 include/grub/ia64/linux.h
|
||||
create mode 100644 include/grub/mips/linux.h
|
||||
create mode 100644 include/grub/powerpc/linux.h
|
||||
create mode 100644 include/grub/sparc64/linux.h
|
||||
|
||||
diff --git a/grub-core/commands/iorw.c b/grub-core/commands/iorw.c
|
||||
index 584baec8f91..7b2999b14b5 100644
|
||||
--- a/grub-core/commands/iorw.c
|
||||
+++ b/grub-core/commands/iorw.c
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <grub/cpu/io.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/lockdown.h>
|
||||
+#include <grub/efi/sb.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -119,6 +120,9 @@ grub_cmd_write (grub_command_t cmd, int argc, char **argv)
|
||||
|
||||
GRUB_MOD_INIT(memrw)
|
||||
{
|
||||
+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
+ return;
|
||||
+
|
||||
cmd_read_byte =
|
||||
grub_register_extcmd ("inb", grub_cmd_read, 0,
|
||||
N_("PORT"), N_("Read 8-bit value from PORT."),
|
||||
@@ -147,6 +151,9 @@ GRUB_MOD_INIT(memrw)
|
||||
|
||||
GRUB_MOD_FINI(memrw)
|
||||
{
|
||||
+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
+ return;
|
||||
+
|
||||
grub_unregister_extcmd (cmd_read_byte);
|
||||
grub_unregister_extcmd (cmd_read_word);
|
||||
grub_unregister_extcmd (cmd_read_dword);
|
||||
diff --git a/grub-core/commands/memrw.c b/grub-core/commands/memrw.c
|
||||
index d401a6db0ef..39cf3a06dbd 100644
|
||||
--- a/grub-core/commands/memrw.c
|
||||
+++ b/grub-core/commands/memrw.c
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <grub/env.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/lockdown.h>
|
||||
+#include <grub/efi/sb.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -121,6 +122,9 @@ grub_cmd_write (grub_command_t cmd, int argc, char **argv)
|
||||
|
||||
GRUB_MOD_INIT(memrw)
|
||||
{
|
||||
+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
+ return;
|
||||
+
|
||||
cmd_read_byte =
|
||||
grub_register_extcmd ("read_byte", grub_cmd_read, 0,
|
||||
N_("ADDR"), N_("Read 8-bit value from ADDR."),
|
||||
@@ -149,6 +153,9 @@ GRUB_MOD_INIT(memrw)
|
||||
|
||||
GRUB_MOD_FINI(memrw)
|
||||
{
|
||||
+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
+ return;
|
||||
+
|
||||
grub_unregister_extcmd (cmd_read_byte);
|
||||
grub_unregister_extcmd (cmd_read_word);
|
||||
grub_unregister_extcmd (cmd_read_dword);
|
||||
diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c
|
||||
index b7149370950..7afb9e6f724 100644
|
||||
--- a/grub-core/kern/dl.c
|
||||
+++ b/grub-core/kern/dl.c
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <grub/env.h>
|
||||
#include <grub/cache.h>
|
||||
#include <grub/i18n.h>
|
||||
+#include <grub/efi/sb.h>
|
||||
|
||||
/* Platforms where modules are in a readonly area of memory. */
|
||||
#if defined(GRUB_MACHINE_QEMU)
|
||||
@@ -704,7 +705,7 @@ grub_dl_load_file (const char *filename)
|
||||
grub_dl_t mod = 0;
|
||||
|
||||
#ifdef GRUB_MACHINE_EFI
|
||||
- if (grub_efi_secure_boot ())
|
||||
+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
{
|
||||
#if 0
|
||||
/* This is an error, but grub2-mkconfig still generates a pile of
|
||||
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
|
||||
index 4a2259aa1c7..8cff7be0289 100644
|
||||
--- a/grub-core/kern/efi/efi.c
|
||||
+++ b/grub-core/kern/efi/efi.c
|
||||
@@ -286,40 +286,6 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
|
||||
return grub_efi_get_variable_with_attributes (var, guid, datasize_out, data_out, NULL);
|
||||
}
|
||||
|
||||
-grub_efi_boolean_t
|
||||
-grub_efi_secure_boot (void)
|
||||
-{
|
||||
- grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
|
||||
- grub_size_t datasize;
|
||||
- char *secure_boot = NULL;
|
||||
- char *setup_mode = NULL;
|
||||
- grub_efi_boolean_t ret = 0;
|
||||
-
|
||||
- secure_boot = grub_efi_get_variable("SecureBoot", &efi_var_guid, &datasize);
|
||||
- if (datasize != 1 || !secure_boot)
|
||||
- {
|
||||
- grub_dprintf ("secureboot", "No SecureBoot variable\n");
|
||||
- goto out;
|
||||
- }
|
||||
- grub_dprintf ("secureboot", "SecureBoot: %d\n", *secure_boot);
|
||||
-
|
||||
- setup_mode = grub_efi_get_variable("SetupMode", &efi_var_guid, &datasize);
|
||||
- if (datasize != 1 || !setup_mode)
|
||||
- {
|
||||
- grub_dprintf ("secureboot", "No SetupMode variable\n");
|
||||
- goto out;
|
||||
- }
|
||||
- grub_dprintf ("secureboot", "SetupMode: %d\n", *setup_mode);
|
||||
-
|
||||
- if (*secure_boot && !*setup_mode)
|
||||
- ret = 1;
|
||||
-
|
||||
- out:
|
||||
- grub_free (secure_boot);
|
||||
- grub_free (setup_mode);
|
||||
- return ret;
|
||||
-}
|
||||
-
|
||||
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||
|
||||
/* Search the mods section from the PE32/PE32+ image. This code uses
|
||||
diff --git a/grub-core/loader/efi/appleloader.c b/grub-core/loader/efi/appleloader.c
|
||||
index 74888c463ba..585f2b57385 100644
|
||||
--- a/grub-core/loader/efi/appleloader.c
|
||||
+++ b/grub-core/loader/efi/appleloader.c
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <grub/misc.h>
|
||||
#include <grub/efi/api.h>
|
||||
#include <grub/efi/efi.h>
|
||||
+#include <grub/efi/sb.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
@@ -227,6 +228,9 @@ static grub_command_t cmd;
|
||||
|
||||
GRUB_MOD_INIT(appleloader)
|
||||
{
|
||||
+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
+ return;
|
||||
+
|
||||
cmd = grub_register_command ("appleloader", grub_cmd_appleloader,
|
||||
N_("[OPTS]"),
|
||||
/* TRANSLATORS: This command is used on EFI to
|
||||
@@ -238,5 +242,8 @@ GRUB_MOD_INIT(appleloader)
|
||||
|
||||
GRUB_MOD_FINI(appleloader)
|
||||
{
|
||||
+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
+ return;
|
||||
+
|
||||
grub_unregister_command (cmd);
|
||||
}
|
||||
diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
|
||||
index e6a8d4ad0e9..07c4937898d 100644
|
||||
--- a/grub-core/loader/efi/chainloader.c
|
||||
+++ b/grub-core/loader/efi/chainloader.c
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <grub/efi/disk.h>
|
||||
#include <grub/efi/pe32.h>
|
||||
#include <grub/efi/linux.h>
|
||||
+#include <grub/efi/sb.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/net.h>
|
||||
diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c
|
||||
index 5f3290ce17b..54befc26626 100644
|
||||
--- a/grub-core/loader/i386/bsd.c
|
||||
+++ b/grub-core/loader/i386/bsd.c
|
||||
@@ -40,6 +40,7 @@
|
||||
#ifdef GRUB_MACHINE_PCBIOS
|
||||
#include <grub/machine/int.h>
|
||||
#endif
|
||||
+#include <grub/efi/sb.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -2137,6 +2138,9 @@ static grub_command_t cmd_netbsd_module_elf, cmd_openbsd_ramdisk;
|
||||
|
||||
GRUB_MOD_INIT (bsd)
|
||||
{
|
||||
+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
+ return;
|
||||
+
|
||||
/* Net and OpenBSD kernels are often compressed. */
|
||||
grub_dl_load ("gzio");
|
||||
|
||||
@@ -2176,6 +2180,9 @@ GRUB_MOD_INIT (bsd)
|
||||
|
||||
GRUB_MOD_FINI (bsd)
|
||||
{
|
||||
+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
+ return;
|
||||
+
|
||||
grub_unregister_extcmd (cmd_freebsd);
|
||||
grub_unregister_extcmd (cmd_openbsd);
|
||||
grub_unregister_extcmd (cmd_netbsd);
|
||||
diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
|
||||
index dccf3bb3005..4aeb0e4b9a6 100644
|
||||
--- a/grub-core/loader/i386/linux.c
|
||||
+++ b/grub-core/loader/i386/linux.c
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <grub/linux.h>
|
||||
#include <grub/machine/kernel.h>
|
||||
#include <grub/safemath.h>
|
||||
+#include <grub/efi/sb.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -1138,6 +1139,9 @@ static grub_command_t cmd_linux, cmd_initrd;
|
||||
|
||||
GRUB_MOD_INIT(linux)
|
||||
{
|
||||
+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
+ return;
|
||||
+
|
||||
cmd_linux = grub_register_command ("linux", grub_cmd_linux,
|
||||
0, N_("Load Linux."));
|
||||
cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd,
|
||||
@@ -1147,6 +1151,9 @@ GRUB_MOD_INIT(linux)
|
||||
|
||||
GRUB_MOD_FINI(linux)
|
||||
{
|
||||
+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
+ return;
|
||||
+
|
||||
grub_unregister_command (cmd_linux);
|
||||
grub_unregister_command (cmd_initrd);
|
||||
}
|
||||
diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c
|
||||
index 4b1750e360e..e3fa1221e81 100644
|
||||
--- a/grub-core/loader/i386/pc/linux.c
|
||||
+++ b/grub-core/loader/i386/pc/linux.c
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <grub/lib/cmdline.h>
|
||||
#include <grub/linux.h>
|
||||
#include <grub/safemath.h>
|
||||
+#include <grub/efi/sb.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -487,6 +488,9 @@ static grub_command_t cmd_linux, cmd_linux16, cmd_initrd, cmd_initrd16;
|
||||
|
||||
GRUB_MOD_INIT(linux16)
|
||||
{
|
||||
+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
+ return;
|
||||
+
|
||||
cmd_linux =
|
||||
grub_register_command ("linux", grub_cmd_linux,
|
||||
0, N_("Load Linux."));
|
||||
@@ -504,6 +508,9 @@ GRUB_MOD_INIT(linux16)
|
||||
|
||||
GRUB_MOD_FINI(linux16)
|
||||
{
|
||||
+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
+ return;
|
||||
+
|
||||
grub_unregister_command (cmd_linux);
|
||||
grub_unregister_command (cmd_linux16);
|
||||
grub_unregister_command (cmd_initrd);
|
||||
diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c
|
||||
index facb13f3d36..47e481f4576 100644
|
||||
--- a/grub-core/loader/multiboot.c
|
||||
+++ b/grub-core/loader/multiboot.c
|
||||
@@ -50,6 +50,7 @@
|
||||
#include <grub/video.h>
|
||||
#include <grub/memory.h>
|
||||
#include <grub/i18n.h>
|
||||
+#include <grub/efi/sb.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -444,6 +445,9 @@ static grub_command_t cmd_multiboot, cmd_module;
|
||||
|
||||
GRUB_MOD_INIT(multiboot)
|
||||
{
|
||||
+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
+ return;
|
||||
+
|
||||
cmd_multiboot =
|
||||
#ifdef GRUB_USE_MULTIBOOT2
|
||||
grub_register_command ("multiboot2", grub_cmd_multiboot,
|
||||
@@ -464,6 +468,9 @@ GRUB_MOD_INIT(multiboot)
|
||||
|
||||
GRUB_MOD_FINI(multiboot)
|
||||
{
|
||||
+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
+ return;
|
||||
+
|
||||
grub_unregister_command (cmd_multiboot);
|
||||
grub_unregister_command (cmd_module);
|
||||
}
|
||||
diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c
|
||||
index 1c0cf6a430a..baa54e652ab 100644
|
||||
--- a/grub-core/loader/xnu.c
|
||||
+++ b/grub-core/loader/xnu.c
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/verify.h>
|
||||
#include <grub/safemath.h>
|
||||
+#include <grub/efi/sb.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -1497,6 +1498,9 @@ static grub_extcmd_t cmd_splash;
|
||||
|
||||
GRUB_MOD_INIT(xnu)
|
||||
{
|
||||
+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
+ return;
|
||||
+
|
||||
cmd_kernel = grub_register_command ("xnu_kernel", grub_cmd_xnu_kernel, 0,
|
||||
N_("Load XNU image."));
|
||||
cmd_kernel64 = grub_register_command ("xnu_kernel64", grub_cmd_xnu_kernel64,
|
||||
@@ -1540,6 +1544,9 @@ GRUB_MOD_INIT(xnu)
|
||||
|
||||
GRUB_MOD_FINI(xnu)
|
||||
{
|
||||
+ if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
|
||||
+ return;
|
||||
+
|
||||
#ifndef GRUB_MACHINE_EMU
|
||||
grub_unregister_command (cmd_resume);
|
||||
#endif
|
||||
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
|
||||
index 6295df85f3f..585fa6662b6 100644
|
||||
--- a/include/grub/efi/efi.h
|
||||
+++ b/include/grub/efi/efi.h
|
||||
@@ -91,7 +91,6 @@ EXPORT_FUNC (grub_efi_set_variable) (const char *var,
|
||||
const grub_efi_guid_t *guid,
|
||||
void *data,
|
||||
grub_size_t datasize);
|
||||
-grub_efi_boolean_t EXPORT_FUNC (grub_efi_secure_boot) (void);
|
||||
int
|
||||
EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1,
|
||||
const grub_efi_device_path_t *dp2);
|
||||
diff --git a/include/grub/ia64/linux.h b/include/grub/ia64/linux.h
|
||||
new file mode 100644
|
||||
index 00000000000..e69de29bb2d
|
||||
diff --git a/include/grub/mips/linux.h b/include/grub/mips/linux.h
|
||||
new file mode 100644
|
||||
index 00000000000..e69de29bb2d
|
||||
diff --git a/include/grub/powerpc/linux.h b/include/grub/powerpc/linux.h
|
||||
new file mode 100644
|
||||
index 00000000000..e69de29bb2d
|
||||
diff --git a/include/grub/sparc64/linux.h b/include/grub/sparc64/linux.h
|
||||
new file mode 100644
|
||||
index 00000000000..e69de29bb2d
|
||||
@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From 0c7ae6d7527d08e54a6eeebddb6c5c697c4b37d2 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Thu, 14 Jul 2016 17:48:45 +0800
|
||||
Subject: [PATCH] efinet: Setting DNS server from UEFI protocol
|
||||
Subject: [PATCH 8/8] efinet: Setting DNS server from UEFI protocol
|
||||
|
||||
In the URI device path node, any name rahter than address can be used for
|
||||
looking up the resources so that DNS service become needed to get answer of the
|
||||
@ -29,23 +29,21 @@ Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
Signed-off-by: Ken Lin <ken.lin@hpe.com>
|
||||
---
|
||||
grub-core/net/drivers/efi/efinet.c | 163 +++++++++++++++++++++++++++++++++++++
|
||||
include/grub/efi/api.h | 75 +++++++++++++++++
|
||||
2 files changed, 238 insertions(+)
|
||||
include/grub/efi/api.h | 76 +++++++++++++++++
|
||||
2 files changed, 239 insertions(+)
|
||||
|
||||
diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c
|
||||
index 8171ecaa5e4..715a6168d77 100644
|
||||
--- a/grub-core/net/drivers/efi/efinet.c
|
||||
+++ b/grub-core/net/drivers/efi/efinet.c
|
||||
@@ -33,6 +33,8 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
||||
@@ -30,6 +30,8 @@
|
||||
/* GUID. */
|
||||
static grub_efi_guid_t net_io_guid = GRUB_EFI_SIMPLE_NETWORK_GUID;
|
||||
static grub_efi_guid_t pxe_io_guid = GRUB_EFI_PXE_GUID;
|
||||
+static grub_efi_guid_t ip4_config_guid = GRUB_EFI_IP4_CONFIG2_PROTOCOL_GUID;
|
||||
+static grub_efi_guid_t ip6_config_guid = GRUB_EFI_IP6_CONFIG_PROTOCOL_GUID;
|
||||
static grub_guid_t net_io_guid = GRUB_EFI_SIMPLE_NETWORK_GUID;
|
||||
static grub_guid_t pxe_io_guid = GRUB_EFI_PXE_GUID;
|
||||
+static grub_guid_t ip4_config_guid = GRUB_EFI_IP4_CONFIG2_PROTOCOL_GUID;
|
||||
+static grub_guid_t ip6_config_guid = GRUB_EFI_IP6_CONFIG_PROTOCOL_GUID;
|
||||
|
||||
static grub_err_t
|
||||
send_card_buffer (struct grub_net_card *dev,
|
||||
@@ -332,6 +334,125 @@ grub_efinet_findcards (void)
|
||||
@@ -342,6 +344,125 @@
|
||||
grub_free (handles);
|
||||
}
|
||||
|
||||
@ -56,7 +54,7 @@ index 8171ecaa5e4..715a6168d77 100644
|
||||
+ grub_efi_handle_t handle;
|
||||
+ grub_efi_status_t status;
|
||||
+
|
||||
+ status = efi_call_3 (grub_efi_system_table->boot_services->locate_device_path,
|
||||
+ status = grub_efi_system_table->boot_services->locate_device_path (
|
||||
+ protocol, &device_path, &handle);
|
||||
+
|
||||
+ if (status != GRUB_EFI_SUCCESS)
|
||||
@ -92,7 +90,7 @@ index 8171ecaa5e4..715a6168d77 100644
|
||||
+ if (!addrs)
|
||||
+ return 0;
|
||||
+
|
||||
+ status = efi_call_4 (conf->get_data, conf,
|
||||
+ status = conf->get_data (conf,
|
||||
+ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_DNSSERVER,
|
||||
+ &data_size, addrs);
|
||||
+
|
||||
@ -103,7 +101,7 @@ index 8171ecaa5e4..715a6168d77 100644
|
||||
+ if (!addrs)
|
||||
+ return 0;
|
||||
+
|
||||
+ status = efi_call_4 (conf->get_data, conf,
|
||||
+ status = conf->get_data (conf,
|
||||
+ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_DNSSERVER,
|
||||
+ &data_size, addrs);
|
||||
+ }
|
||||
@ -142,7 +140,7 @@ index 8171ecaa5e4..715a6168d77 100644
|
||||
+ if (!addrs)
|
||||
+ return 0;
|
||||
+
|
||||
+ status = efi_call_4 (conf->get_data, conf,
|
||||
+ status = conf->get_data (conf,
|
||||
+ GRUB_EFI_IP6_CONFIG_DATA_TYPE_DNSSERVER,
|
||||
+ &data_size, addrs);
|
||||
+
|
||||
@ -153,7 +151,7 @@ index 8171ecaa5e4..715a6168d77 100644
|
||||
+ if (!addrs)
|
||||
+ return 0;
|
||||
+
|
||||
+ status = efi_call_4 (conf->get_data, conf,
|
||||
+ status = conf->get_data (conf,
|
||||
+ GRUB_EFI_IP6_CONFIG_DATA_TYPE_DNSSERVER,
|
||||
+ &data_size, addrs);
|
||||
+ }
|
||||
@ -171,7 +169,7 @@ index 8171ecaa5e4..715a6168d77 100644
|
||||
static struct grub_net_buff *
|
||||
grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *use_ipv6)
|
||||
{
|
||||
@@ -390,6 +511,8 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u
|
||||
@@ -394,6 +515,8 @@
|
||||
grub_efi_ipv4_device_path_t *ipv4 = (grub_efi_ipv4_device_path_t *) ldp;
|
||||
struct grub_net_bootp_packet *bp;
|
||||
grub_uint8_t *ptr;
|
||||
@ -180,7 +178,7 @@ index 8171ecaa5e4..715a6168d77 100644
|
||||
|
||||
bp = (struct grub_net_bootp_packet *) nb->tail;
|
||||
err = grub_netbuff_put (nb, sizeof (*bp) + 4);
|
||||
@@ -451,6 +574,25 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u
|
||||
@@ -455,6 +578,25 @@
|
||||
*ptr++ = sizeof ("HTTPClient") - 1;
|
||||
grub_memcpy (ptr, "HTTPClient", sizeof ("HTTPClient") - 1);
|
||||
|
||||
@ -206,7 +204,7 @@ index 8171ecaa5e4..715a6168d77 100644
|
||||
ptr = nb->tail;
|
||||
err = grub_netbuff_put (nb, 1);
|
||||
if (err)
|
||||
@@ -483,6 +625,8 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u
|
||||
@@ -487,6 +629,8 @@
|
||||
struct grub_net_dhcp6_option *opt;
|
||||
struct grub_net_dhcp6_option_iana *iana;
|
||||
struct grub_net_dhcp6_option_iaaddr *iaaddr;
|
||||
@ -215,7 +213,7 @@ index 8171ecaa5e4..715a6168d77 100644
|
||||
|
||||
d6p = (struct grub_net_dhcp6_packet *)nb->tail;
|
||||
err = grub_netbuff_put (nb, sizeof(*d6p));
|
||||
@@ -546,6 +690,25 @@ grub_efinet_create_dhcp_ack_from_device_path (grub_efi_device_path_t *dp, int *u
|
||||
@@ -550,6 +694,25 @@
|
||||
opt->len = grub_cpu_to_be16 (uri_len);
|
||||
grub_memcpy (opt->data, uri_dp->uri, uri_len);
|
||||
|
||||
@ -241,15 +239,12 @@ index 8171ecaa5e4..715a6168d77 100644
|
||||
*use_ipv6 = 1;
|
||||
}
|
||||
|
||||
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
|
||||
index 4a51667adb1..0b490195ad9 100644
|
||||
--- a/include/grub/efi/api.h
|
||||
+++ b/include/grub/efi/api.h
|
||||
@@ -352,6 +352,15 @@
|
||||
#define GRUB_EFI_RNG_PROTOCOL_GUID \
|
||||
{ 0x3152bca5, 0xeade, 0x433d, \
|
||||
{ 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44 } \
|
||||
+
|
||||
@@ -379,6 +379,16 @@
|
||||
{0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f } \
|
||||
}
|
||||
|
||||
+#define GRUB_EFI_IP4_CONFIG2_PROTOCOL_GUID \
|
||||
+ { 0x5b446ed1, 0xe30b, 0x4faa, \
|
||||
+ { 0x87, 0x1a, 0x36, 0x54, 0xec, 0xa3, 0x60, 0x80 } \
|
||||
@ -258,12 +253,14 @@ index 4a51667adb1..0b490195ad9 100644
|
||||
+#define GRUB_EFI_IP6_CONFIG_PROTOCOL_GUID \
|
||||
+ { 0x937fe521, 0x95ae, 0x4d1a, \
|
||||
+ { 0x89, 0x29, 0x48, 0xbc, 0xd9, 0x0a, 0xd3, 0x1a } \
|
||||
}
|
||||
|
||||
+ }
|
||||
+
|
||||
struct grub_efi_sal_system_table
|
||||
@@ -1883,6 +1892,72 @@ struct grub_efi_rng_protocol
|
||||
};
|
||||
typedef struct grub_efi_rng_protocol grub_efi_rng_protocol_t;
|
||||
{
|
||||
grub_uint32_t signature;
|
||||
@@ -1879,4 +1889,70 @@
|
||||
} GRUB_PACKED;
|
||||
typedef struct initrd_media_device_path initrd_media_device_path_t;
|
||||
|
||||
+enum grub_efi_ip4_config2_data_type {
|
||||
+ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_INTERFACEINFO,
|
||||
@ -277,21 +274,21 @@ index 4a51667adb1..0b490195ad9 100644
|
||||
+
|
||||
+struct grub_efi_ip4_config2_protocol
|
||||
+{
|
||||
+ grub_efi_status_t (*set_data) (struct grub_efi_ip4_config2_protocol *this,
|
||||
+ grub_efi_status_t (__grub_efi_api *set_data) (struct grub_efi_ip4_config2_protocol *this,
|
||||
+ grub_efi_ip4_config2_data_type_t data_type,
|
||||
+ grub_efi_uintn_t data_size,
|
||||
+ void *data);
|
||||
+
|
||||
+ grub_efi_status_t (*get_data) (struct grub_efi_ip4_config2_protocol *this,
|
||||
+ grub_efi_status_t (__grub_efi_api *get_data) (struct grub_efi_ip4_config2_protocol *this,
|
||||
+ grub_efi_ip4_config2_data_type_t data_type,
|
||||
+ grub_efi_uintn_t *data_size,
|
||||
+ void *data);
|
||||
+
|
||||
+ grub_efi_status_t (*register_data_notify) (struct grub_efi_ip4_config2_protocol *this,
|
||||
+ grub_efi_status_t (__grub_efi_api *register_data_notify) (struct grub_efi_ip4_config2_protocol *this,
|
||||
+ grub_efi_ip4_config2_data_type_t data_type,
|
||||
+ grub_efi_event_t event);
|
||||
+
|
||||
+ grub_efi_status_t (*unregister_datanotify) (struct grub_efi_ip4_config2_protocol *this,
|
||||
+ grub_efi_status_t (__grub_efi_api *unregister_datanotify) (struct grub_efi_ip4_config2_protocol *this,
|
||||
+ grub_efi_ip4_config2_data_type_t data_type,
|
||||
+ grub_efi_event_t event);
|
||||
+};
|
||||
@ -311,26 +308,24 @@ index 4a51667adb1..0b490195ad9 100644
|
||||
+
|
||||
+struct grub_efi_ip6_config_protocol
|
||||
+{
|
||||
+ grub_efi_status_t (*set_data) (struct grub_efi_ip6_config_protocol *this,
|
||||
+ grub_efi_status_t (__grub_efi_api *set_data) (struct grub_efi_ip6_config_protocol *this,
|
||||
+ grub_efi_ip6_config_data_type_t data_type,
|
||||
+ grub_efi_uintn_t data_size,
|
||||
+ void *data);
|
||||
+
|
||||
+ grub_efi_status_t (*get_data) (struct grub_efi_ip6_config_protocol *this,
|
||||
+ grub_efi_status_t (__grub_efi_api *get_data) (struct grub_efi_ip6_config_protocol *this,
|
||||
+ grub_efi_ip6_config_data_type_t data_type,
|
||||
+ grub_efi_uintn_t *data_size,
|
||||
+ void *data);
|
||||
+
|
||||
+ grub_efi_status_t (*register_data_notify) (struct grub_efi_ip6_config_protocol *this,
|
||||
+ grub_efi_status_t (__grub_efi_api *register_data_notify) (struct grub_efi_ip6_config_protocol *this,
|
||||
+ grub_efi_ip6_config_data_type_t data_type,
|
||||
+ grub_efi_event_t event);
|
||||
+
|
||||
+ grub_efi_status_t (*unregister_datanotify) (struct grub_efi_ip6_config_protocol *this,
|
||||
+ grub_efi_status_t (__grub_efi_api *unregister_datanotify) (struct grub_efi_ip6_config_protocol *this,
|
||||
+ grub_efi_ip6_config_data_type_t data_type,
|
||||
+ grub_efi_event_t event);
|
||||
+};
|
||||
+typedef struct grub_efi_ip6_config_protocol grub_efi_ip6_config_protocol_t;
|
||||
+
|
||||
#if (GRUB_TARGET_SIZEOF_VOID_P == 4) || defined (__ia64__) \
|
||||
|| defined (__aarch64__) || defined (__MINGW64__) || defined (__CYGWIN__) \
|
||||
|| defined(__riscv)
|
||||
#endif /* ! GRUB_EFI_API_HEADER */
|
||||
151
0008-linuxefi-Use-common-grub_initrd_load.patch
Normal file
151
0008-linuxefi-Use-common-grub_initrd_load.patch
Normal file
@ -0,0 +1,151 @@
|
||||
From adf486860fe0d395579be8b01d4fda8b93377768 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Wed, 8 Jun 2022 16:04:12 +0800
|
||||
Subject: [PATCH 08/10] linuxefi: Use common grub_initrd_load
|
||||
|
||||
By using the common initrd loading routine factored out allows to share between
|
||||
features like concatenating initramfs component.
|
||||
|
||||
For eg.
|
||||
|
||||
initrdefi /initrd-5.16.15-1-default newc:grub.cfg:/grub2/grub.cfg
|
||||
|
||||
The file /grub2/grub.cfg read off from root disk will be available to use as
|
||||
/grub.cfg in the target initramfs loaded by grub.
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/loader/i386/efi/linux.c | 87 ++++---------------------------
|
||||
1 file changed, 10 insertions(+), 77 deletions(-)
|
||||
|
||||
--- a/grub-core/loader/i386/efi/linux.c
|
||||
+++ b/grub-core/loader/i386/efi/linux.c
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <grub/cpu/efi/memory.h>
|
||||
#include <grub/tpm.h>
|
||||
#include <grub/safemath.h>
|
||||
+#include <grub/linux.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
@@ -146,44 +147,6 @@
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
-#define BOUNCE_BUFFER_MAX 0x1000000ull
|
||||
-
|
||||
-static grub_ssize_t
|
||||
-read(grub_file_t file, grub_uint8_t *bufp, grub_size_t len)
|
||||
-{
|
||||
- grub_ssize_t bufpos = 0;
|
||||
- static grub_size_t bbufsz = 0;
|
||||
- static char *bbuf = NULL;
|
||||
-
|
||||
- if (bbufsz == 0)
|
||||
- bbufsz = MIN(BOUNCE_BUFFER_MAX, len);
|
||||
-
|
||||
- while (!bbuf && bbufsz)
|
||||
- {
|
||||
- bbuf = grub_malloc(bbufsz);
|
||||
- if (!bbuf)
|
||||
- bbufsz >>= 1;
|
||||
- }
|
||||
- if (!bbuf)
|
||||
- grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("cannot allocate bounce buffer"));
|
||||
-
|
||||
- while (bufpos < (long long)len)
|
||||
- {
|
||||
- grub_ssize_t sz;
|
||||
-
|
||||
- sz = grub_file_read (file, bbuf, MIN(bbufsz, len - bufpos));
|
||||
- if (sz < 0)
|
||||
- return sz;
|
||||
- if (sz == 0)
|
||||
- break;
|
||||
-
|
||||
- grub_memcpy(bufp + bufpos, bbuf, sz);
|
||||
- bufpos += sz;
|
||||
- }
|
||||
-
|
||||
- return bufpos;
|
||||
-}
|
||||
-
|
||||
#define LOW_U32(val) ((grub_uint32_t)(((grub_addr_t)(val)) & 0xffffffffull))
|
||||
#define HIGH_U32(val) ((grub_uint32_t)(((grub_addr_t)(val) >> 32) & 0xffffffffull))
|
||||
|
||||
@@ -191,10 +154,8 @@
|
||||
grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char *argv[])
|
||||
{
|
||||
- grub_file_t *files = 0;
|
||||
- int i, nfiles = 0;
|
||||
+ struct grub_linux_initrd_context initrd_ctx = { 0, 0, 0 };
|
||||
grub_size_t size = 0;
|
||||
- grub_uint8_t *ptr;
|
||||
|
||||
if (argc == 0)
|
||||
{
|
||||
@@ -208,24 +169,10 @@
|
||||
goto fail;
|
||||
}
|
||||
|
||||
- files = grub_calloc (argc, sizeof (files[0]));
|
||||
- if (!files)
|
||||
+ if (grub_initrd_init (argc, argv, &initrd_ctx))
|
||||
goto fail;
|
||||
|
||||
- for (i = 0; i < argc; i++)
|
||||
- {
|
||||
- files[i] = grub_file_open (argv[i], GRUB_FILE_TYPE_LINUX_INITRD
|
||||
- | GRUB_FILE_TYPE_NO_DECOMPRESS);
|
||||
- if (! files[i])
|
||||
- goto fail;
|
||||
- nfiles++;
|
||||
- if (grub_add (size, ALIGN_UP (grub_file_size (files[i]), 4), &size))
|
||||
- {
|
||||
- grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected"));
|
||||
- goto fail;
|
||||
- }
|
||||
- }
|
||||
-
|
||||
+ size = grub_get_initrd_size (&initrd_ctx);
|
||||
initrd_mem = kernel_alloc(size, N_("can't allocate initrd"));
|
||||
if (initrd_mem == NULL)
|
||||
goto fail;
|
||||
@@ -238,30 +185,16 @@
|
||||
params->ext_ramdisk_image = HIGH_U32(initrd_mem);
|
||||
#endif
|
||||
|
||||
- ptr = initrd_mem;
|
||||
-
|
||||
- for (i = 0; i < nfiles; i++)
|
||||
- {
|
||||
- grub_ssize_t cursize = grub_file_size (files[i]);
|
||||
- if (read (files[i], ptr, cursize) != cursize)
|
||||
- {
|
||||
- if (!grub_errno)
|
||||
- grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
|
||||
- argv[i]);
|
||||
- goto fail;
|
||||
- }
|
||||
- ptr += cursize;
|
||||
- grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4));
|
||||
- ptr += ALIGN_UP_OVERHEAD (cursize, 4);
|
||||
- }
|
||||
+ /* FIXME: Use bounce buffers as many UEFI machines apparently can't DMA
|
||||
+ * correctly above 4GB
|
||||
+ */
|
||||
+ if (grub_initrd_load (&initrd_ctx, initrd_mem))
|
||||
+ goto fail;
|
||||
|
||||
params->ramdisk_size = size;
|
||||
|
||||
fail:
|
||||
- for (i = 0; i < nfiles; i++)
|
||||
- grub_file_close (files[i]);
|
||||
- grub_free (files);
|
||||
-
|
||||
+ grub_initrd_close (&initrd_ctx);
|
||||
if (initrd_mem && grub_errno)
|
||||
grub_efi_free_pages((grub_efi_physical_address_t)(grub_addr_t)initrd_mem, BYTES_TO_PAGES(size));
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From 923c8f6807cbd93b72d4dcb16c213d0d2a6b5b9a Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Axtens <dja@axtens.net>
|
||||
Date: Thu, 1 Oct 2020 20:23:48 +1000
|
||||
Subject: [PATCH] pgp: factor out rsa_pad
|
||||
Subject: [PATCH 08/23] pgp: factor out rsa_pad
|
||||
|
||||
rsa_pad does the PKCS#1 v1.5 padding for the RSA signature scheme.
|
||||
We want to use it in other RSA signature verification applications.
|
||||
@ -18,23 +18,20 @@ PKCS#1 v1.5 module.
|
||||
|
||||
Signed-off-by: Daniel Axtens <dja@axtens.net>
|
||||
---
|
||||
grub-core/Makefile.core.def | 8 ++++++
|
||||
grub-core/commands/pgp.c | 28 ++-------------------
|
||||
grub-core/lib/pkcs1_v15.c | 59 +++++++++++++++++++++++++++++++++++++++++++++
|
||||
include/grub/pkcs1_v15.h | 27 +++++++++++++++++++++
|
||||
grub-core/Makefile.core.def | 8 +++++
|
||||
grub-core/commands/pgp.c | 28 ++----------------
|
||||
grub-core/lib/pkcs1_v15.c | 59 +++++++++++++++++++++++++++++++++++++
|
||||
include/grub/pkcs1_v15.h | 27 +++++++++++++++++
|
||||
4 files changed, 96 insertions(+), 26 deletions(-)
|
||||
create mode 100644 grub-core/lib/pkcs1_v15.c
|
||||
create mode 100644 include/grub/pkcs1_v15.h
|
||||
|
||||
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
|
||||
index 81fc274148e..97347ae76f9 100644
|
||||
--- a/grub-core/Makefile.core.def
|
||||
+++ b/grub-core/Makefile.core.def
|
||||
@@ -2510,6 +2510,14 @@ module = {
|
||||
cppflags = '$(CPPFLAGS_GCRY)';
|
||||
@@ -2542,6 +2542,14 @@
|
||||
};
|
||||
|
||||
+module = {
|
||||
module = {
|
||||
+ name = pkcs1_v15;
|
||||
+ common = lib/pkcs1_v15.c;
|
||||
+
|
||||
@ -42,11 +39,10 @@ index 81fc274148e..97347ae76f9 100644
|
||||
+ cppflags = '$(CPPFLAGS_GCRY)';
|
||||
+};
|
||||
+
|
||||
module = {
|
||||
+module = {
|
||||
name = all_video;
|
||||
common = lib/fake_module.c;
|
||||
diff --git a/grub-core/commands/pgp.c b/grub-core/commands/pgp.c
|
||||
index 5daa1e9d00c..2408db4994f 100644
|
||||
};
|
||||
--- a/grub-core/commands/pgp.c
|
||||
+++ b/grub-core/commands/pgp.c
|
||||
@@ -24,6 +24,7 @@
|
||||
@ -57,7 +53,7 @@ index 5daa1e9d00c..2408db4994f 100644
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/gcrypt/gcrypt.h>
|
||||
#include <grub/pubkey.h>
|
||||
@@ -411,32 +412,7 @@ static int
|
||||
@@ -411,32 +412,7 @@
|
||||
rsa_pad (gcry_mpi_t *hmpi, grub_uint8_t *hval,
|
||||
const gcry_md_spec_t *hash, struct grub_public_subkey *sk)
|
||||
{
|
||||
@ -91,9 +87,6 @@ index 5daa1e9d00c..2408db4994f 100644
|
||||
}
|
||||
|
||||
struct grub_pubkey_context
|
||||
diff --git a/grub-core/lib/pkcs1_v15.c b/grub-core/lib/pkcs1_v15.c
|
||||
new file mode 100644
|
||||
index 00000000000..dbacd563d01
|
||||
--- /dev/null
|
||||
+++ b/grub-core/lib/pkcs1_v15.c
|
||||
@@ -0,0 +1,59 @@
|
||||
@ -156,9 +149,6 @@ index 00000000000..dbacd563d01
|
||||
+ grub_free (em);
|
||||
+ return ret;
|
||||
+}
|
||||
diff --git a/include/grub/pkcs1_v15.h b/include/grub/pkcs1_v15.h
|
||||
new file mode 100644
|
||||
index 00000000000..5c338c84a15
|
||||
--- /dev/null
|
||||
+++ b/include/grub/pkcs1_v15.h
|
||||
@@ -0,0 +1,27 @@
|
||||
@ -1,7 +1,8 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From 8fbcf9f2e97c98bdb63ae7d544aa9bb273022403 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Jones <pjones@redhat.com>
|
||||
Date: Wed, 12 Sep 2018 16:12:27 -0400
|
||||
Subject: [PATCH] x86-efi: Allow initrd+params+cmdline allocations above 4GB.
|
||||
Subject: [PATCH 08/11] x86-efi: Allow initrd+params+cmdline allocations above
|
||||
4GB.
|
||||
|
||||
This enables everything except the kernel itself to be above 4GB.
|
||||
Putting the kernel up there still doesn't work, because of the way
|
||||
@ -9,12 +10,12 @@ params->code32_start is used.
|
||||
|
||||
Signed-off-by: Peter Jones <pjones@redhat.com>
|
||||
---
|
||||
grub-core/loader/i386/efi/linux.c | 67 +++++++++++++++++++++++++++++++++++----
|
||||
include/grub/i386/linux.h | 6 +++-
|
||||
grub-core/loader/i386/efi/linux.c | 67 +++++++++++++++++++++++++++----
|
||||
include/grub/i386/linux.h | 6 ++-
|
||||
2 files changed, 65 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
|
||||
index 3e4f7ef39f4..6bc18d5aef5 100644
|
||||
index d284db5d1..d49749269 100644
|
||||
--- a/grub-core/loader/i386/efi/linux.c
|
||||
+++ b/grub-core/loader/i386/efi/linux.c
|
||||
@@ -52,13 +52,22 @@ struct allocation_choice {
|
||||
@ -63,7 +64,7 @@ index 3e4f7ef39f4..6bc18d5aef5 100644
|
||||
static grub_err_t
|
||||
grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc, char *argv[])
|
||||
@@ -207,8 +224,12 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -208,8 +225,12 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
||||
goto fail;
|
||||
grub_dprintf ("linux", "initrd_mem = %p\n", initrd_mem);
|
||||
|
||||
@ -78,7 +79,7 @@ index 3e4f7ef39f4..6bc18d5aef5 100644
|
||||
|
||||
ptr = initrd_mem;
|
||||
|
||||
@@ -338,6 +359,18 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -329,6 +350,18 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -97,7 +98,7 @@ index 3e4f7ef39f4..6bc18d5aef5 100644
|
||||
params = kernel_alloc (sizeof(*params), "cannot allocate kernel parameters");
|
||||
if (!params)
|
||||
goto fail;
|
||||
@@ -372,21 +405,40 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -365,21 +398,40 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
grub_dprintf ("linux", "cmdline:%s\n", linux_cmdline);
|
||||
grub_dprintf ("linux", "setting lh->cmd_line_ptr to 0x%08x\n",
|
||||
@ -140,7 +141,7 @@ index 3e4f7ef39f4..6bc18d5aef5 100644
|
||||
if (!kernel_mem)
|
||||
goto fail;
|
||||
grub_dprintf("linux", "kernel_mem = %p\n", kernel_mem);
|
||||
@@ -395,8 +447,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
@@ -388,8 +440,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
||||
|
||||
loaded = 1;
|
||||
|
||||
@ -153,7 +154,7 @@ index 3e4f7ef39f4..6bc18d5aef5 100644
|
||||
grub_memcpy (kernel_mem, (char *)kernel + start, filelen - start);
|
||||
|
||||
diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h
|
||||
index 25ef52c04eb..fac22476cc5 100644
|
||||
index 25ef52c04..fac22476c 100644
|
||||
--- a/include/grub/i386/linux.h
|
||||
+++ b/include/grub/i386/linux.h
|
||||
@@ -236,7 +236,11 @@ struct linux_kernel_params
|
||||
@ -169,3 +170,6 @@ index 25ef52c04eb..fac22476cc5 100644
|
||||
|
||||
union
|
||||
{
|
||||
--
|
||||
2.31.1
|
||||
|
||||
327
0009-Add-crypttab_entry-to-obviate-the-need-to-input-pass.patch
Normal file
327
0009-Add-crypttab_entry-to-obviate-the-need-to-input-pass.patch
Normal file
@ -0,0 +1,327 @@
|
||||
From 749f7dee6f63217e536663aebb817aec72a65d5a Mon Sep 17 00:00:00 2001
|
||||
From: Michael Chang <mchang@suse.com>
|
||||
Date: Thu, 9 Jun 2022 21:06:00 +0800
|
||||
Subject: [PATCH 09/10] Add crypttab_entry to obviate the need to input
|
||||
password twice
|
||||
|
||||
This patch adds crypttab_entry command to hint grub where to put the key file
|
||||
automatically loaded by linux cryptsetup. It's syntax is similar to
|
||||
/etc/crypttab so that it is relatively straightforward to import.
|
||||
|
||||
crypttab_entry <volume-name> <encrypted-device> <key-file>
|
||||
|
||||
For eg:
|
||||
|
||||
crypttab_entry cr_root 5e1dd109e39343f984da57fd742d3f23 none
|
||||
|
||||
Please note the "encrypted-device" only accepts UUID without dashes as it is
|
||||
the only identification used by grub's cryptodisk device. The crypttab_entry
|
||||
can also be used multiple times to specify encrypted volumes unlocked by
|
||||
"cryptomount -a".
|
||||
|
||||
Signed-off-by: Michael Chang <mchang@suse.com>
|
||||
---
|
||||
grub-core/Makefile.core.def | 5 +
|
||||
grub-core/commands/crypttab.c | 47 ++++++++++++++
|
||||
grub-core/disk/cryptodisk.c | 6 +
|
||||
grub-core/loader/linux.c | 137 ++++++++++++++++++++++++++++++++++++++++--
|
||||
include/grub/linux.h | 3
|
||||
5 files changed, 193 insertions(+), 5 deletions(-)
|
||||
create mode 100644 grub-core/commands/crypttab.c
|
||||
|
||||
--- a/grub-core/Makefile.core.def
|
||||
+++ b/grub-core/Makefile.core.def
|
||||
@@ -2695,3 +2695,8 @@
|
||||
cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)';
|
||||
cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB)';
|
||||
};
|
||||
+
|
||||
+module = {
|
||||
+ name = crypttab;
|
||||
+ common = commands/crypttab.c;
|
||||
+};
|
||||
--- /dev/null
|
||||
+++ b/grub-core/commands/crypttab.c
|
||||
@@ -0,0 +1,47 @@
|
||||
+
|
||||
+#include <grub/dl.h>
|
||||
+#include <grub/command.h>
|
||||
+#include <grub/misc.h>
|
||||
+#include <grub/i18n.h>
|
||||
+#include <grub/linux.h>
|
||||
+
|
||||
+GRUB_MOD_LICENSE ("GPLv3+");
|
||||
+
|
||||
+static grub_err_t
|
||||
+grub_cmd_crypttab_entry (grub_command_t cmd __attribute__ ((unused)),
|
||||
+ int argc, char **argv)
|
||||
+{
|
||||
+ char buf[64];
|
||||
+ const char *path = NULL;
|
||||
+
|
||||
+ if (argc == 2)
|
||||
+ path = NULL;
|
||||
+ else if (argc == 3)
|
||||
+ path = argv[2];
|
||||
+ else
|
||||
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("two or three arguments expected"));
|
||||
+
|
||||
+ if (!path
|
||||
+ || grub_strcmp (path, "none") == 0
|
||||
+ || grub_strcmp (path, "-") == 0)
|
||||
+ {
|
||||
+ grub_snprintf (buf, sizeof (buf), "/etc/cryptsetup-keys.d/%s.key", argv[0]);
|
||||
+ path = buf;
|
||||
+ }
|
||||
+
|
||||
+ /*FIXME: Validate UUID string*/
|
||||
+ return grub_initrd_publish_key (argv[1], NULL, 0, path);
|
||||
+}
|
||||
+
|
||||
+static grub_command_t cmd;
|
||||
+
|
||||
+GRUB_MOD_INIT(crypttab)
|
||||
+{
|
||||
+ cmd = grub_register_command ("crypttab_entry", grub_cmd_crypttab_entry,
|
||||
+ N_("VOLUME-NAME ENCRYPTED-DEVICE KEY-FILE") , N_("No description"));
|
||||
+}
|
||||
+
|
||||
+GRUB_MOD_FINI(crypttab)
|
||||
+{
|
||||
+ grub_unregister_command (cmd);
|
||||
+}
|
||||
--- a/grub-core/disk/cryptodisk.c
|
||||
+++ b/grub-core/disk/cryptodisk.c
|
||||
@@ -30,6 +30,8 @@
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
#include <grub/emu/hostdisk.h>
|
||||
+#else
|
||||
+#include <grub/linux.h>
|
||||
#endif
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
@@ -1235,6 +1237,10 @@
|
||||
if (cargs->hdr_file != NULL)
|
||||
source->read_hook = NULL;
|
||||
|
||||
+#ifndef GRUB_UTIL
|
||||
+ if (cargs->key_data && dev)
|
||||
+ grub_initrd_publish_key (dev->uuid, (const char *)cargs->key_data, cargs->key_len, NULL);
|
||||
+#endif
|
||||
if (askpass)
|
||||
{
|
||||
cargs->key_len = 0;
|
||||
--- a/grub-core/loader/linux.c
|
||||
+++ b/grub-core/loader/linux.c
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <grub/file.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/safemath.h>
|
||||
+#include <grub/list.h>
|
||||
|
||||
struct newc_head
|
||||
{
|
||||
@@ -27,6 +28,7 @@
|
||||
struct grub_linux_initrd_component
|
||||
{
|
||||
grub_file_t file;
|
||||
+ char *buf;
|
||||
char *newc_name;
|
||||
grub_off_t size;
|
||||
};
|
||||
@@ -38,6 +40,18 @@
|
||||
struct dir *child;
|
||||
};
|
||||
|
||||
+struct grub_key_publisher
|
||||
+{
|
||||
+ struct grub_key_publisher *next;
|
||||
+ struct grub_key_publisher **prev;
|
||||
+ char *name; /* UUID */
|
||||
+ char *path;
|
||||
+ char *key;
|
||||
+ grub_size_t key_len;
|
||||
+};
|
||||
+
|
||||
+static struct grub_key_publisher *kpuber;
|
||||
+
|
||||
static char
|
||||
hex (grub_uint8_t val)
|
||||
{
|
||||
@@ -162,6 +176,65 @@
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
+static grub_err_t
|
||||
+grub_initrd_component (const char *buf, int bufsz, const char *newc_name,
|
||||
+ struct grub_linux_initrd_context *initrd_ctx)
|
||||
+{
|
||||
+ struct dir *root = 0;
|
||||
+ struct grub_linux_initrd_component *comp = initrd_ctx->components + initrd_ctx->nfiles;
|
||||
+ grub_size_t dir_size, name_len;
|
||||
+
|
||||
+ while (*newc_name == '/')
|
||||
+ newc_name++;
|
||||
+
|
||||
+ initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4);
|
||||
+ comp->newc_name = grub_strdup (newc_name);
|
||||
+ if (!comp->newc_name ||
|
||||
+ insert_dir (comp->newc_name, &root, 0, &dir_size))
|
||||
+ {
|
||||
+ /* FIXME: Check NULL file pointer before close */
|
||||
+ grub_initrd_close (initrd_ctx);
|
||||
+ return grub_errno;
|
||||
+ }
|
||||
+ /* Should name_len count terminating null ? */
|
||||
+ name_len = grub_strlen (comp->newc_name) + 1;
|
||||
+ if (grub_add (initrd_ctx->size,
|
||||
+ ALIGN_UP (sizeof (struct newc_head) + name_len, 4),
|
||||
+ &initrd_ctx->size) ||
|
||||
+ grub_add (initrd_ctx->size, dir_size, &initrd_ctx->size))
|
||||
+ goto overflow;
|
||||
+
|
||||
+ comp->buf = grub_malloc (bufsz);
|
||||
+ if (!comp->buf)
|
||||
+ {
|
||||
+ free_dir (root);
|
||||
+ grub_initrd_close (initrd_ctx);
|
||||
+ return grub_errno;
|
||||
+ }
|
||||
+ grub_memcpy (comp->buf, buf, bufsz);
|
||||
+ initrd_ctx->nfiles++;
|
||||
+ comp->size = bufsz;
|
||||
+ if (grub_add (initrd_ctx->size, comp->size,
|
||||
+ &initrd_ctx->size))
|
||||
+ goto overflow;
|
||||
+
|
||||
+ initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4);
|
||||
+ if (grub_add (initrd_ctx->size,
|
||||
+ ALIGN_UP (sizeof (struct newc_head)
|
||||
+ + sizeof ("TRAILER!!!") - 1, 4),
|
||||
+ &initrd_ctx->size))
|
||||
+ goto overflow;
|
||||
+
|
||||
+ free_dir (root);
|
||||
+ root = 0;
|
||||
+ return GRUB_ERR_NONE;
|
||||
+
|
||||
+ overflow:
|
||||
+ free_dir (root);
|
||||
+ grub_initrd_close (initrd_ctx);
|
||||
+ return grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected"));
|
||||
+}
|
||||
+
|
||||
grub_err_t
|
||||
grub_initrd_init (int argc, char *argv[],
|
||||
struct grub_linux_initrd_context *initrd_ctx)
|
||||
@@ -169,11 +242,17 @@
|
||||
int i;
|
||||
int newc = 0;
|
||||
struct dir *root = 0;
|
||||
+ struct grub_key_publisher *pk;
|
||||
+ int numkey = 0;
|
||||
|
||||
initrd_ctx->nfiles = 0;
|
||||
initrd_ctx->components = 0;
|
||||
|
||||
- initrd_ctx->components = grub_calloc (argc, sizeof (initrd_ctx->components[0]));
|
||||
+ FOR_LIST_ELEMENTS (pk, kpuber)
|
||||
+ if (pk->key && pk->path)
|
||||
+ numkey++;
|
||||
+
|
||||
+ initrd_ctx->components = grub_calloc (argc + numkey, sizeof (initrd_ctx->components[0]));
|
||||
if (!initrd_ctx->components)
|
||||
return grub_errno;
|
||||
|
||||
@@ -253,6 +332,10 @@
|
||||
root = 0;
|
||||
}
|
||||
|
||||
+ FOR_LIST_ELEMENTS (pk, kpuber)
|
||||
+ if (pk->key && pk->path)
|
||||
+ grub_initrd_component (pk->key, pk->key_len, pk->path, initrd_ctx);
|
||||
+
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
overflow:
|
||||
@@ -276,7 +359,9 @@
|
||||
for (i = 0; i < initrd_ctx->nfiles; i++)
|
||||
{
|
||||
grub_free (initrd_ctx->components[i].newc_name);
|
||||
- grub_file_close (initrd_ctx->components[i].file);
|
||||
+ if (initrd_ctx->components[i].file)
|
||||
+ grub_file_close (initrd_ctx->components[i].file);
|
||||
+ grub_free (initrd_ctx->components[i].buf);
|
||||
}
|
||||
grub_free (initrd_ctx->components);
|
||||
initrd_ctx->components = 0;
|
||||
@@ -325,7 +410,12 @@
|
||||
}
|
||||
|
||||
cursize = initrd_ctx->components[i].size;
|
||||
- if (grub_file_read (initrd_ctx->components[i].file, ptr, cursize)
|
||||
+ if (initrd_ctx->components[i].buf)
|
||||
+ {
|
||||
+ grub_memcpy (ptr, initrd_ctx->components[i].buf, cursize);
|
||||
+ newc = 1;
|
||||
+ }
|
||||
+ else if (grub_file_read (initrd_ctx->components[i].file, ptr, cursize)
|
||||
!= cursize)
|
||||
{
|
||||
if (!grub_errno)
|
||||
@@ -346,3 +436,45 @@
|
||||
root = 0;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
+
|
||||
+grub_err_t
|
||||
+grub_initrd_publish_key (const char *uuid, const char *key, grub_size_t key_len, const char *path)
|
||||
+{
|
||||
+ struct grub_key_publisher *cur = NULL;
|
||||
+
|
||||
+ FOR_LIST_ELEMENTS (cur, kpuber)
|
||||
+ if (grub_uuidcasecmp (cur->name, uuid, sizeof (cur->name)) == 0)
|
||||
+ break;
|
||||
+
|
||||
+ if (!cur)
|
||||
+ cur = grub_zalloc (sizeof (*cur));
|
||||
+ if (!cur)
|
||||
+ return grub_errno;
|
||||
+
|
||||
+ if (key && key_len)
|
||||
+ {
|
||||
+ grub_free (cur->key);
|
||||
+ cur->key = grub_malloc (key_len);
|
||||
+ if (!cur->key)
|
||||
+ {
|
||||
+ grub_free (cur);
|
||||
+ return grub_errno;
|
||||
+ }
|
||||
+ grub_memcpy (cur->key, key, key_len);
|
||||
+ cur->key_len = key_len;
|
||||
+ }
|
||||
+
|
||||
+ if (path)
|
||||
+ {
|
||||
+ grub_free (cur->path);
|
||||
+ cur->path = grub_strdup (path);
|
||||
+ }
|
||||
+
|
||||
+ if (!cur->name)
|
||||
+ {
|
||||
+ cur->name = grub_strdup (uuid);
|
||||
+ grub_list_push (GRUB_AS_LIST_P (&kpuber), GRUB_AS_LIST (cur));
|
||||
+ }
|
||||
+
|
||||
+ return GRUB_ERR_NONE;
|
||||
+}
|
||||
--- a/include/grub/linux.h
|
||||
+++ b/include/grub/linux.h
|
||||
@@ -22,3 +22,6 @@
|
||||
grub_err_t
|
||||
grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
|
||||
void *target);
|
||||
+
|
||||
+grub_err_t
|
||||
+grub_initrd_publish_key (const char *uuid, const char *key, grub_size_t key_len, const char *path);
|
||||
@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From def9a985bdb1a12db49be42b748b646abc156411 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Axtens <dja@axtens.net>
|
||||
Date: Fri, 2 Oct 2020 10:49:26 +1000
|
||||
Subject: [PATCH] crypto: move storage for grub_crypto_pk_* to crypto.c
|
||||
Subject: [PATCH 09/23] crypto: move storage for grub_crypto_pk_* to crypto.c
|
||||
|
||||
The way gcry_rsa and friends (the asymmetric ciphers) are loaded for the
|
||||
pgp module is a bit quirky.
|
||||
@ -40,7 +40,7 @@ Signed-off-by: Daniel Axtens <dja@axtens.net>
|
||||
2 files changed, 4 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/grub-core/commands/pgp.c b/grub-core/commands/pgp.c
|
||||
index 2408db4994f..355a43844ac 100644
|
||||
index 2408db499..355a43844 100644
|
||||
--- a/grub-core/commands/pgp.c
|
||||
+++ b/grub-core/commands/pgp.c
|
||||
@@ -147,10 +147,6 @@ const char *hashes[] = {
|
||||
@ -55,7 +55,7 @@ index 2408db4994f..355a43844ac 100644
|
||||
dsa_pad (gcry_mpi_t *hmpi, grub_uint8_t *hval,
|
||||
const gcry_md_spec_t *hash, struct grub_public_subkey *sk);
|
||||
diff --git a/grub-core/lib/crypto.c b/grub-core/lib/crypto.c
|
||||
index ca334d5a40e..c578128a59d 100644
|
||||
index ca334d5a4..c578128a5 100644
|
||||
--- a/grub-core/lib/crypto.c
|
||||
+++ b/grub-core/lib/crypto.c
|
||||
@@ -121,6 +121,10 @@ grub_md_unregister (gcry_md_spec_t *cipher)
|
||||
@ -69,3 +69,6 @@ index ca334d5a40e..c578128a59d 100644
|
||||
void
|
||||
grub_crypto_hash (const gcry_md_spec_t *hash, void *out, const void *in,
|
||||
grub_size_t inlen)
|
||||
--
|
||||
2.31.1
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user