Skip to contentSkip to conversation

GRUB: Supporting Secure Boot of xen.gz

PATCH Superseded Ross Lagerwall via Grub-devel 2 participants 27 messages Mar 13, 2024 – Mar 28, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover GRUB: Supporting Secure Boot of xen.gz

This patch series implements support for loading and verifying a signed xen.gz binary. This would allow the same xen.gz binary to be used for BIOS boot, UEFI boot, and UEFI boot with Secure Boot verification. There is an accompanying Xen patch series.

The first two patches update the multiboot2 specification with the necessary changes.

Patches 3 through 5 implement the spec changes.
Patches 6 and 7 are a couple of small changes to allow the Secure Boot verification to happen.

Ross

Diff stat for 0001 and 0002 (to be applied to the "multiboot2" branch) Ross Lagerwall (2):
multiboot2: Add load type header and support for the PE binary type
multiboot2: Allow 64-bit entry tags

 doc/multiboot.texi | 71 ++++++++++++++++++++++++++++++++++------------
 doc/multiboot2.h   | 19 ++++++++++++-
 2 files changed, 71 insertions(+), 19 deletions(-)

Diff stat for 0003 to 0007 (to be applied to the "master" branch) Ross Lagerwall (5):
multiboot2: Add support for the load type header tag
multiboot2: Add PE load support
multiboot2: Add support for 64-bit entry addresses
efi: Allow loading multiboot modules without verification
verifiers: Verify after decompression

 grub-core/Makefile.core.def       |   1 +
 grub-core/kern/efi/sb.c           |   1 +
 grub-core/loader/multiboot_mbi2.c |  66 ++-
 grub-core/loader/multiboot_pe.c   | 694 ++++++++++++++++++++++++++++++
 include/grub/efi/pe32.h           |  64 +++
 include/grub/file.h               |   2 +-
 include/grub/multiboot2.h         |   4 +
 include/multiboot2.h              |  19 +-
 8 files changed, 844 insertions(+), 7 deletions(-)
 create mode 100644 grub-core/loader/multiboot_pe.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/7 multiboot2: Add load type header and support for the PE binary type

Currently, multiboot2-compatible bootloaders can load ELF binaries and a.out binaries. The presence of the address header tag determines how the bootloader tries to interpret the binary (a.out if the address tag is present else ELF).

Add a new load type header tag that explicitly states the type of the binary. Bootloaders should use the binary type specified in the load type tag. If the load type tag is not present, the bootloader should fall back to the previous heuristics.

In addition to the existing address and ELF load types, specify a new optional PE binary load type. This new type is a useful addition since PE binaries can be signed and verified (i.e. used with Secure Boot).

---
 doc/multiboot.texi | 39 ++++++++++++++++++++++++++++++++++-----
 doc/multiboot2.h   | 13 +++++++++++++
 2 files changed, 47 insertions(+), 5 deletions(-)
doc/multiboot.texi +34 -5
index df8a0d056e76..d12719c744eb 100644
@@ -511,11 +511,12 @@ assumes that no bss segment is present.
 
 Note: This information does not need to be provided if the kernel image
 is in @sc{elf} format, but it must be provided if the image is in a.out
-format or in some other format. When the address tag is present it must
-be used in order to load the image, regardless of whether an @sc{elf}
-header is also present. Compliant boot loaders must be able to load
-images that are either in @sc{elf} format or contain the address tag
-embedded in the Multiboot2 header.
+format or in some other format. If the load type tag is not specified
+and the address tag is present it must be used in order to load the
+image, regardless of whether an @sc{elf} header is also present.
+Compliant boot loaders must be able to load images that are either in
+@sc{elf} format or contain the address tag embedded in the Multiboot2
+header.
 
 @subsection The entry address tag of Multiboot2 header
 
@@ -732,6 +733,34 @@ and @samp{2} means load image at highest possible address but not
 higher than max_addr.
 @end table
 
+@node Load type tag
+@subsection Load type tag
+
+@example
+@group
+        +-------------------+
+u16     | type = 11         |
+u16     | flags             |
+u32     | size = 12         |
+u32     | load_type         |
+        +-------------------+
+@end group
+@end example
+
+This tag indicates the type of the payload and how the boot loader
+should load it.
+
+The meaning of each field is as follows:
+
+@table @code
+@item load_type
+Recognized load types are @samp{0} for address (i.e. load a.out using
+the address tag), @samp{1} for ELF, and @samp{2} for PE. Compliant
+bootloaders should implement support for a.out and ELF as a minimum.  If
+this tag is not specified, the boot loader should attempt to load the
+payload using the information specified in the address tag if present,
+else it should load the payload as an ELF binary.  @end table
+
 @node Machine state
 @section MIPS machine state
 
doc/multiboot2.h +13 -0
index b181607075b2..d4cae05706e4 100644
@@ -75,6 +75,7 @@
 #define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI32  8
 #define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64  9
 #define MULTIBOOT_HEADER_TAG_RELOCATABLE  10
+#define MULTIBOOT_HEADER_TAG_LOAD_TYPE  11
 
 #define MULTIBOOT_ARCHITECTURE_I386  0
 #define MULTIBOOT_ARCHITECTURE_MIPS32  4
@@ -179,6 +180,18 @@ struct multiboot_header_tag_relocatable
   multiboot_uint32_t preference;
 };
 
+struct multiboot_header_tag_load_type
+{
+  multiboot_uint16_t type;
+  multiboot_uint16_t flags;
+  multiboot_uint32_t size;
+#define MULTIBOOT_LOAD_TYPE_ADDRESS     0
+#define MULTIBOOT_LOAD_TYPE_ELF         1
+#define MULTIBOOT_LOAD_TYPE_PE          2
+#define MULTIBOOT_LOAD_TYPE_TOTAL       3
+  multiboot_uint32_t load_type;
+};
+
 struct multiboot_color
 {
   multiboot_uint8_t red;
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 1/7] multiboot2: Add load type header and support for the PE binary type

Quoted 3 lines · Ross Lagerwall

In addition to the existing address and ELF load types, specify a new optional PE binary load type. This new type is a useful addition since PE binaries can be signed and verified (i.e. used with Secure Boot).

And the consideration to have ELF signable (by whatever extension to the ELF spec) went nowhere?

Jan

#3 lore raw

Re: [PATCH 1/7] multiboot2: Add load type header and support for the PE binary type

Hi, I saw this on the list and have concerns:

-------- Original Message --------
On 14 Mar 2024, 6:24 pm, Jan Beulich via Grub-devel < [email protected]> wrote:

Quoted 5 lines · Ross Lagerwall
Quoted 3 lines

In addition to the existing address and ELF load types, specify a new optional PE binary load type. This new type is a useful addition since PE binaries can be signed and verified (i.e. used with Secure Boot).

And the consideration to have ELF signable (by whatever extension to the ELF spec) went nowhere? Jan

