Skip to contentSkip to conversation

efi: Unified Xen hypervisor/kernel/initrd images

PATCH Superseded Trammell Hudson 2 participants 13 messages Sep 17, 2020 – Sep 21, 2020

v5 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v5 cover efi: Unified Xen hypervisor/kernel/initrd images

This patch series adds support for bundling the xen.efi hypervisor, the xen.cfg configuration file, the Linux kernel and initrd, as well as the XSM, and architectural specific files into a single "unified" EFI executable. This allows an administrator to update the components independently without requiring rebuilding xen, as well as to replace the components in an existing image.

The resulting EFI executable can be invoked directly from the UEFI Boot Manager, removing the need to use a separate loader like grub as well as removing dependencies on local filesystem access. And since it is a single file, it can be signed and validated by UEFI Secure Boot without requring the shim protocol.

It is inspired by systemd-boot's unified kernel technique and borrows the function to locate PE sections from systemd's LGPL'ed code. During EFI boot, Xen looks at its own loaded image to locate the PE sections for the Xen configuration (.config), dom0 kernel (.kernel), dom0 initrd (.ramdisk), and XSM config (.xsm), which are included after building xen.efi using objcopy to add named sections for each input file.

Trammell Hudson (5):
efi/boot.c: Make file->ptr const void* efi/boot.c: add file.need_to_free
efi/boot.c: add handle_file_info()
efi: Enable booting unified hypervisor/kernel/initrd images
efi: Do not use command line if unified config is included

 .gitignore                  |   1 +
 docs/misc/efi.pandoc        |  49 +++++++++++
 xen/arch/arm/efi/efi-boot.h |  25 ++++--
 xen/arch/x86/efi/Makefile   |   2 +-
 xen/arch/x86/efi/efi-boot.h |  11 ++-
 xen/common/efi/boot.c       | 162 +++++++++++++++++++++++++++---------
 xen/common/efi/efi.h        |   3 +
 xen/common/efi/pe.c         | 134 +++++++++++++++++++++++++++++
 8 files changed, 335 insertions(+), 52 deletions(-)
 create mode 100644 xen/common/efi/pe.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH v5 1/5 efi/boot.c: Make file->ptr const void*

Other than the config file parser that edits the image inplace, no other users of the file sections requires write access to the data.

---
 xen/common/efi/boot.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
xen/common/efi/boot.c +6 -5
index 0ac80e47bb..157fe0e8c5 100644
@@ -41,7 +41,7 @@
 
 typedef EFI_STATUS
 (/* _not_ EFIAPI */ *EFI_SHIM_LOCK_VERIFY) (
-    IN VOID *Buffer,
+    IN const VOID *Buffer,
     IN UINT32 Size);
 
 typedef struct {
@@ -104,7 +104,8 @@ struct file {
     UINTN size;
     union {
         EFI_PHYSICAL_ADDRESS addr;
-        void *ptr;
+        char *str;
+        const void *ptr;
     };
 };
 
@@ -592,7 +593,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
             efi_arch_handle_module(file, name, options);
         }
 
-        ret = FileHandle->Read(FileHandle, &file->size, file->ptr);
+        ret = FileHandle->Read(FileHandle, &file->size, file->str);
         if ( !EFI_ERROR(ret) && file->size != size )
             ret = EFI_ABORTED;
         if ( EFI_ERROR(ret) )
