Sign the Image which is zboot's payload
Subsystems (7)
cover Sign the Image which is zboot's payload
From: Pingfan Liu <[email protected]>
I hesitate to post this series, since Ard has recommended using an emulated UEFI boot service to resolve the UKI kexec load problem [1]. since on aarch64, vmlinuz.efi has faced the similar issue at present. But anyway, I have a crude outline of it and am sending it out for discussion.
For security boot, the vmlinuz.efi will be signed so UEFI boot loader can check against it. But at present, there is no signature for kexec file load, this series makes a signature on the zboot's payload -- Image before it is compressed. As a result, the kexec-tools parses and decompresses the Image.gz to get the Image, which has signature and can be checked against during kexec file load
Cc: "Ard Biesheuvel <[email protected]>"
Cc: "Jan Hendrik Farr" <[email protected]>
Cc: "Baoquan He" <[email protected]>
Cc: "Dave Young" <[email protected]>
Cc: "Philipp Rudo" <[email protected]>
Cc: Ard Biesheuvel <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Will Deacon <[email protected]>
To: [email protected]
To: [email protected]
To: [email protected]
Pingfan Liu (2):
zboot: Signing the payload
arm64: Enable signing on the kernel image loaded by kexec file load
arch/arm64/Kconfig | 2 + drivers/firmware/efi/libstub/Makefile.zboot | 23 +++++++-- kernel/Kconfig.kexec_sign | 54 +++++++++++++++++++++ 3 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 kernel/Kconfig.kexec_sign
Signature · 7 lines
2.31.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 1/2 zboot: Signing the payload
From: Pingfan Liu <[email protected]>
Emulate the scheme of module signing to sign the zboot's payload i.e. Image before it is compressed.
And overall, the signature on vmlinuz.efi will be used by UEFI boot loader and the signature on Image will be used by kexec file load.
To: [email protected]
To: [email protected]
To: [email protected]
--- drivers/firmware/efi/libstub/Makefile.zboot | 23 ++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
drivers/firmware/efi/libstub/Makefile.zboot +20 -3
@@ -4,13 +4,30 @@ # EFI_ZBOOT_PAYLOAD, EFI_ZBOOT_BFD_TARGET, EFI_ZBOOT_MACH_TYPE and # EFI_ZBOOT_FORWARD_CFI -quiet_cmd_copy_and_pad = PAD $@ - cmd_copy_and_pad = cp $< $@ && \ + +# +# Signing +# +ifeq ($(CONFIG_KEXEC_ZBOOT_SIG),y) +ifeq ($(filter pkcs11:%, $(CONFIG_KEXEC_ZBOOT_SIG_KEY)),) +sig-key := $(if $(wildcard $(CONFIG_KEXEC_ZBOOT_SIG_KEY)),,$(srctree)/)$(CONFIG_KEXEC_ZBOOT_SIG_KEY) +else +sig-key := $(CONFIG_KEXEC_ZBOOT_SIG_KEY) +endif +cmd_sign = scripts/sign-file $(CONFIG_KEXEC_ZBOOT_SIG_HASH) "$(sig-key)" certs/signing_key.x509 $@ +else + cmd_sign := : +endif + +cmd_copy_and_pad = cp $< $@ && \ truncate -s $(shell hexdump -s16 -n4 -e '"%u"' $<) $@ +quiet_cmd_copy_and_pad_sign = PAD and SIGN $@ + cmd_copy_and_pad_sign = $(cmd_copy_and_pad) && $(cmd_sign) + # Pad the file to the size of the uncompressed image in memory, including BSS $(obj)/vmlinux.bin: $(obj)/$(EFI_ZBOOT_PAYLOAD) FORCE - $(call if_changed,copy_and_pad) + $(call if_changed,copy_and_pad_sign) comp-type-$(CONFIG_KERNEL_GZIP) := gzip comp-type-$(CONFIG_KERNEL_LZ4) := lz4
Signature · 7 lines
2.31.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 2/2 arm64: Enable signing on the kernel image loaded by kexec file load
In reply to Pingfan LiuFrom: Pingfan Liu <[email protected]>
Enable the signing on the kernel image if both KEXEC_SIG and EFI_ZBOOT are configured.
To: [email protected]
To: [email protected]
To: [email protected]
--- arch/arm64/Kconfig | 2 ++ kernel/Kconfig.kexec_sign | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 kernel/Kconfig.kexec_sign
arch/arm64/Kconfig +2 -0
@@ -1493,6 +1493,8 @@ config KEXEC_SIG verification for the corresponding kernel image type being loaded in order for this to work. +source "kernel/Kconfig.kexec_sign" + config KEXEC_IMAGE_VERIFY_SIG bool "Enable Image signature verification support" default y
kernel/Kconfig.kexec_sign new file +54 -0
54 lines not on this page · raw message
Signature · 7 lines
2.31.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Hi Pingfan!
Quoted 9 lines · Pingfan Liu
From: Pingfan Liu <[email protected]>
For security boot, the vmlinuz.efi will be signed so UEFI boot loader can check against it. But at present, there is no signature for kexec file load, this series makes a signature on the zboot's payload -- Image before it is compressed. As a result, the kexec-tools parses and decompresses the Image.gz to get the Image, which has signature and can be checked against during kexec file load
I missed some of the earlier discussion about this zboot kexec support. So just let me know if I'm missing something here. You were exploring these two options in getting this supported:
1. Making kexec_file_load do all the work.
This option makes the signature verification easy. kexec_file_load checks the signature on the pe file and then extracts it and does the kexec.
This is similar to how I'm approaching UKI support in [1].
2. Extract in userspace and pass decompressed kernel to kexec_file_load
This options requires the decompressed kernel to have a valid signature on it. That's why this patch adds the ability to add that signature to the kernel contained inside the zboot image.
This option would not make sense for UKI support as it would not validate the signature with respect to the initrd and cmdline that it contains. Am I correct in thinking that there is no similar issue with zboot images? They don't contain any more information besides the kernel that is intended to be securely signed, right? Do you have a reference for the zboot image layout somewhere?
Quoted 1 line
I hesitate to post this series,
I appreciate you sending it, it's helping the discussion along.
Quoted 5 lines
[...] since Ard has recommended using an
emulated UEFI boot service to resolve the UKI kexec load problem [1]. since on aarch64, vmlinuz.efi has faced the similar issue at present. But anyway, I have a crude outline of it and am sending it out for discussion.
The more I'm thinking about it, the more I like Ard's idea. There's now already two different formats trying to be added to kexec that are pretty different from each other, yet they both have the UEFI interface in common. I think if the kernel supported kexec'ing EFI applications that would be a more flexible and forward-looking approach. It's a standard that both zboot and UKI as well as all future formats for UEFI platforms will support anyways. So while it's more work right now to implement, I think it'll likely pay off.
It is significantly more work than the other options though. So I think before work is started on it, it would be nice to get some type of consensus on these things (not an exhaustive list, please feel free to add to it):
1. Is it the right approach? It adds a significant amount of userspace API.
2. What subset of the UEFI spec needs/should to be supported?
3. Can we let runtime services still be handled by the firmware after exiting boot services?
4. How can we debug the stubs that are being invoked?
5. Can we let the EFI binary know that this is a kexec and not a normal bootup. Potentially systemd-stub would want to change how/if it does TPM PCR measurements.
...
[1] https://lore.kernel.org/kexec/[email protected]/T/
Added some more CCs.
Hi Jan,
Quoted 28 lines · Jan Hendrik Farr
Hi Pingfan!
Quoted 9 lines · Pingfan Liu
From: Pingfan Liu <[email protected]>
For security boot, the vmlinuz.efi will be signed so UEFI boot loader can check against it. But at present, there is no signature for kexec file load, this series makes a signature on the zboot's payload -- Image before it is compressed. As a result, the kexec-tools parses and decompresses the Image.gz to get the Image, which has signature and can be checked against during kexec file load
I missed some of the earlier discussion about this zboot kexec support. So just let me know if I'm missing something here. You were exploring these two options in getting this supported:
1. Making
kexec_file_loaddo all the work.This option makes the signature verification easy.
kexec_file_loadchecks the signature on the pe file and then extracts it and does the kexec.This is similar to how I'm approaching UKI support in [1].
2. Extract in userspace and pass decompressed kernel to
kexec_file_load
Quoted 7 lines
This options requires the decompressed kernel to have a valid signature on it. That's why this patch adds the ability to add that signature to the kernel contained inside the zboot image.
This option would not make sense for UKI support as it would not validate the signature with respect to the initrd and cmdline that it contains.
Another possibility for the cmdline could be using the bootconfig facility which was
introduced for boot time tracking:Documentation/admin-guide/bootconfig.rst
So the initrd+cmdline can be signed as well. Has this been discussed before for UKI?
Thanks
Dave
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 18 lines · Jan Hendrik Farr
Hi Pingfan!
Quoted 9 lines · Pingfan Liu
From: Pingfan Liu <[email protected]>
For security boot, the vmlinuz.efi will be signed so UEFI boot loader can check against it. But at present, there is no signature for kexec file load, this series makes a signature on the zboot's payload -- Image before it is compressed. As a result, the kexec-tools parses and decompresses the Image.gz to get the Image, which has signature and can be checked against during kexec file load
I missed some of the earlier discussion about this zboot kexec support. So just let me know if I'm missing something here. You were exploring these two options in getting this supported:
Quoted 8 lines
1. Making
kexec_file_loaddo all the work.This option makes the signature verification easy.
kexec_file_loadchecks the signature on the pe file and then extracts it and does the kexec.This is similar to how I'm approaching UKI support in [1].
Yes, that is my original try.
Quoted 6 lines
2. Extract in userspace and pass decompressed kernel to
kexec_file_loadThis option requires the decompressed kernel to have a valid signature on it. That's why this patch adds the ability to add that signature to the kernel contained inside the zboot image.
You got it.
Quoted 5 lines
This option would not make sense for UKI support as it would not validate the signature with respect to the initrd and cmdline that it contains. Am I correct in thinking that there is no similar issue with zboot images? They don't contain any more information besides the kernel that is intended to be securely signed, right? Do you have a reference
If using my second method, it means to unpack the UKI image in user space, and pass the kernel image, initrd and cmdline through kexec_file_load interface. If the UKI can have signature on the initrd and cmdline, we extend the capability of that interface to check those verification.
Quoted 2 lines
for the zboot image layout somewhere?
Sorry that maybe there is no document. I understand them through the code. The zboot image, aka, vmlinuz.efi looks like:
PE header, which is formed manually in arch/arm64/kernel/head.S EFI decompressor, which consists of drivers/firmware/efi/libstub/zboot.c and libstub
Image.gz, which is formed by compressing Image as instructed in Makefile.zboot
Quoted 10 lines
Quoted 1 line
I hesitate to post this series,
I appreciate you sending it, it's helping the discussion along.
Quoted 5 lines
[...] since Ard has recommended using an
emulated UEFI boot service to resolve the UKI kexec load problem [1]. since on aarch64, vmlinuz.efi has faced the similar issue at present. But anyway, I have a crude outline of it and am sending it out for discussion.
Quoted 5 lines
The more I'm thinking about it, the more I like Ard's idea. There's now already two different formats trying to be added to kexec that are pretty different from each other, yet they both have the UEFI interface in common. I think if the kernel supported kexec'ing EFI applications that would be a more flexible and forward-looking approach. It's a
Yes, I agree. That method is attractive, originally I had a try when Ard suggested it but there was no clear boundary on which boot service should be implemented for zboot, so I did not move on along that direction.
Now, UKI poses another challenge to kexec_file_load, and seems to require more than zboot. And it appears that Ard's approach is a silver bullet for that issue.
Quoted 9 lines
standard that both zboot and UKI as well as all future formats for UEFI platforms will support anyways. So while it's more work right now to implement, I think it'll likely pay off.
It is significantly more work than the other options though. So I think before work is started on it, it would be nice to get some type of consensus on these things (not an exhaustive list, please feel free to add to it):
I try to answer part of the questions.
Quoted 2 lines
1. Is it the right approach? It adds a significant amount of userspace API.
My crude assumption: this new stub will replace the purgatory, and I am not sure whether kexec-tools source tree will accommodate it. It can be signed and checked during the kexec_file_load.
Quoted 3 lines
2. What subset of the UEFI spec needs/should to be supported?
3. Can we let runtime services still be handled by the firmware after exiting boot services?
I think the runtime services survive through the kexec process. It is derived from the real firmware, not related with this stub
Quoted 6 lines
4. How can we debug the stubs that are being invoked?
5. Can we let the EFI binary know that this is a kexec and not a normal bootup. Potentially systemd-stub would want to change how/if it does TPM PCR measurements.
...
Besides these questions, I wonder whether a highly configured EDK2 can be used as the stub (ArmVirtQemuKernel.dsc can be the start point). But there should be efforts to exclude the drivers which have the MMIO access. I saw Ard is active in EDK2, maybe that is the reason why he did not pick up EDK2 to serve the stub.
Thanks,
Pingfan
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Ard Biesheuvel
maintainerQuoted 3 lines · Pingfan Liu
Quoted 1 line · Jan Hendrik Farr
...
Quoted 39 lines
Quoted 4 lines
I missed some of the earlier discussion about this zboot kexec support. So just let me know if I'm missing something here. You were exploring these two options in getting this supported:
Quoted 8 lines
1. Making
kexec_file_loaddo all the work.This option makes the signature verification easy.
kexec_file_loadchecks the signature on the pe file and then extracts it and does the kexec.This is similar to how I'm approaching UKI support in [1].
Yes, that is my original try.
Quoted 6 lines
2. Extract in userspace and pass decompressed kernel to
kexec_file_loadThis option requires the decompressed kernel to have a valid signature on it. That's why this patch adds the ability to add that signature to the kernel contained inside the zboot image.
You got it.
Quoted 5 lines
This option would not make sense for UKI support as it would not validate the signature with respect to the initrd and cmdline that it contains. Am I correct in thinking that there is no similar issue with zboot images? They don't contain any more information besides the kernel that is intended to be securely signed, right? Do you have a reference
If using my second method, it means to unpack the UKI image in user space, and pass the kernel image, initrd and cmdline through
kexec_file_loadinterface. If the UKI can have signature on the initrd and cmdline, we extend the capability of that interface to check those verification.Quoted 2 lines
for the zboot image layout somewhere?
Quoted 8 lines
Sorry that maybe there is no document. I understand them through the code. The zboot image, aka, vmlinuz.efi looks like:
PE header, which is formed manually inarch/arm64/kernel/head.SEFI decompressor, which consists ofdrivers/firmware/efi/libstub/zboot.cand libstub
Image.gz, which is formed by compressing Image as instructed in Makefile.zboot
Indeed, this is currently only documented in code. zboot is a PE executable that decompresses the kernel and boots it, but it also carries the base and size of the compressed payload in its header, along with the compression type so non-EFI loaders can run it as well (QEMU implements this for gzip on arm64)
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
I hesitate to post this series,
I appreciate you sending it, it's helping the discussion along.
Absolutely. RFCs are important because nobody knows how exactly the code will look until someone takes the time to implement it. So your work on this is much appreciated, even if we may decide to take another approach down the road.
Quoted 12 lines
Quoted 11 lines
Quoted 5 lines
[...] since Ard has recommended using an
emulated UEFI boot service to resolve the UKI kexec load problem [1]. since on aarch64, vmlinuz.efi has faced the similar issue at present. But anyway, I have a crude outline of it and am sending it out for discussion.The more I'm thinking about it, the more I like Ard's idea. There's now already two different formats trying to be added to kexec that are pretty different from each other, yet they both have the UEFI interface in common. I think if the kernel supported kexec'ing EFI applications that would be a more flexible and forward-looking approach. It's a
Quoted 9 lines
Yes, I agree. That method is attractive, originally I had a try when Ard suggested it but there was no clear boundary on which boot service should be implemented for zboot, so I did not move on along that direction.
Now, UKI poses another challenge to
kexec_file_load, and seems to require more than zboot. And it appears that Ard's approach is a silver bullet for that issue.
Yes, it looks appealing but it will take some time to iterate on ideas and converge on an implementation.
Quoted 19 lines
Quoted 9 lines
standard that both zboot and UKI as well as all future formats for UEFI platforms will support anyways. So while it's more work right now to implement, I think it'll likely pay off.
It is significantly more work than the other options though. So I think before work is started on it, it would be nice to get some type of consensus on these things (not an exhaustive list, please feel free to add to it):
I try to answer part of the questions.
Quoted 2 lines
1. Is it the right approach? It adds a significant amount of userspace API.
My crude assumption: this new stub will replace the purgatory, and I am not sure whether kexec-tools source tree will accommodate it. It can be signed and checked during the
kexec_file_load.
Quoted 7 lines
Quoted 3 lines
2. What subset of the UEFI spec needs/should to be supported?
3. Can we let runtime services still be handled by the firmware after exiting boot services?I think the runtime services survive through the kexec process. It is derived from the real firmware, not related with this stub
Yes, this should be possible.
Quoted 7 lines
Quoted 6 lines
4. How can we debug the stubs that are being invoked?
5. Can we let the EFI binary know that this is a kexec and not a normal bootup. Potentially systemd-stub would want to change how/if it does TPM PCR measurements.
...
Not sure whether this matters. The TPM logic is exposed via EFI protocols, and the kernel could either expose them or not. If it does, and we execute the EFI stub (sytemd-stub) code all the way through to ExitBootServices() while executing in the old kernel, we could even take PCR measurements and display them, giving us secure and measured boot for kexec.
Quoted 6 lines
Besides these questions, I wonder whether a highly configured EDK2 can be used as the stub (ArmVirtQemuKernel.dsc can be the start point). But there should be efforts to exclude the drivers which have the MMIO access. I saw Ard is active in EDK2, maybe that is the reason why he did not pick up EDK2 to serve the stub.
I don't think EDK2 is suitable for this - the code style is different, the license is different and it is simply a lot of code.
What I would prefer is to define a subset of the EFI boot services that we actually rely on, and perhaps even introduce some other constraints on the EFI code, e.g., allow it to run unprivileged.
That way, kexec could execute the EFI stub as an ordinary user process (to some extent), including allocations for the decompressed kernel, initrd, etc. Finally, the only thing purgatory would need to do is linearize the populated regions in the VA space and copy them to physical memory.
This all sounds very high-level, and there may be some difficulties down the road, but I think this deserves a proper look because it is an appealing way to make EFI execution idempotent in the context of kexec, and also reduces the arch-specific logic substantially.
Hi Dave,
Quoted 39 lines · On Fri, 22 Sep 2023 13:41:22 +0800 Dave Young <[email protected]> wrote:
Hi Jan,
Quoted 28 lines · Jan Hendrik Farr
Hi Pingfan!
Quoted 9 lines · Pingfan Liu
From: Pingfan Liu <[email protected]>
For security boot, the vmlinuz.efi will be signed so UEFI boot loader can check against it. But at present, there is no signature for kexec file load, this series makes a signature on the zboot's payload -- Image before it is compressed. As a result, the kexec-tools parses and decompresses the Image.gz to get the Image, which has signature and can be checked against during kexec file load
I missed some of the earlier discussion about this zboot kexec support. So just let me know if I'm missing something here. You were exploring these two options in getting this supported:
1. Making
kexec_file_loaddo all the work.This option makes the signature verification easy.
kexec_file_loadchecks the signature on the pe file and then extracts it and does the kexec.This is similar to how I'm approaching UKI support in [1].
2. Extract in userspace and pass decompressed kernel to
kexec_file_loadQuoted 7 lines
This options requires the decompressed kernel to have a valid signature on it. That's why this patch adds the ability to add that signature to the kernel contained inside the zboot image.
This option would not make sense for UKI support as it would not validate the signature with respect to the initrd and cmdline that it contains.
Quoted 7 lines
Another possibility for the cmdline could be using the bootconfig facility which was
introduced for boot time tracking:Documentation/admin-guide/bootconfig.rstSo the initrd+cmdline can be signed as well. Has this been discussed before for UKI?
Not that I know of. But I'm not sure if the bootconfig the way it works today does the trick.
For one the bootconfig is simply glued to the end of the initrd. But that makes it part of the UKI as well. So there is no added gain.
Plus, adding the cmdline to the UKI was done on purpose to prevent any unauthorized editing. That basically means that any change to the cmdline needs to be signed as well. But I don't see any signature verification while processing the bootconfig.
Finally the bootconfig is setup too late in the boot process, in particular after setup_arch which reserves the crashkernel memory and needs to parse the kernel command line for that. An even more extreme example is the decompressor phase on s390. There the command line is parsed as well. And that is code that runs before start_kernel.
All in all I don't believe that using the bootconfig adds much benefit for the UKI.
Thanks
Philipp
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 12 lines · Ard Biesheuvel
On Mon, 25 Sept 2023 at 03:01, Pingfan Liu <[email protected]> wrote:
[...]
Quoted 7 lines
Quoted 6 lines
4. How can we debug the stubs that are being invoked?
5. Can we let the EFI binary know that this is a kexec and not a normal bootup. Potentially systemd-stub would want to change how/if it does TPM PCR measurements.
...
Quoted 7 lines
Not sure whether this matters. The TPM logic is exposed via EFI protocols, and the kernel could either expose them or not. If it does, and we execute the EFI stub (sytemd-stub) code all the way through to
ExitBootServices()while executing in the old kernel, we could even take PCR measurements and display them, giving us secure and measured boot for kexec.
I think we should definitely delay any of the measurements until ExitBootServices(). We don't wan't measurements of a kernel that is not running and might even get unloaded before being kexec'ed to make their way into the TPM.
Quoted 20 lines
Quoted 6 lines
Besides these questions, I wonder whether a highly configured EDK2 can be used as the stub (ArmVirtQemuKernel.dsc can be the start point). But there should be efforts to exclude the drivers which have the MMIO access. I saw Ard is active in EDK2, maybe that is the reason why he did not pick up EDK2 to serve the stub.
I don't think EDK2 is suitable for this - the code style is different, the license is different and it is simply a lot of code.
What I would prefer is to define a subset of the EFI boot services that we actually rely on, and perhaps even introduce some other constraints on the EFI code, e.g., allow it to run unprivileged.
That way, kexec could execute the EFI stub as an ordinary user process (to some extent), including allocations for the decompressed kernel, initrd, etc. Finally, the only thing purgatory would need to do is linearize the populated regions in the VA space and copy them to physical memory.
Quoted 4 lines
This all sounds very high-level, and there may be some difficulties down the road, but I think this deserves a proper look because it is an appealing way to make EFI execution idempotent in the context of kexec, and also reduces the arch-specific logic substantially.
I just started work on a proof-of-concept implementation of this [1]. It's kinda unorganized and early right now though. Currently just testing with executing a bzimage with the normal EFI stub on x86. At this point it starts executing the EFI stub which checks efi_system_table->hdr.signature for the correct signature (which I have not set yet). That causes the EFI stub to exit. It does correctly call the exit function from my provided boot services table and the correct ExitStatus gets logged in dmesg. So it's able to call into my boot services correctly.
This is definitly the most low level code I've ever written though, so I'm just learning this stuff.
Next I'll work on setting up a proper memory mapping for the EFI application.
After that I'll work on implementing the needed boot services and protocols.
[1] https://github.com/Cydox/linux/commits/kexec-uefi
--
Jan