If the purpose of signing binaries is to prevent their execution unless they are signed by their owner, this is MALWARE unless the end user can replace the keys with one of their choosing.
Adding a field to elf to provide this feature is IMHO asking for trouble because the key is stored elsewhere and there is nothing to prevent abuse of this field to deny users their freedom to run code, (ie by not providing them the key or a guaranteed mechanism for providing their own).

On that note, why is it such a useful feature to restrict the freedom to run code in grub? If grub selects malware to execute, the user must have chosen to run it - or grub itself is compromised?

Do you think that locking binaries down is the future for users to ensure their own security or it is acceptable for 3rd parties to hide platform keys to lock all systems down, even by binary?

I'm not convinced.

Damien Zammit
GNU/Hurd hacker

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#4 lore raw

Re: [PATCH 1/7] multiboot2: Add load type header and support for the PE binary type

In reply to Jan Beulich via Grub-devel

Please take this discussion to a separate thread. In this thread it's pure offtopic

Quoted 15 lines · Jan Beulich via Grub-devel
Quoted 3 lines · Ross Lagerwall

In addition to the existing address and ELF load types, specify a new optional PE binary load type. This new type is a useful addition since PE binaries can be signed and verified (i.e. used with Secure Boot).

And the consideration to have ELF signable (by whatever extension to the ELF spec) went nowhere?

Jan

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 7 lines
Regards
Vladimir 'phcoder' Serbinenko

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#5 lore raw

Re: [PATCH 1/7] multiboot2: Add load type header and support for the PE binary type

In reply to Jan Beulich via Grub-devel
Quoted 9 lines · Jan Beulich
Quoted 3 lines · Ross Lagerwall

In addition to the existing address and ELF load types, specify a new optional PE binary load type. This new type is a useful addition since PE binaries can be signed and verified (i.e. used with Secure Boot).

And the consideration to have ELF signable (by whatever extension to the ELF spec) went nowhere?

I'm not sure if you're referring to some ongoing work to create signable ELFs that I'm not aware of.

I didn't choose that route because:

* Signed PE binaries are the current standard for Secure Boot.

* Having signed ELF binaries would mean that code to handle them needs to be added to Shim which contravenes its goals of being small and simple to verify.

* I could be wrong on this but to my knowledge, the ELF format is not being actively updated nor is the standard owned/maintained by a specific group which makes updating it difficult.

* Tools would need to be updated/developed to add support for signing ELF binaries and inspecting the signatures.

I am open to suggestions of course but I'm not sure what benefits there would be to going the ELF route.

Ross

#6 lore raw

Re: [PATCH 1/7] multiboot2: Add load type header and support for the PE binary type

Quoted 7 lines · Ross Lagerwall
Quoted 6 lines · Jan Beulich
Quoted 3 lines · Ross Lagerwall

In addition to the existing address and ELF load types, specify a new optional PE binary load type. This new type is a useful addition since PE binaries can be signed and verified (i.e. used with Secure Boot).

Quoted 6 lines
Quoted 3 lines

And the consideration to have ELF signable (by whatever extension to the ELF spec) went nowhere?

I'm not sure if you're referring to some ongoing work to create signable ELFs that I'm not aware of.

Something must have been invented already to make Linux modules signable.

Quoted 7 lines

I didn't choose that route because:

* Signed PE binaries are the current standard for Secure Boot.

* Having signed ELF binaries would mean that code to handle them needs to be added to Shim which contravenes its goals of being small and simple to verify.

Both true, but neither goes entirely without saying, I suppose.

Quoted 3 lines

* I could be wrong on this but to my knowledge, the ELF format is not being actively updated nor is the standard owned/maintained by a specific group which makes updating it difficult.

And PE/COFF isn't under control of a public entity / group afaik, which may be viewed as no better, if not worse.

Quoted 2 lines

* Tools would need to be updated/developed to add support for signing ELF binaries and inspecting the signatures.

As above, yes indeed.

Jan

#7 lore raw

Re: [PATCH 1/7] multiboot2: Add load type header and support for the PE binary type

Quoted 9 lines · Jan Beulich
Quoted 7 lines · Ross Lagerwall
Quoted 6 lines · Jan Beulich
Quoted 3 lines · Ross Lagerwall

In addition to the existing address and ELF load types, specify a new optional PE binary load type. This new type is a useful addition since PE binaries can be signed and verified (i.e. used with Secure Boot).

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

And the consideration to have ELF signable (by whatever extension to the ELF spec) went nowhere?

I'm not sure if you're referring to some ongoing work to create signable ELFs that I'm not aware of.

Something must have been invented already to make Linux modules signable.

Linux module signatures operate outside of the ELF container. In fact, AFAIK the actual signed content could be anything. The file format is:

* Content (i.e. ELF binary)
* Signature of content in PKCS7 format
* Signature info, including signature length
* Magic marker: "~Module signature appended~\n"

This kind of arrangement does indeed work but it is fragile. Since the signature is on the entire contents and tools that understand ELF don't parse the signature, any transformation of the binary (e.g. to strip out debuginfo) will cause the signature to be lost / invalidated.

Nevertheless, this could still be an option for Xen if this is deemed to be a preferred solution by others. It would be good to hear some opinions on this.

Quoted 9 lines
Quoted 8 lines

I didn't choose that route because:

* Signed PE binaries are the current standard for Secure Boot.

* Having signed ELF binaries would mean that code to handle them needs to be added to Shim which contravenes its goals of being small and simple to verify.

Quoted 8 lines

Both true, but neither goes entirely without saying, I suppose.

Quoted 3 lines

* I could be wrong on this but to my knowledge, the ELF format is not being actively updated nor is the standard owned/maintained by a specific group which makes updating it difficult.

And PE/COFF isn't under control of a public entity / group afaik, which may be viewed as no better, if not worse.

Agreed, I guess my point was that PE/COFF doesn't need to be updated to support signing because it already supports it.

Thanks,
Ross

#8 lore raw

Re: [PATCH 1/7] multiboot2: Add load type header and support for the PE binary type

Quoted 24 lines · Ross Lagerwall
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Ross Lagerwall
Quoted 5 lines · Jan Beulich
Quoted 3 lines · Ross Lagerwall

In addition to the existing address and ELF load types, specify a new optional PE binary load type. This new type is a useful addition since PE binaries can be signed and verified (i.e. used with Secure Boot).

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

And the consideration to have ELF signable (by whatever extension to the ELF spec) went nowhere?

I'm not sure if you're referring to some ongoing work to create signable ELFs that I'm not aware of.

Something must have been invented already to make Linux modules signable.

Linux module signatures operate outside of the ELF container. In fact, AFAIK the actual signed content could be anything. The file format is:

* Content (i.e. ELF binary)
* Signature of content in PKCS7 format
* Signature info, including signature length
* Magic marker: "~Module signature appended~\n"

Quoted 4 lines

This kind of arrangement does indeed work but it is fragile. Since the signature is on the entire contents and tools that understand ELF don't parse the signature, any transformation of the binary (e.g. to strip out debuginfo) will cause the signature to be lost / invalidated.