@@ -616,7 +617,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
 
 static void __init pre_parse(const struct file *cfg)
 {
-    char *ptr = cfg->ptr, *end = ptr + cfg->size;
+    char *ptr = cfg->str, *end = ptr + cfg->size;
     bool start = true, comment = false;
 
     for ( ; ptr < end; ++ptr )
@@ -645,7 +646,7 @@ static void __init pre_parse(const struct file *cfg)
 static char *__init get_value(const struct file *cfg, const char *section,
                               const char *item)
 {
-    char *ptr = cfg->ptr, *end = ptr + cfg->size;
+    char *ptr = cfg->str, *end = ptr + cfg->size;
     size_t slen = section ? strlen(section) : 0, ilen = strlen(item);
     bool match = !slen;
 
Signature · 1 line
2.25.1
Reviewed-by on v5 1/5
#2 lore raw

Re: [PATCH v5 1/5] efi/boot.c: Make file->ptr const void*

Quoted 5 lines · Trammell Hudson

Other than the config file parser that edits the image inplace, no other users of the file sections requires write access to the data.

albeit ...

xen/common/efi/boot.c static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, · line 596

Quoted 6 lines
xen/common/efi/boot.c +1 -1
@@ -592,7 +593,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
             efi_arch_handle_module(file, name, options);
         }
 
-        ret = FileHandle->Read(FileHandle, &file->size, file->ptr);
+        ret = FileHandle->Read(FileHandle, &file->size, file->str);

... I'm not particularly happy about this part of the change. But yes - what do you do.

Jan

#3 lore raw

PATCH v5 2/5 efi/boot.c: add file.need_to_free

In reply to Trammell Hudson

The config file, kernel, initrd, etc should only be freed if they are allocated with the UEFI allocator.

---
 xen/common/efi/boot.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
xen/common/efi/boot.c +6 -4
index 157fe0e8c5..77530a0595 100644
@@ -102,6 +102,7 @@ union string {
 
 struct file {
     UINTN size;
+    bool need_to_free;
     union {
         EFI_PHYSICAL_ADDRESS addr;
         char *str;
@@ -280,13 +281,13 @@ void __init noreturn blexit(const CHAR16 *str)
     if ( !efi_bs )
         efi_arch_halt();
 
-    if ( cfg.addr )
+    if ( cfg.addr && cfg.need_to_free )
         efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size));
-    if ( kernel.addr )
+    if ( kernel.addr && kernel.need_to_free )
         efi_bs->FreePages(kernel.addr, PFN_UP(kernel.size));
-    if ( ramdisk.addr )
+    if ( ramdisk.addr && ramdisk.need_to_free )
         efi_bs->FreePages(ramdisk.addr, PFN_UP(ramdisk.size));
-    if ( xsm.addr )
+    if ( xsm.addr && xsm.need_to_free )
         efi_bs->FreePages(xsm.addr, PFN_UP(xsm.size));
 
     efi_arch_blexit();
@@ -573,6 +574,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
                          HYPERVISOR_VIRT_END - DIRECTMAP_VIRT_START);
         ret = efi_bs->AllocatePages(AllocateMaxAddress, EfiLoaderData,
                                     PFN_UP(size), &file->addr);
+        file->need_to_free = true;
     }
     if ( EFI_ERROR(ret) )
     {
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH v5 2/5] efi/boot.c: add file.need_to_free

Quoted 4 lines · Trammell Hudson

The config file, kernel, initrd, etc should only be freed if they are allocated with the UEFI allocator.

Hmm, this hasn't changed from v4, despite the review requests. Any particular reason?

Jan

#5 lore raw

PATCH v5 3/5 efi/boot.c: add handle_file_info()

In reply to Trammell Hudson

Add a separate function to display the address ranges used by the files and call efi_arch_handle_module() on the modules.

---
 xen/common/efi/boot.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)
xen/common/efi/boot.c +17 -10
index 77530a0595..e0280f7a21 100644
@@ -540,6 +540,22 @@ static char * __init split_string(char *s)
     return NULL;
 }
 
+static void __init handle_file_info(CHAR16 *name,
+                                    const struct file *file, const char *options)
+{
+    if ( file == &cfg )
+        return;
+
+    PrintStr(name);
+    PrintStr(L": ");
+    DisplayUint(file->addr, 2 * sizeof(file->addr));
+    PrintStr(L"-");
+    DisplayUint(file->addr + file->size, 2 * sizeof(file->addr));
+    PrintStr(newline);
+
+    efi_arch_handle_module(file, name, options);
+}
+
 static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
                              struct file *file, const char *options)
 {
@@ -584,16 +600,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
     else
     {
         file->size = size;
-        if ( file != &cfg )
-        {
-            PrintStr(name);
-            PrintStr(L": ");
-            DisplayUint(file->addr, 2 * sizeof(file->addr));
-            PrintStr(L"-");
-            DisplayUint(file->addr + size, 2 * sizeof(file->addr));
-            PrintStr(newline);
-            efi_arch_handle_module(file, name, options);
-        }
+        handle_file_info(name, file, options);
 
         ret = FileHandle->Read(FileHandle, &file->size, file->str);
         if ( !EFI_ERROR(ret) && file->size != size )
Signature · 1 line
2.25.1
#6 lore raw

Re: [PATCH v5 3/5] efi/boot.c: add handle_file_info()

Quoted 4 lines · Trammell Hudson

Add a separate function to display the address ranges used by the files and call efi_arch_handle_module() on the modules.

You've lost the ack I gave, and ...

xen/common/efi/boot.c static char * __init split_string(char *s) · line 544

Quoted 8 lines
xen/common/efi/boot.c +2 -0
@@ -540,6 +540,22 @@ static char * __init split_string(char *s)
     return NULL;
 }
 
+static void __init handle_file_info(CHAR16 *name,
+                                    const struct file *file, const char *options)

... with the const added here you ought to mention (in a post- description remark perhaps) that this now depends on a not yet applied patch on the list). Remember that reviewers and committer may be different people, and even if the committer participated in review, (s)he may have forgotten by the time a patch is otherwise ready to go in.

