feat: minimal poc for exporting UEFI variables à la sd-boot #166
Labels
No labels
bug
dependency
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
review-next
security
stub
tool
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: raito/lanzaboote#166
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "sd-stub-efi-variables"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@nikstur be happy now :>
We only need to polyfill some features, @blitz let me know what is the potential for upstreaming to uefi-rs.
internal todolist:
figure out the lifetime for the temporary strings set in export_efi_variables
prepare what should be upstreamed to uefi-rs
figure out error handling
add a test for EFI variables
TPM measurements are out of scope for this PR and variables related to them too.
Random seed support is out of scope for this PR
This implements a substantial part of #94.
You can simplify this a bit with the
guid
macro:Thank you!
This is ready for review @blitz @nikstur.
I added a test which should explain what happens here in the userspace and should ensure we have the expected semantics.
Here's the specification for the EFI variables: https://www.freedesktop.org/software/systemd/man/systemd-stub.html#EFI%20Variables (we can share and we are recommended to share their Vendor ID AFAIK).
Looks good. Added some ideas for improvement. These can also be addressed later. This definetely improves the status quo.
Can we maybe get some lovely Nix-style commit message, e.g. "stub: export boot loader interface efivars"
We don't really need this assignment, do we?
@ -270,0 +302,4 @@
)
SD_LOADER_GUID = "4a67b082-0a4c-41cf-b6c7-440b29bb8c4f"
expected_variables = ["LoaderDevicePartUUID",
A few of these variables might be/will be set by the boot loader. The stub would only set them if the boot loader didn't. So if we wanted to test this fully we would need to get rid of sd-boot and boot the stub directly (e.g. via a custom bootloader).
I think this is supposed to run if the boot loader does not support the random seed. Otherwise the random seed is processed twice (i.e. combined with the systemd token, hashed and then written to into an efivar): first by the boot loader, then by the stub. See https://github.com/systemd/systemd/blob/main/src/boot/efi/stub.c#L208
All of this could go into the
efivars.rs
module since we don't need it for any other purpose, right?Maybe we can find a more neutral name for this struct? These flags are defined by the BootLoaderInterface and in theory this could be implemented by other bootloaders. So maybe we should just call the struct
EfiLoaderFeatures
(this is what systemd does) orLoaderFeatures
.Same as with the loader:
EfiStubFeatures
orStubFeatures
?The changes in this module deserve their own module: maybe
evifars.rs
?Correct
Good point, 0-4AM hacking gets you this kind of stuff :C
Agreed
EfiStubFeatures
sounds good to meCorrect, I did by extreme correctness, I am planning to add those methods natively in the QEMU test driver in the future
(actually I already opened a PR I believe somewhere in nixpkgs)
@ -270,0 +302,4 @@
)
SD_LOADER_GUID = "4a67b082-0a4c-41cf-b6c7-440b29bb8c4f"
expected_variables = ["LoaderDevicePartUUID",
We should definitely do that in those tests
Agreed
Agreed
Do you mean that error while exporting this variable is fatal?
@ -270,0 +302,4 @@
)
SD_LOADER_GUID = "4a67b082-0a4c-41cf-b6c7-440b29bb8c4f"
expected_variables = ["LoaderDevicePartUUID",
Did a trick to do it
No, I mean we don't need the no-op
let _ =
assignment. Either way the result of the function is just ignored.This will generate a warning?
Do you want me to disable
unused_must_use
?Ah because it returns a Result. My bad. You could use
.ok()
and then you dont need to assign the resultingOption
to anything. But I don't have a strong preference in that case.Good point, will do the ok
There's a problem in this PR. I am writing UTF8 strings when bootctl is expecting UTF16 strings I believe.
I will fix this.
This is now fixed, you can see the correct parameters in the VM test on the CI (hopefully).
@nikstur can I have a second approval after my latest changes on string handling?
Looks good but the
part_discovery.rs
module is now superfluous, right?The code form this module is also in
efivars.rs
now. So it can be deleted now, right?Right, forgot it
Fixed
Since this PR I am receiving the following error which I don't really know what to do with:
is this yet another flake
follows
issue?I cannot reproduce it without flakes.
I removed all follows but nix just defaulted to use the pinned version, so apparently you must do a flake update after that.
#147 cannot come soon enough.