This looks extremely poor to me, so ...

Quoted 3 lines

Nevertheless, this could still be an option for Xen if this is deemed to be a preferred solution by others. It would be good to hear some opinions on this.

... I'd rather not see this used for Xen.

Jan

#9 lore raw

Re: [PATCH 1/7] multiboot2: Add load type header and support for the PE binary type

In reply to Ross Lagerwall via Grub-devel
Quoted 27 lines · Ross Lagerwall
Quoted 9 lines · Jan Beulich
Quoted 7 lines · Ross Lagerwall
Quoted 6 lines · Jan Beulich
Quoted 3 lines · Ross Lagerwall

In addition to the existing address and ELF load types, specify a new optional PE binary load type. This new type is a useful addition since PE binaries can be signed and verified (i.e. used with Secure Boot).

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

And the consideration to have ELF signable (by whatever extension to the ELF spec) went nowhere?

I'm not sure if you're referring to some ongoing work to create signable ELFs that I'm not aware of.

Something must have been invented already to make Linux modules signable.

Linux module signatures operate outside of the ELF container. In fact, AFAIK the actual signed content could be anything. The file format is:

* Content (i.e. ELF binary)
* Signature of content in PKCS7 format
* Signature info, including signature length
* Magic marker: "~Module signature appended~\n"

Quoted 8 lines

This kind of arrangement does indeed work but it is fragile. Since the signature is on the entire contents and tools that understand ELF don't parse the signature, any transformation of the binary (e.g. to strip out debuginfo) will cause the signature to be lost / invalidated.

Nevertheless, this could still be an option for Xen if this is deemed to be a preferred solution by others. It would be good to hear some opinions on this.

No, IMO the PE route is likely the best one, as there's already all the tooling around it, and it's what other OSes use to perform secure boot.

It would have been nice for ELF to grow an extension to the spec for image integrity data, but I don't see myself doing the work TBH.

Thanks, Roger.

#10 lore raw

Re: [PATCH 1/7] multiboot2: Add load type header and support for the PE binary type

In reply to Ross Lagerwall via Grub-devel
Quoted 63 lines · Ross Lagerwall

Currently, multiboot2-compatible bootloaders can load ELF binaries and a.out binaries. The presence of the address header tag determines how the bootloader tries to interpret the binary (a.out if the address tag is present else ELF).

Add a new load type header tag that explicitly states the type of the binary. Bootloaders should use the binary type specified in the load type tag. If the load type tag is not present, the bootloader should fall back to the previous heuristics.

In addition to the existing address and ELF load types, specify a new optional PE binary load type. This new type is a useful addition since PE binaries can be signed and verified (i.e. used with Secure Boot).

---
 doc/multiboot.texi | 39 ++++++++++++++++++++++++++++++++++-----
 doc/multiboot2.h   | 13 +++++++++++++
 2 files changed, 47 insertions(+), 5 deletions(-)
doc/multiboot.texi +23 -5
index df8a0d056e76..d12719c744eb 100644
@@ -511,11 +511,12 @@ assumes that no bss segment is present.
 
 Note: This information does not need to be provided if the kernel image
 is in @sc{elf} format, but it must be provided if the image is in a.out
-format or in some other format. When the address tag is present it must
-be used in order to load the image, regardless of whether an @sc{elf}
-header is also present. Compliant boot loaders must be able to load
-images that are either in @sc{elf} format or contain the address tag
-embedded in the Multiboot2 header.
+format or in some other format. If the load type tag is not specified
+and the address tag is present it must be used in order to load the
+image, regardless of whether an @sc{elf} header is also present.
+Compliant boot loaders must be able to load images that are either in
+@sc{elf} format or contain the address tag embedded in the Multiboot2
+header.
 
 @subsection The entry address tag of Multiboot2 header
 
@@ -732,6 +733,34 @@ and @samp{2} means load image at highest possible address but not
 higher than max_addr.
 @end table
 
+@node Load type tag
+@subsection Load type tag
+
+@example
+@group
+        +-------------------+
+u16     | type = 11         |
+u16     | flags             |
+u32     | size = 12         |
+u32     | load_type         |
+        +-------------------+
+@end group
+@end example
+
+This tag indicates the type of the payload and how the boot loader
+should load it.
+

doc/multiboot.texi and @samp{2} means load image at highest possible address but not · line 762

Quoted 10 lines
doc/multiboot.texi +10 -0
+The meaning of each field is as follows:
+
+@table @code
+@item load_type
+Recognized load types are @samp{0} for address (i.e. load a.out using
+the address tag), @samp{1} for ELF, and @samp{2} for PE. Compliant
+bootloaders should implement support for a.out and ELF as a minimum.  If
+this tag is not specified, the boot loader should attempt to load the
+payload using the information specified in the address tag if present,
+else it should load the payload as an ELF binary.  @end table

I wonder if it would be simpler to use the following order instead:

1. Address tag
2. Load type tag
3. ELF header

It's pointless to add a Loader type tag with load_type == 0, as that's already mandated by the Address tag. IOW: signaling the use of the Address tag here is kind of pointless, if the fields in the Address tag are set, that's the only signaling required for the data in the Address tag to be used.

Or are we attempting to support images that set Address tag and Load type tag != 0 in order to use the Address tag when the loader doesn't recognize the Load type tag, and otherwise use a different format?

Would it be sensible for multiboot2 to use PE in preference to ELF if present on the image? (without requiring any signaling). I would think this could be troublesome if kernels are so far expecting the ELF header to be used with multiboot2, even if they also expose a PE header.

Thanks, Roger.

#11 lore raw

Re: [PATCH 1/7] multiboot2: Add load type header and support for the PE binary type

Quoted 88 lines · Roger Pau Monné
Quoted 63 lines · Ross Lagerwall

Currently, multiboot2-compatible bootloaders can load ELF binaries and a.out binaries. The presence of the address header tag determines how the bootloader tries to interpret the binary (a.out if the address tag is present else ELF).

Add a new load type header tag that explicitly states the type of the binary. Bootloaders should use the binary type specified in the load type tag. If the load type tag is not present, the bootloader should fall back to the previous heuristics.

In addition to the existing address and ELF load types, specify a new optional PE binary load type. This new type is a useful addition since PE binaries can be signed and verified (i.e. used with Secure Boot).

---
 doc/multiboot.texi | 39 ++++++++++++++++++++++++++++++++++-----
 doc/multiboot2.h   | 13 +++++++++++++
 2 files changed, 47 insertions(+), 5 deletions(-)
doc/multiboot.texi +23 -5
index df8a0d056e76..d12719c744eb 100644
@@ -511,11 +511,12 @@ assumes that no bss segment is present.
 
 Note: This information does not need to be provided if the kernel image
 is in @sc{elf} format, but it must be provided if the image is in a.out