And btw - briefly mentioning what changes you made compared to the previous version (again in a post-description remark) helps reviews quite a bit.

Jan

#7 lore raw

PATCH v5 4/5 efi: Enable booting unified hypervisor/kernel/initrd images

In reply to Trammell Hudson

This patch adds support for bundling the xen.efi hypervisor, the xen.cfg configuration file, the Linux kernel and initrd, as well as the XSM, and architectural specific files into a single "unified" EFI executable. This allows an administrator to update the components independently without requiring rebuilding xen, as well as to replace the components in an existing image.

The resulting EFI executable can be invoked directly from the UEFI Boot Manager, removing the need to use a separate loader like grub as well as removing dependencies on local filesystem access. And since it is a single file, it can be signed and validated by UEFI Secure Boot without requring the shim protocol.

It is inspired by systemd-boot's unified kernel technique and borrows the function to locate PE sections from systemd's LGPL'ed code. During EFI boot, Xen looks at its own loaded image to locate the PE sections for the Xen configuration (.config), dom0 kernel (.kernel), dom0 initrd (.ramdisk), and XSM config (.xsm), which are included after building xen.efi using objcopy to add named sections for each input file.

For x86, the CPU ucode can be included in a section named .ucode, which is loaded in the efi_arch_cfg_file_late() stage of the boot process.

On ARM systems the Device Tree can be included in a section named .dtb, which is loaded during the efi_arch_cfg_file_early() stage of the boot process.

Note that the system will fall back to loading files from disk if the named sections do not exist. This allows distributions to continue with the status quo if they want a signed kernel + config, while still allowing a user provided initrd (which is how the shim protocol currently works as well).

---
 .gitignore                  |   1 +
 docs/misc/efi.pandoc        |  49 +++++++++++++
 xen/arch/arm/efi/efi-boot.h |  25 ++++---
 xen/arch/x86/efi/Makefile   |   2 +-
 xen/arch/x86/efi/efi-boot.h |  11 ++-
 xen/common/efi/boot.c       |  73 +++++++++++++++-----
 xen/common/efi/efi.h        |   3 +
 xen/common/efi/pe.c         | 134 ++++++++++++++++++++++++++++++++++++
 8 files changed, 269 insertions(+), 29 deletions(-)
 create mode 100644 xen/common/efi/pe.c
.gitignore +1 -0
index 823f4743dc..d568017804 100644
@@ -299,6 +299,7 @@ xen/arch/*/efi/boot.c
 xen/arch/*/efi/compat.c
 xen/arch/*/efi/ebmalloc.c
 xen/arch/*/efi/efi.h
+xen/arch/*/efi/pe.c
 xen/arch/*/efi/runtime.c
 xen/common/config_data.S
 xen/common/config.gz
docs/misc/efi.pandoc +49 -0

52 lines not on this page · raw message

xen/arch/arm/efi/efi-boot.h +17 -8
index 27dd0b1a94..47ced1db8d 100644
@@ -375,27 +375,36 @@ static void __init noreturn efi_arch_post_exit_boot(void)
     efi_xen_start(fdt, fdt_totalsize(fdt));
 }
 