-format or in some other format. When the address tag is present it must
-be used in order to load the image, regardless of whether an @sc{elf}
-header is also present. Compliant boot loaders must be able to load
-images that are either in @sc{elf} format or contain the address tag
-embedded in the Multiboot2 header.
+format or in some other format. If the load type tag is not specified
+and the address tag is present it must be used in order to load the
+image, regardless of whether an @sc{elf} header is also present.
+Compliant boot loaders must be able to load images that are either in
+@sc{elf} format or contain the address tag embedded in the Multiboot2
+header.
 
 @subsection The entry address tag of Multiboot2 header
 
@@ -732,6 +733,34 @@ and @samp{2} means load image at highest possible address but not
 higher than max_addr.
 @end table
 
+@node Load type tag
+@subsection Load type tag
+
+@example
+@group
+        +-------------------+
+u16     | type = 11         |
+u16     | flags             |
+u32     | size = 12         |
+u32     | load_type         |
+        +-------------------+
+@end group
+@end example
+
+This tag indicates the type of the payload and how the boot loader
+should load it.
+

doc/multiboot.texi and @samp{2} means load image at highest possible address but not · line 762

Quoted 10 lines
doc/multiboot.texi +10 -0
+The meaning of each field is as follows:
+
+@table @code
+@item load_type
+Recognized load types are @samp{0} for address (i.e. load a.out using
+the address tag), @samp{1} for ELF, and @samp{2} for PE. Compliant
+bootloaders should implement support for a.out and ELF as a minimum.  If
+this tag is not specified, the boot loader should attempt to load the
+payload using the information specified in the address tag if present,
+else it should load the payload as an ELF binary.  @end table

I wonder if it would be simpler to use the following order instead:

1. Address tag
2. Load type tag
3. ELF header

It's pointless to add a Loader type tag with load_type == 0, as that's already mandated by the Address tag. IOW: signaling the use of the Address tag here is kind of pointless, if the fields in the Address tag are set, that's the only signaling required for the data in the Address tag to be used.

Quoted 3 lines

Or are we attempting to support images that set Address tag and Load type tag != 0 in order to use the Address tag when the loader doesn't recognize the Load type tag, and otherwise use a different format?

No, that wasn't my intention. My intention for the load type tag was to have one tag that unambiguously describes the payload format and if that is missing, fall back to the previous logic for compatibility. It avoids more complicated heuristics if different payload types are added in the future.

Quoted 7 lines

Would it be sensible for multiboot2 to use PE in preference to ELF if present on the image? (without requiring any signaling). I would think this could be troublesome if kernels are so far expecting the ELF header to be used with multiboot2, even if they also expose a PE header.

AFAIK an ELF image can't also be a valid PE/COFF image since they have different magic numbers at the start of the image. Perhaps it would be simpler to avoid introducing the load type tag and just load the payload based on the magic number?

Ross

#12 lore raw

Re: [PATCH 1/7] multiboot2: Add load type header and support for the PE binary type

Quoted 107 lines · Ross Lagerwall
Quoted 88 lines · Roger Pau Monné
Quoted 63 lines · Ross Lagerwall

Currently, multiboot2-compatible bootloaders can load ELF binaries and a.out binaries. The presence of the address header tag determines how the bootloader tries to interpret the binary (a.out if the address tag is present else ELF).

Add a new load type header tag that explicitly states the type of the binary. Bootloaders should use the binary type specified in the load type tag. If the load type tag is not present, the bootloader should fall back to the previous heuristics.

In addition to the existing address and ELF load types, specify a new optional PE binary load type. This new type is a useful addition since PE binaries can be signed and verified (i.e. used with Secure Boot).

---
 doc/multiboot.texi | 39 ++++++++++++++++++++++++++++++++++-----
 doc/multiboot2.h   | 13 +++++++++++++
 2 files changed, 47 insertions(+), 5 deletions(-)
doc/multiboot.texi +23 -5
index df8a0d056e76..d12719c744eb 100644
@@ -511,11 +511,12 @@ assumes that no bss segment is present.
 
 Note: This information does not need to be provided if the kernel image
 is in @sc{elf} format, but it must be provided if the image is in a.out
-format or in some other format. When the address tag is present it must
-be used in order to load the image, regardless of whether an @sc{elf}
-header is also present. Compliant boot loaders must be able to load
-images that are either in @sc{elf} format or contain the address tag
-embedded in the Multiboot2 header.
+format or in some other format. If the load type tag is not specified
+and the address tag is present it must be used in order to load the
+image, regardless of whether an @sc{elf} header is also present.
+Compliant boot loaders must be able to load images that are either in
+@sc{elf} format or contain the address tag embedded in the Multiboot2
+header.
 
 @subsection The entry address tag of Multiboot2 header
 
@@ -732,6 +733,34 @@ and @samp{2} means load image at highest possible address but not
 higher than max_addr.
 @end table
 
+@node Load type tag
+@subsection Load type tag
+
+@example
+@group
+        +-------------------+
+u16     | type = 11         |
+u16     | flags             |
+u32     | size = 12         |
+u32     | load_type         |
+        +-------------------+
+@end group
+@end example
+
+This tag indicates the type of the payload and how the boot loader
+should load it.
+

doc/multiboot.texi and @samp{2} means load image at highest possible address but not · line 762

Quoted 10 lines
doc/multiboot.texi +10 -0
+The meaning of each field is as follows:
+
+@table @code
+@item load_type
+Recognized load types are @samp{0} for address (i.e. load a.out using
+the address tag), @samp{1} for ELF, and @samp{2} for PE. Compliant
+bootloaders should implement support for a.out and ELF as a minimum.  If
+this tag is not specified, the boot loader should attempt to load the
+payload using the information specified in the address tag if present,
+else it should load the payload as an ELF binary.  @end table

I wonder if it would be simpler to use the following order instead:

1. Address tag
2. Load type tag
3. ELF header

It's pointless to add a Loader type tag with load_type == 0, as that's already mandated by the Address tag. IOW: signaling the use of the Address tag here is kind of pointless, if the fields in the Address tag are set, that's the only signaling required for the data in the Address tag to be used.

Quoted 3 lines

Or are we attempting to support images that set Address tag and Load type tag != 0 in order to use the Address tag when the loader doesn't recognize the Load type tag, and otherwise use a different format?

No, that wasn't my intention. My intention for the load type tag was to have one tag that unambiguously describes the payload format and if that is missing, fall back to the previous logic for compatibility. It avoids more complicated heuristics if different payload types are added in the future.

Quoted 7 lines

Would it be sensible for multiboot2 to use PE in preference to ELF if present on the image? (without requiring any signaling). I would think this could be troublesome if kernels are so far expecting the ELF header to be used with multiboot2, even if they also expose a PE header.

Quoted 4 lines

AFAIK an ELF image can't also be a valid PE/COFF image since they have different magic numbers at the start of the image. Perhaps it would be simpler to avoid introducing the load type tag and just load the payload based on the magic number?

I would likely be fine with just handling it like we handle ELF, if a PE header is found use it. As long as ELF and PE headers are mutually exclusive.

Thanks, Roger.

#13 lore raw

PATCH 2/7 multiboot2: Allow 64-bit entry tags

In reply to Ross Lagerwall via Grub-devel

Binaries may be built with entry points above 4G. While bootloaders may relocate them below 4G, it should be possible for the binary to specify those entry points. Therefore, extend the multiboot2 protocol such that 64 bit addresses are allowed for entry points. The extension is done in a backwards-compatible way.

---
 doc/multiboot.texi | 32 +++++++++++++++++++-------------
 doc/multiboot2.h   |  6 +++++-
 2 files changed, 24 insertions(+), 14 deletions(-)
doc/multiboot.texi +19 -13
index d12719c744eb..049afab53c1f 100644
@@ -522,12 +522,12 @@ header.
 
 @example
 @group
-        +-------------------+
-u16     | type = 3          |
-u16     | flags             |
-u32     | size              |
-u32     | entry_addr        |
-        +-------------------+
+          +-------------------+
+u16       | type = 3          |
+u16       | flags             |
+u32       | size              |
+u32 / u64 | entry_addr        |
+          +-------------------+
 @end group
 @end example
 
@@ -538,7 +538,10 @@ The meaning of each is as follows:
 
 @item entry_addr
 The physical address to which the boot loader should jump in order to
-start running the operating system.
+start running the operating system. @samp{entry_addr} may be specified
+either as a @samp{u32} or @samp{u64}. The bootloader should use the
+header size to determine the size of @samp{entry_addr}.
+
 @end table
 
 @subsection EFI i386 entry address tag of Multiboot2 header
@@ -573,12 +576,12 @@ tag of Multiboot2 header are ignored.
 
 @example
 @group
-        +-------------------+
-u16     | type = 9          |
-u16     | flags             |
-u32     | size              |
-u32     | entry_addr        |
-        +-------------------+
+          +-------------------+
+u16       | type = 9          |
+u16       | flags             |
+u32       | size              |
+u32 / u64 | entry_addr        |
+          +-------------------+
 @end group
 @end example
 
@@ -594,6 +597,9 @@ is as follows:
 @item entry_addr
 The physical address to which the boot loader should jump in order to
 start running EFI amd64 compatible operating system code.
+@samp{entry_addr} may be specified either as a @samp{u32} or @samp{u64}.
+The bootloader should use the header size to determine the size of
+@samp{entry_addr}.
 @end table
 
 This tag is taken into account only on EFI amd64 platforms
doc/multiboot2.h +5 -1
index d4cae05706e4..a994a7b28b02 100644
@@ -141,7 +141,11 @@ struct multiboot_header_tag_entry_address
   multiboot_uint16_t type;
   multiboot_uint16_t flags;
   multiboot_uint32_t size;
-  multiboot_uint32_t entry_addr;
+  union
+  {
+    multiboot_uint32_t entry_addr32;
+    multiboot_uint64_t entry_addr64;
+  };
 };
 
 struct multiboot_header_tag_console_flags
Signature · 1 line
2.43.0
#14 lore raw

Re: [PATCH 2/7] multiboot2: Allow 64-bit entry tags

Quoted 22 lines · Ross Lagerwall

Binaries may be built with entry points above 4G. While bootloaders may relocate them below 4G, it should be possible for the binary to specify those entry points. Therefore, extend the multiboot2 protocol such that 64 bit addresses are allowed for entry points. The extension is done in a backwards-compatible way.

---
 doc/multiboot.texi | 32 +++++++++++++++++++-------------
 doc/multiboot2.h   |  6 +++++-
 2 files changed, 24 insertions(+), 14 deletions(-)
doc/multiboot.texi +0 -2
index d12719c744eb..049afab53c1f 100644
@@ -522,12 +522,12 @@ header.
 
 @example
 @group
-        +-------------------+
-u16     | type = 3          |

doc/multiboot.texi header. · line 530

Quoted 10 lines
doc/multiboot.texi +6 -4
-u16     | flags             |
-u32     | size              |
-u32     | entry_addr        |
-        +-------------------+
+          +-------------------+
+u16       | type = 3          |
+u16       | flags             |
+u32       | size              |
+u32 / u64 | entry_addr        |
+          +-------------------+

I might be confused, but this entry point is used in 32bit protected mode, and hence a 64bit value is simply impossible to use according to the protocol in "3.3 I386 machine state".

Unless that section is expanded to describe other protocols that use the entry address in a way where 64bits could be meaningful it seems pointless to expand the field.

Quoted 21 lines
doc/multiboot.texi +4 -3
 @end group
 @end example
 
@@ -538,7 +538,10 @@ The meaning of each is as follows:
 
 @item entry_addr
 The physical address to which the boot loader should jump in order to
-start running the operating system.
+start running the operating system. @samp{entry_addr} may be specified
+either as a @samp{u32} or @samp{u64}. The bootloader should use the
+header size to determine the size of @samp{entry_addr}.
+
 @end table
 
 @subsection EFI i386 entry address tag of Multiboot2 header
@@ -573,12 +576,12 @@ tag of Multiboot2 header are ignored.
 
 @example
 @group
-        +-------------------+
-u16     | type = 9          |

doc/multiboot.texi tag of Multiboot2 header are ignored. · line 584

Quoted 10 lines
doc/multiboot.texi +6 -4
-u16     | flags             |
-u32     | size              |
-u32     | entry_addr        |
-        +-------------------+
+          +-------------------+
+u16       | type = 9          |
+u16       | flags             |
+u32       | size              |
+u32 / u64 | entry_addr        |
+          +-------------------+

This does seem sensible.

Thanks, Roger.

#15 lore raw

Re: [PATCH 2/7] multiboot2: Allow 64-bit entry tags

Quoted 39 lines · Roger Pau Monné
Quoted 22 lines · Ross Lagerwall

Binaries may be built with entry points above 4G. While bootloaders may relocate them below 4G, it should be possible for the binary to specify those entry points. Therefore, extend the multiboot2 protocol such that 64 bit addresses are allowed for entry points. The extension is done in a backwards-compatible way.

---
 doc/multiboot.texi | 32 +++++++++++++++++++-------------
 doc/multiboot2.h   |  6 +++++-
 2 files changed, 24 insertions(+), 14 deletions(-)
doc/multiboot.texi +0 -2
index d12719c744eb..049afab53c1f 100644
@@ -522,12 +522,12 @@ header.
 
 @example
 @group
-        +-------------------+
-u16     | type = 3          |

doc/multiboot.texi header. · line 530

Quoted 10 lines
doc/multiboot.texi +6 -4
-u16     | flags             |
-u32     | size              |
-u32     | entry_addr        |
-        +-------------------+
+          +-------------------+
+u16       | type = 3          |
+u16       | flags             |
+u32       | size              |
+u32 / u64 | entry_addr        |
+          +-------------------+