-static void __init efi_arch_cfg_file_early(EFI_FILE_HANDLE dir_handle, char *section)
+static void __init efi_arch_cfg_file_early(const EFI_LOADED_IMAGE *image,
+                                           EFI_FILE_HANDLE dir_handle,
+                                           const char *section)
 {
     union string name;
 
     /*
      * The DTB must be processed before any other entries in the configuration
-     * file, as the DTB is updated as modules are loaded.
+     * file, as the DTB is updated as modules are loaded.  Prefer the one
+     * stored as a PE section in a unified image, and fall back to a file
+     * on disk if the section is not present.
      */
-    name.s = get_value(&cfg, section, "dtb");
-    if ( name.s )
+    if ( !read_section(image, ".dtb", &dtbfile, NULL) )
     {
-        split_string(name.s);
-        read_file(dir_handle, s2w(&name), &dtbfile, NULL);
-        efi_bs->FreePool(name.w);
+        name.s = get_value(&cfg, section, "dtb");
+        if ( name.s )
+        {
+            split_string(name.s);
+            read_file(dir_handle, s2w(&name), &dtbfile, NULL);
+            efi_bs->FreePool(name.w);
+        }
     }
     fdt = fdt_increase_size(&dtbfile, cfg.size + EFI_PAGE_SIZE);
     if ( !fdt )
         blexit(L"Unable to create new FDT");
 }
 
-static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *section)
+static void __init efi_arch_cfg_file_late(const EFI_LOADED_IMAGE *image,
+                                          EFI_FILE_HANDLE dir_handle,
+                                          const char *section)
 {
 }
 
xen/arch/x86/efi/Makefile +1 -1
index 770438a029..e857c0f2cc 100644
@@ -8,7 +8,7 @@ cmd_objcopy_o_ihex = $(OBJCOPY) -I ihex -O binary $< $@
 
 boot.init.o: buildid.o
 
-EFIOBJ := boot.init.o ebmalloc.o compat.o runtime.o
+EFIOBJ := boot.init.o pe.init.o ebmalloc.o compat.o runtime.o
 
 $(call cc-option-add,cflags-stack-boundary,CC,-mpreferred-stack-boundary=4)
 $(EFIOBJ): CFLAGS-stack-boundary := $(cflags-stack-boundary)
xen/arch/x86/efi/efi-boot.h +9 -2
index eef3f52789..db3e29f573 100644
@@ -272,14 +272,21 @@ static void __init noreturn efi_arch_post_exit_boot(void)
     unreachable();
 }
 
-static void __init efi_arch_cfg_file_early(EFI_FILE_HANDLE dir_handle, char *section)
+static void __init efi_arch_cfg_file_early(const EFI_LOADED_IMAGE *image,
+                                           EFI_FILE_HANDLE dir_handle,
+                                           const char *section)
 {
 }
 
-static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char *section)
+static void __init efi_arch_cfg_file_late(const EFI_LOADED_IMAGE *image,
+                                          EFI_FILE_HANDLE dir_handle,
+                                          const char *section)
 {
     union string name;
 
+    if ( read_section(image, ".ucode", &ucode, NULL) )
+        return;
+
     name.s = get_value(&cfg, section, "ucode");
     if ( !name.s )
         name.s = get_value(&cfg, "global", "ucode");
xen/common/efi/boot.c +55 -18

112 lines not on this page · raw message

xen/common/efi/efi.h +3 -0
index 4845d84913..c9d3752121 100644
@@ -47,3 +47,6 @@ const CHAR16 *wmemchr(const CHAR16 *s, CHAR16 c, UINTN n);
 /* EFI boot allocator. */
 void *ebmalloc(size_t size);
 void free_ebmalloc_unused_mem(void);
+
+const void *pe_find_section(const void *image_base, const size_t image_size,
+                            const char *section_name, UINTN *size_out);
xen/common/efi/pe.c new file +134 -0

134 lines not on this page · raw message

Signature · 1 line
2.25.1
#8 lore raw

Re: [PATCH v5 4/5] efi: Enable booting unified hypervisor/kernel/initrd images

xen/common/efi/boot.c static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, · line 634

Quoted 10 lines · Trammell Hudson
xen/common/efi/boot.c +6 -0
@@ -624,6 +626,29 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
     return true;
 }
 