I might be confused, but this entry point is used in 32bit protected mode, and hence a 64bit value is simply impossible to use according to the protocol in "3.3 I386 machine state".

Quoted 3 lines

Unless that section is expanded to describe other protocols that use the entry address in a way where 64bits could be meaningful it seems pointless to expand the field.

I changed this because the same binary is being used for both BIOS boot and UEFI boot, therefore it may have a base address above 4 GiB. Despite that, it is expected that GRUB would relocate the binary below 4 GiB so BIOS boot would still work.

However, on reflection this is kind of nasty. I've managed to build Xen in such a way that this is no longer needed so I can drop this change from the next version of this series.

Ross

#16 lore raw

Re: [PATCH 2/7] multiboot2: Allow 64-bit entry tags

Quoted 40 lines · Ross Lagerwall
Quoted 39 lines · Roger Pau Monné
Quoted 22 lines · Ross Lagerwall

Binaries may be built with entry points above 4G. While bootloaders may relocate them below 4G, it should be possible for the binary to specify those entry points. Therefore, extend the multiboot2 protocol such that 64 bit addresses are allowed for entry points. The extension is done in a backwards-compatible way.

---
 doc/multiboot.texi | 32 +++++++++++++++++++-------------
 doc/multiboot2.h   |  6 +++++-
 2 files changed, 24 insertions(+), 14 deletions(-)
doc/multiboot.texi +0 -2
index d12719c744eb..049afab53c1f 100644
@@ -522,12 +522,12 @@ header.
 
 @example
 @group
-        +-------------------+
-u16     | type = 3          |

doc/multiboot.texi header. · line 530

Quoted 10 lines
doc/multiboot.texi +6 -4
-u16     | flags             |
-u32     | size              |
-u32     | entry_addr        |
-        +-------------------+
+          +-------------------+
+u16       | type = 3          |
+u16       | flags             |
+u32       | size              |
+u32 / u64 | entry_addr        |
+          +-------------------+

I might be confused, but this entry point is used in 32bit protected mode, and hence a 64bit value is simply impossible to use according to the protocol in "3.3 I386 machine state".

Quoted 8 lines
Quoted 3 lines

Unless that section is expanded to describe other protocols that use the entry address in a way where 64bits could be meaningful it seems pointless to expand the field.

I changed this because the same binary is being used for both BIOS boot and UEFI boot, therefore it may have a base address above 4 GiB. Despite that, it is expected that GRUB would relocate the binary below 4 GiB so BIOS boot would still work.

Right, for UEFI boot it's possible to have entry addresses above 4GB, because the entry point is called in long mode with identity page tables (and hence you can put addresses in %rip past the 4GB boundary).

However the multiboot entry point puts the CPU in 32bit protected mode, and hence %eip can only hold a value below the 4GB boundary.

It's technically impossible to use an entry point above 4GB, unless there's something that I'm missing that changes the initial CPU state for the multiboot2 entry point.

Thanks, Roger.

#17 lore raw

PATCH 3/7 multiboot2: Add support for the load type header tag

In reply to Ross Lagerwall via Grub-devel

The binary may expose its type using the load type header tag. Implement it according to the specification.

---
 grub-core/loader/multiboot_mbi2.c | 45 ++++++++++++++++++++++++++++---
 include/grub/multiboot2.h         |  1 +
 include/multiboot2.h              | 13 +++++++++
 3 files changed, 56 insertions(+), 3 deletions(-)
grub-core/loader/multiboot_mbi2.c +42 -3
index 00a48413c013..6ef4f265070a 100644
@@ -119,10 +119,12 @@ grub_multiboot2_load (grub_file_t file, const char *filename)
   grub_uint32_t console_required = 0;
   struct multiboot_header_tag_framebuffer *fbtag = NULL;
   int accepted_consoles = GRUB_MULTIBOOT2_CONSOLE_EGA_TEXT;
+  struct multiboot_header_tag_load_type *load_type_tag;
   mbi_load_data_t mld;
 
   mld.mbi_ver = 2;
   mld.relocatable = 0;
+  mld.load_type = MULTIBOOT_LOAD_TYPE_TOTAL;
 
   mld.buffer = grub_malloc (MULTIBOOT_SEARCH);
   if (!mld.buffer)
@@ -258,6 +260,17 @@ grub_multiboot2_load (grub_file_t file, const char *filename)
 #endif
 	break;
 
+      case MULTIBOOT_HEADER_TAG_LOAD_TYPE:
+        load_type_tag = (struct multiboot_header_tag_load_type *) tag;
+        mld.load_type = load_type_tag->load_type;
+        if (mld.load_type >= MULTIBOOT_LOAD_TYPE_TOTAL)
+          {
+              grub_free (mld.buffer);
+              return grub_error (GRUB_ERR_UNKNOWN_OS,
+                                 "unsupported load type: %u", load_type_tag->load_type);
+          }
+        break;
+
       default:
 	if (! (tag->flags & MULTIBOOT_HEADER_TAG_OPTIONAL))
 	  {
@@ -268,14 +281,32 @@ grub_multiboot2_load (grub_file_t file, const char *filename)
 	break;
       }
 
-  if (addr_tag && !entry_specified && !(keep_bs && efi_entry_specified))
+  if (mld.load_type == MULTIBOOT_LOAD_TYPE_ADDRESS && !addr_tag)
+    {
+      grub_free (mld.buffer);
+      return grub_error (GRUB_ERR_UNKNOWN_OS,
+                         "load type address without address tag");
+    }
+  if (mld.load_type < MULTIBOOT_LOAD_TYPE_TOTAL &&
+      mld.load_type != MULTIBOOT_LOAD_TYPE_ADDRESS && addr_tag)
+    {
+      grub_free (mld.buffer);
+      return grub_error (GRUB_ERR_UNKNOWN_OS,
+                         "address tag specified but load type doesn't match");
+    }
+  if (mld.load_type == MULTIBOOT_LOAD_TYPE_TOTAL)
+    mld.load_type = addr_tag ? MULTIBOOT_LOAD_TYPE_ADDRESS : MULTIBOOT_LOAD_TYPE_ELF;
+
+  if (mld.load_type == MULTIBOOT_LOAD_TYPE_ADDRESS && !entry_specified &&
+      !(keep_bs && efi_entry_specified))
     {
       grub_free (mld.buffer);
       return grub_error (GRUB_ERR_UNKNOWN_OS,
 			 "load address tag without entry address tag");
     }
 