+static bool __init read_section(const EFI_LOADED_IMAGE *image,
+                                char *const name, struct file *file,
+                                const char *options)
+{
+    /* skip the leading "." in the section name */
+    union string name_string = { .s = name + 1 };

Instead of forcing the caller to pass in a dot-prefixed name and you assuming it's a dot here, how about ...

xen/common/efi/boot.c static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, · line 637

Quoted 2 lines
xen/common/efi/boot.c +2 -0
+    file->ptr = pe_find_section(image->ImageBase, image->ImageSize,
+                                name, &file->size);

... pe_find_section() looking for '.' followed by <name>?

xen/common/efi/boot.c static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, · line 644

Quoted 7 lines
xen/common/efi/boot.c +7 -0
+    if ( !file->ptr )
+        return false;
+
+    file->need_to_free = false;
+
+    if ( !s2w(&name_string) )
+        return false;

You shouldn't give the false impression to the caller that the section was not found, the more that ...

xen/common/efi/boot.c static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, · line 647

Quoted 2 lines
xen/common/efi/boot.c +2 -0
+    handle_file_info(name_string.w, file, options);
+    efi_bs->FreePool(name_string.w);

... you really need the transformation solely for producing output. Just output a static surrogate message instead if this fails? Of course, for x86'es sake you'd then need to pass the ASCII string instead, which would save it from doing the backwards translation, which is its only use of the parameter (Arm doesn't use it at all).

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 1237

Quoted 8 lines
xen/common/efi/boot.c +2 -2
@@ -1208,9 +1233,11 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
         /* Get the file system interface. */
         dir_handle = get_parent_handle(loaded_image, &file_name);
 
-        /* Read and parse the config file. */
-        if ( !cfg_file_name )
+        if ( read_section(loaded_image, ".config", &cfg, NULL) )
+            PrintStr(L"Using unified config file\r\n");

Maybe "embedded" instead of "unified"? The config file isn't unified after all, it's the Xen binary which is.

Jan

#9 lore raw

Re: [PATCH v5 4/5] efi: Enable booting unified hypervisor/kernel/initrd images

Quoted 4 lines · Jan Beulich

On 17.09.2020 17:40, Trammell Hudson wrote:
Instead of forcing the caller to pass in a dot-prefixed name and you assuming it's a dot here, how about ... ... pe_find_section() looking for '.' followed by <name>?

v6 adds a special name compare function to do this with a CHAR16 section name to avoid the extra s2w() you mentioned.

(btw, even if the EFI constness patches don't go in, just making PrintStr cast away the const would allow several of these startup functions to have const CHAR16* arguments since the only reason they are non-const is to be able to print)

Quoted 6 lines

[...]

Review

Quoted 2 lines
(quoted diff) +0 -2
-          if ( read_section(loaded_image, ".config", &cfg, NULL) )
-              PrintStr(L"Using unified config file\\r\\n");

Maybe "embedded" instead of "unified"? The config file isn't unified after all, it's the Xen binary which is.

How about "builtin"?

I missed the reviews on the need_to_free patch; they are also incorporated into v6.

--
Trammell

#10 lore raw

Re: [PATCH v5 4/5] efi: Enable booting unified hypervisor/kernel/initrd images

Quoted 6 lines · Trammell Hudson
Quoted 4 lines · Jan Beulich

On 17.09.2020 17:40, Trammell Hudson wrote:
Instead of forcing the caller to pass in a dot-prefixed name and you assuming it's a dot here, how about ... ... pe_find_section() looking for '.' followed by <name>?

Quoted 7 lines

v6 adds a special name compare function to do this with a CHAR16 section name to avoid the extra s2w() you mentioned.

(btw, even if the EFI constness patches don't go in, just making PrintStr cast away the const would allow several of these startup functions to have const CHAR16* arguments since the only reason they are non-const is to be able to print)

And I'd be happy to approve a patch to this effect, provided it uses an inline function and not a macro to do this wrapping.

Quoted 8 lines
Quoted 6 lines

[...]

Review

Quoted 2 lines
(quoted diff) +0 -2
-          if ( read_section(loaded_image, ".config", &cfg, NULL) )
-              PrintStr(L"Using unified config file\\r\\n");

Maybe "embedded" instead of "unified"? The config file isn't unified after all, it's the Xen binary which is.

How about "builtin"?

That's fine with me as well.

Jan

#11 lore raw

PATCH v5 5/5 efi: Do not use command line if unified config is included

In reply to Trammell Hudson

If a unified Xen image is used, then the bundled configuration, Xen command line, dom0 kernel, and ramdisk are prefered over any files listed in the config file or provided on the command line.

Unlike the shim based verification, the PE signature on a unified image covers all of the Xen+config+kernel+initrd modules linked into the unified image. This also ensures that, on properly configured UEFI Secure Boot platforms, the entire runtime will be measured into the TPM for unsealing secrets or remote attestation.

---
 xen/common/efi/boot.c | 43 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 5 deletions(-)
xen/common/efi/boot.c +38 -5
index c14e836640..6dc3f5ac94 100644
@@ -952,6 +952,35 @@ static void __init setup_efi_pci(void)
     efi_bs->FreePool(handles);
 }
 
+/*
+ * Logic should remain sync'ed with linux/arch/x86/xen/efi.c
+ * Secure Boot is enabled iff 'SecureBoot' is set and the system is
+ * not in Setup Mode.
+ */
+static bool __init efi_secure_boot(void)
+{
+    static __initdata EFI_GUID global_guid = EFI_GLOBAL_VARIABLE;
+    uint8_t secboot, setupmode;
+    UINTN secboot_size = sizeof(secboot);
+    UINTN setupmode_size = sizeof(setupmode);
+    EFI_STATUS rc;
+
+    rc = efi_rs->GetVariable(L"SecureBoot", &global_guid,
+                             NULL, &secboot_size, &secboot);
+    if ( rc != EFI_SUCCESS )
+        return false;
+
+    rc = efi_rs->GetVariable(L"SetupMode", &global_guid,
+                             NULL, &setupmode_size, &setupmode);
+    if ( rc != EFI_SUCCESS )
+        return false;
+
+    if ( secboot > 1 || setupmode > 1 )
+        blexit(L"Invalid SecureBoot/SetupMode variables");
+
+    return secboot == 1 && setupmode == 0;
+}
+
 static void __init efi_variables(void)
 {
     EFI_STATUS status;
@@ -1128,15 +1157,15 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
     static EFI_GUID __initdata shim_lock_guid = SHIM_LOCK_PROTOCOL_GUID;
     EFI_LOADED_IMAGE *loaded_image;
     EFI_STATUS status;
-    unsigned int i, argc;
-    CHAR16 **argv, *file_name, *cfg_file_name = NULL, *options = NULL;
+    unsigned int i, argc = 0;
+    CHAR16 **argv = NULL, *file_name, *cfg_file_name = NULL, *options = NULL;
     UINTN gop_mode = ~0;
     EFI_SHIM_LOCK_PROTOCOL *shim_lock;
     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
     union string section = { NULL }, name;
     bool base_video = false;
     const char *option_str;
-    bool use_cfg_file;
+    bool use_cfg_file, secure;
 
     __set_bit(EFI_BOOT, &efi_flags);
     __set_bit(EFI_LOADER, &efi_flags);
@@ -1155,8 +1184,10 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
         PrintErrMesg(L"No Loaded Image Protocol", status);
 
     efi_arch_load_addr_check(loaded_image);
+    secure = efi_secure_boot();
 
-    if ( use_cfg_file )
+    if ( use_cfg_file &&
+         !read_section(loaded_image, ".config", &cfg, NULL))
     {
         UINTN offset = 0;
 
@@ -1214,6 +1245,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
 
     PrintStr(L"Xen " __stringify(XEN_VERSION) "." __stringify(XEN_SUBVERSION)
              XEN_EXTRAVERSION " (c/s " XEN_CHANGESET ") EFI loader\r\n");
+    if ( secure )
+        PrintStr(L"UEFI Secure Boot enabled\r\n");
 
     efi_arch_relocate_image(0);
 
@@ -1233,7 +1266,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
         /* Get the file system interface. */
         dir_handle = get_parent_handle(loaded_image, &file_name);
 
-        if ( read_section(loaded_image, ".config", &cfg, NULL) )
+        if ( cfg.ptr )
             PrintStr(L"Using unified config file\r\n");
         else if ( !cfg_file_name )
         {
Signature · 1 line
2.25.1
#12 lore raw

Re: [PATCH v5 5/5] efi: Do not use command line if unified config is included

xen/common/efi/boot.c efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) · line 1192

Quoted 11 lines · Trammell Hudson
xen/common/efi/boot.c +3 -1
@@ -1155,8 +1184,10 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
         PrintErrMesg(L"No Loaded Image Protocol", status);
 
     efi_arch_load_addr_check(loaded_image);
+    secure = efi_secure_boot();
 
-    if ( use_cfg_file )
+    if ( use_cfg_file &&
+         !read_section(loaded_image, ".config", &cfg, NULL))
     {
         UINTN offset = 0;

I continue to think that it's wrong to ignore the command line altogether. And this isn't just for the Dom0 kernel part when there's no .kernel section, but also because there may be firmware workarounds that the user needs to be able to make use of in order for the binary to work on certain hardware.

Jan