-  if (addr_tag)
+  switch (mld.load_type) {
+  case MULTIBOOT_LOAD_TYPE_ADDRESS:
     {
       grub_uint64_t load_addr = (addr_tag->load_addr + 1)
 	? addr_tag->load_addr : (addr_tag->header_addr
@@ -343,8 +374,9 @@ grub_multiboot2_load (grub_file_t file, const char *filename)
       if (addr_tag->bss_end_addr)
 	grub_memset ((grub_uint8_t *) source + load_size, 0,
 		     addr_tag->bss_end_addr - load_addr - load_size);
+      break;
     }
-  else
+  case MULTIBOOT_LOAD_TYPE_ELF:
     {
       mld.file = file;
       mld.filename = filename;
@@ -355,7 +387,14 @@ grub_multiboot2_load (grub_file_t file, const char *filename)
 	  grub_free (mld.buffer);
 	  return err;
 	}
+      break;
     }
+  case MULTIBOOT_LOAD_TYPE_PE:
+      grub_fatal ("Unsupported load type: %u\n", mld.load_type);
+  default:
+    /* should be impossible */
+    grub_fatal ("Unknown load type: %u\n", mld.load_type);
+  }
 
   load_base_addr = mld.load_base_addr;
 
include/grub/multiboot2.h +1 -0
index b90aa6989674..1f6d4fc9e336 100644
@@ -89,6 +89,7 @@ struct mbi_load_data
   grub_uint32_t link_base_addr;
   grub_uint32_t load_base_addr;
   int avoid_efi_boot_services;
+  grub_uint32_t load_type;
 };
 typedef struct mbi_load_data mbi_load_data_t;
 
include/multiboot2.h +13 -0
index a039aa0439aa..f4377bf7b394 100644
@@ -74,6 +74,7 @@
 #define MULTIBOOT_HEADER_TAG_EFI_BS  7
 #define MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64  9
 #define MULTIBOOT_HEADER_TAG_RELOCATABLE  10
+#define MULTIBOOT_HEADER_TAG_LOAD_TYPE  11
 
 #define MULTIBOOT2_ARCHITECTURE_I386  0
 #define MULTIBOOT2_ARCHITECTURE_MIPS32  4
@@ -178,6 +179,18 @@ struct multiboot_header_tag_relocatable
   multiboot_uint32_t preference;
 };
 
+struct multiboot_header_tag_load_type
+{
+  multiboot_uint16_t type;
+  multiboot_uint16_t flags;
+  multiboot_uint32_t size;
+#define MULTIBOOT_LOAD_TYPE_ADDRESS     0
+#define MULTIBOOT_LOAD_TYPE_ELF         1
+#define MULTIBOOT_LOAD_TYPE_PE          2
+#define MULTIBOOT_LOAD_TYPE_TOTAL       3
+  multiboot_uint32_t load_type;
+};
+
 struct multiboot_color
 {
   multiboot_uint8_t red;
Signature · 1 line
2.43.0
#18 lore raw

Re: [PATCH 3/7] multiboot2: Add support for the load type header tag

Not a full review. Just one blocking problem

grub-core/loader/multiboot_mbi2.c grub_multiboot2_load (grub_file_t file, const char *filename) · line 396

Quoted 8 lines
     }
grub-core/loader/multiboot_mbi2.c +5 -0
+  case MULTIBOOT_LOAD_TYPE_PE:
+      grub_fatal ("Unsupported load type: %u\n", mld.load_type);
+  default:
+    /* should be impossible */
+    grub_fatal ("Unknown load type: %u\n", mld.load_type);

Don't use grub_fatal for this. grub_fatal is only when continue to execute grub is unwise. Here you just have an unsupported file. This is definitely a GRUB_ERR_BAD_OS

Quoted 1 line
#19 lore raw

Re: [PATCH 3/7] multiboot2: Add support for the load type header tag

Quoted 5 lines · Vladimir 'phcoder' Serbinenko

Not a full review. Just one blocking problem

Quoted 2 lines
Quoted 9 lines

grub-core/loader/multiboot_mbi2.c grub_multiboot2_load (grub_file_t file, const char *filename) · line 396

Quoted 6 lines
     }
grub-core/loader/multiboot_mbi2.c +5 -0
+  case MULTIBOOT_LOAD_TYPE_PE:
+      grub_fatal ("Unsupported load type: %u\n", mld.load_type);
+  default:
+    /* should be impossible */
+    grub_fatal ("Unknown load type: %u\n", mld.load_type);

Don't use grub_fatal for this. grub_fatal is only when continue to execute grub is unwise. Here you just have an unsupported file. This is definitely a GRUB_ERR_BAD_OS

Noted... I'll fix that.

Thanks,
Ross

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#20 lore raw

PATCH 4/7 multiboot2: Add PE load support

In reply to Ross Lagerwall via Grub-devel

Add the ability to load multiboot binaries in PE format. This allows the binaries to be signed and verified.

---
 grub-core/Makefile.core.def       |   1 +
 grub-core/loader/multiboot_mbi2.c |  15 +-
 grub-core/loader/multiboot_pe.c   | 694 ++++++++++++++++++++++++++++++
 include/grub/efi/pe32.h           |  64 +++
 include/grub/multiboot2.h         |   3 +
 5 files changed, 775 insertions(+), 2 deletions(-)
 create mode 100644 grub-core/loader/multiboot_pe.c
grub-core/Makefile.core.def +1 -0
index 1571421d7e84..34697ba58171 100644
@@ -1815,6 +1815,7 @@ module = {
 
   common = loader/multiboot.c;
   common = loader/multiboot_mbi2.c;
+  common = loader/multiboot_pe.c;
   enable = x86;
   enable = i386_xen_pvh;
   enable = mips;
grub-core/loader/multiboot_mbi2.c +13 -2
index 6ef4f265070a..3ec96e2f29b9 100644
@@ -389,8 +389,19 @@ grub_multiboot2_load (grub_file_t file, const char *filename)
 	}
       break;
     }
-  case MULTIBOOT_LOAD_TYPE_PE:
-      grub_fatal ("Unsupported load type: %u\n", mld.load_type);
+ case MULTIBOOT_LOAD_TYPE_PE:
+    {
+      mld.file = file;
+      mld.filename = filename;
+      mld.avoid_efi_boot_services = keep_bs;
+      err = grub_multiboot2_load_pe (&mld);
+      if (err)
+        {
+          grub_free (mld.buffer);
+          return err;
+        }
+      break;
+    }
   default:
     /* should be impossible */
     grub_fatal ("Unknown load type: %u\n", mld.load_type);
grub-core/loader/multiboot_pe.c new file +694 -0

694 lines not on this page · raw message

include/grub/efi/pe32.h +64 -0

86 lines not on this page · raw message

include/grub/multiboot2.h +3 -0
index 1f6d4fc9e336..01e2b11755c2 100644
@@ -97,6 +97,9 @@ typedef struct mbi_load_data mbi_load_data_t;
 grub_err_t
 grub_multiboot2_load_elf (mbi_load_data_t *mld);
 
+grub_err_t
+grub_multiboot2_load_pe (mbi_load_data_t *mld);
+
 extern grub_size_t grub_multiboot2_pure_size;
 extern grub_size_t grub_multiboot2_alloc_mbi;
 extern grub_uint32_t grub_multiboot2_payload_eip;
Signature · 1 line
2.43.0
#21 lore raw

PATCH 5/7 multiboot2: Add support for 64-bit entry addresses

In reply to Ross Lagerwall via Grub-devel

Add support for entry addresses that may be either 32 bits or 64 bits in size. This may be necessary if the binary is built with an entry address above 4G.

---
 grub-core/loader/multiboot_mbi2.c | 10 ++++++++--
 include/multiboot2.h              |  6 +++++-
 2 files changed, 13 insertions(+), 3 deletions(-)
grub-core/loader/multiboot_mbi2.c +8 -2
index 3ec96e2f29b9..c268aa614284 100644
@@ -205,13 +205,19 @@ grub_multiboot2_load (grub_file_t file, const char *filename)
 
       case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS:
 	entry_specified = 1;
-	entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr;
+	if ((tag->size - sizeof(struct multiboot_header_tag)) == sizeof(multiboot_uint64_t))
+	  entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr64;
+	else
+	  entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr32;
 	break;
 
       case MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64:
 #if defined (GRUB_MACHINE_EFI) && defined (__x86_64__)
 	efi_entry_specified = 1;
-	efi_entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr;
+	if ((tag->size - sizeof(struct multiboot_header_tag)) == sizeof(multiboot_uint64_t))
+	  efi_entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr64;
+	else
+	  efi_entry = ((struct multiboot_header_tag_entry_address *) tag)->entry_addr32;
 #endif
 	break;
 
include/multiboot2.h +5 -1
index f4377bf7b394..e4798bfef937 100644
@@ -140,7 +140,11 @@ struct multiboot_header_tag_entry_address
   multiboot_uint16_t type;
   multiboot_uint16_t flags;
   multiboot_uint32_t size;
-  multiboot_uint32_t entry_addr;
+  union
+  {
+    multiboot_uint32_t entry_addr32;
+    multiboot_uint64_t entry_addr64;
+  };
 };
 
 struct multiboot_header_tag_console_flags
Signature · 1 line
2.43.0
#22 lore raw

PATCH 6/7 efi: Allow loading multiboot modules without verification

In reply to Ross Lagerwall via Grub-devel

GRUB doesn't do anything with multiboot modules except loading them and passing a pointer to the multiboot kernel. Therefore GRUB itself doesn't need to verify the module. Multiboot modules may contain code that needs to be verified. If this is the case, the expectation is that the multiboot kernel verifies the modules. For example, with Xen, the first multiboot module contains the dom0 kernel binary and Xen verifies it before starting it.

---
 grub-core/kern/efi/sb.c | 1 +
 1 file changed, 1 insertion(+)
grub-core/kern/efi/sb.c +1 -0
index 8d3e413608bb..f76290d65e9f 100644
@@ -171,6 +171,7 @@ shim_lock_verifier_init (grub_file_t io __attribute__ ((unused)),
     case GRUB_FILE_TYPE_LOADENV:
     case GRUB_FILE_TYPE_SAVEENV:
     case GRUB_FILE_TYPE_VERIFY_SIGNATURE:
+    case GRUB_FILE_TYPE_MULTIBOOT_MODULE:
       *flags = GRUB_VERIFY_FLAGS_SKIP_VERIFICATION;
       return GRUB_ERR_NONE;
 
Signature · 1 line
2.43.0
#23 lore raw

PATCH 7/7 verifiers: Verify after decompression

In reply to Ross Lagerwall via Grub-devel

It is convenient and common to have binaries stored in gzip archives (e.g. xen.gz). Verification should be run after decompression rather than before so reorder the file filter list as appropriate.

---
 include/grub/file.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/grub/file.h +1 -1
index a5bf3a792d6f..a1ef3582bc7b 100644
@@ -182,10 +182,10 @@ 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_VERIFY,
     GRUB_FILE_FILTER_GZIO,
     GRUB_FILE_FILTER_XZIO,
     GRUB_FILE_FILTER_LZOPIO,
+    GRUB_FILE_FILTER_VERIFY,
     GRUB_FILE_FILTER_MAX,
     GRUB_FILE_FILTER_COMPRESSION_FIRST = GRUB_FILE_FILTER_GZIO,
     GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_LZOPIO,
Signature · 1 line
2.43.0
#24 lore raw

Re: [PATCH 7/7] verifiers: Verify after decompression

Quoted 3 lines · Ross Lagerwall via Grub-devel

It is convenient and common to have binaries stored in gzip archives (e.g. xen.gz). Verification should be run after decompression rather than before so reorder the file filter list as appropriate.

The proposed change would result in the disruption of the tpm and pgp clients within the verifier framework. Specifically, the tpm pcr prediction software relies on the integrity of raw files rather than decompressed ones. Additionally, pgp detached signatures are designed to target original files, thus necessitating the current structure to maintain functionality.

Thanks,
Michael

Quoted 30 lines
---
 include/grub/file.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/grub/file.h +1 -1
index a5bf3a792d6f..a1ef3582bc7b 100644
@@ -182,10 +182,10 @@ 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_VERIFY,
     GRUB_FILE_FILTER_GZIO,
     GRUB_FILE_FILTER_XZIO,
     GRUB_FILE_FILTER_LZOPIO,
+    GRUB_FILE_FILTER_VERIFY,
     GRUB_FILE_FILTER_MAX,
     GRUB_FILE_FILTER_COMPRESSION_FIRST = GRUB_FILE_FILTER_GZIO,
     GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_LZOPIO,
Signature · 7 lines
2.43.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#25 lore raw

Re: [PATCH 7/7] verifiers: Verify after decompression

In reply to Ross Lagerwall via Grub-devel

Verifying after decompression is a bad security practice. It relies on decompression having no security holes. Given how complex decompression is, this is almost guaranteed to be false.

Quoted 30 lines · Ross Lagerwall via Grub-devel

It is convenient and common to have binaries stored in gzip archives (e.g. xen.gz). Verification should be run after decompression rather than before so reorder the file filter list as appropriate.

---
 include/grub/file.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/grub/file.h +1 -1
index a5bf3a792d6f..a1ef3582bc7b 100644
@@ -182,10 +182,10 @@ 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_VERIFY,
     GRUB_FILE_FILTER_GZIO,
     GRUB_FILE_FILTER_XZIO,
     GRUB_FILE_FILTER_LZOPIO,
+    GRUB_FILE_FILTER_VERIFY,
     GRUB_FILE_FILTER_MAX,
     GRUB_FILE_FILTER_COMPRESSION_FIRST = GRUB_FILE_FILTER_GZIO,

GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_LZOPIO,
--
2.43.0

Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#26 lore raw

Re: [PATCH 7/7] verifiers: Verify after decompression

Quoted 3 lines · Vladimir 'phcoder' Serbinenko

Verifying after decompression is a bad security practice. It relies on decompression having no security holes. Given how complex decompression is, this is almost guaranteed to be false.

Point taken... I'll drop this patch as it is not essential to the goal of booting Secure Booting Xen via GRUB.

Thanks,
Ross

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel