Skip to content

Enable MS-compatible secure boot with OVMF#284874

Merged
adamcstephens merged 6 commits intoNixOS:masterfrom
shlevy:ovmf-ms
Feb 26, 2024
Merged

Enable MS-compatible secure boot with OVMF#284874
adamcstephens merged 6 commits intoNixOS:masterfrom
shlevy:ovmf-ms

Conversation

@shlevy
Copy link
Member

@shlevy shlevy commented Jan 30, 2024

Description of changes

These changes, especially the new msVarsTemplate flag for OVMF to create a UEFI variables store with MS secure boot keys enrolled, allow for virtualization of Windows 11 without bypassing secure boot restrictions.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@shlevy
Copy link
Member Author

shlevy commented Jan 30, 2024

Note that I am still doing final comprehensive tests, but I have done initial validation of the resulting images.

@ofborg ofborg bot added the 8.has: package (new) This PR adds a new package label Jan 30, 2024
@ofborg ofborg bot requested review from alyssais and edolstra January 30, 2024 00:47
@ofborg ofborg bot added 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels Jan 30, 2024
@adamcstephens
Copy link
Contributor

adamcstephens commented Jan 30, 2024

I would rather this be included by default with OVMFFull and not a standalone package. I see OVMFFull as batteries included and should definitely have secure boot support. What do you think @RaitoBezarius ?

@alyssais
Copy link
Member

The QEMU update looks good, but why is it part of this PR?

@shlevy
Copy link
Member Author

shlevy commented Jan 30, 2024

@alyssais The OVMFMSVars derivation uses qemu to populate the nvram image, and it hangs on 8.2.0 (but not prior versions of qemu nor on 8.2.1).

@shlevy
Copy link
Member Author

shlevy commented Jan 30, 2024

@adamcstephens I can move that if that's what the maintainers want. To be clear, OVMFFull does fully support secure boot, it just doesn't have the MS keys so you have to do your own key management.

@alyssais
Copy link
Member

@alyssais The OVMFMSVars derivation uses qemu to populate the nvram image, and it hangs on 8.2.0 (but not prior versions of qemu nor on 8.2.1).

Would make more sense in a separate PR IMO. There's no point holding up a simple QEMU update for the other stuff here.

@adamcstephens
Copy link
Contributor

Looks like #284925 is the qemu side. If that's going to move forward this time, we may want to base this PR off of it since both add the OVMF build flag. I do prefer systemManagementModeSupport as it better matches the naming of the other arguments.

Either way, yes I think this should be handled in the OVMF package directly. It can include ms.nix if that's easier, but I would prefer to not expose another top-level package.

@shlevy
Copy link
Member Author

shlevy commented Jan 30, 2024

@alyssais Rebased on #285002

@shlevy
Copy link
Member Author

shlevy commented Jan 30, 2024

@adamcstephens That other PR doesn't bump qemu versions and is mostly about NixOS support. I also think the logic of requiring SMM when secureBoot is being used is more appropriate.

@alyssais
Copy link
Member

Thanks a lot.

@shlevy shlevy requested a review from infinisil as a code owner January 30, 2024 14:57
@github-actions github-actions bot added the 6.topic: lib The Nixpkgs function library label Jan 30, 2024
@shlevy
Copy link
Member Author

shlevy commented Jan 30, 2024

@adamcstephens OK, inlined into the main derivation.

@shlevy
Copy link
Member Author

shlevy commented Jan 30, 2024

@adamcstephens Updated flag name for SMM.

@shlevy
Copy link
Member Author

shlevy commented Jan 30, 2024

Testing confirmed: Default vars file does not have secure boot enabled, new vars file does and requires MS-signed boot.

@baloo
Copy link
Member

baloo commented Jan 30, 2024

There is still an issue with SMM when secureboot is enabled.
For some reason enabling SMM still makes it impossible to update EFI variables. The qemu 8.2.1 bump doesn't fix that.

I don't know if we should build OVMF with a builtin set of keys. I'd much rather go with an approach like: baloo@0174b95

Get the test driver (or whatever wrapper) to write the efivars storage directly, and embed a set of keys from the user if needed.

@shlevy
Copy link
Member Author

shlevy commented Jan 30, 2024

@baloo It can't be right that it's impossible to update EFI vars, since the script that generates the variables template works by launching a qemu VM and running a firmware program to update them, and my Windows VM is able to update the boot order. Where are you seeing this issue?

I don't know if we should build OVMF with a builtin set of keys.

With this change, you still get the empty variable store if you want it. You have to opt in to the default keys by using OVMF_VARS.ms.fd. Note that approximately every real world x86 secure boot implementation has these keys and most of the secure boot signing infrastructure revolves around them in some shape or form.

@baloo
Copy link
Member

baloo commented Jan 30, 2024

@baloo It can't be right that it's impossible to update EFI vars, since the script that generates the variables template works by launching a qemu VM and running a firmware program to update them, and my Windows VM is able to update the boot order. Where are you seeing this issue?

The moment secureboot is turned on, the SMM handler for qemu seems to make it impossible to update variables.
That occurs with lanzaboote test suite (when pulling changes from #284925) :

nix build 'github:baloo/lanzaboote/baloo/qemu-smm#checks.x86_64-linux.basic' -j 12 -L

@shlevy
Copy link
Member Author

shlevy commented Jan 30, 2024

@baloo You need to pass -global driver=cfi.pflash01,property=secure,value=on to qemu.

@shlevy
Copy link
Member Author

shlevy commented Feb 15, 2024

You probably should rebase on master and test this again.

Fixed

@ofborg ofborg bot requested a review from adamcstephens February 15, 2024 18:48
@AshleyYakeley
Copy link

@AshleyYakeley are you able or have you tested this to ensure it meets your needs?

Yes, this works for me. I used "${packages.OVMFFull.fd}/FV/OVMF_CODE.ms.fd" and "${packages.OVMFFull.fd}/FV/OVMF_VARS.ms.fd" from shlevy's branch, and I could get past the hardware check of the Windows 11 installer.

@AshleyYakeley
Copy link

This PR would close #288184.

@ofborg ofborg bot removed the 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. label Feb 16, 2024
@AshleyYakeley
Copy link

Is this ready to merge?

@shlevy
Copy link
Member Author

shlevy commented Feb 23, 2024

I have no known issues on my end.

@AshleyYakeley
Copy link

Well, if no-one has any objections...

@shlevy
Copy link
Member Author

shlevy commented Feb 25, 2024

@adamcstephens still wants to test #284874 (comment)

@adamcstephens
Copy link
Contributor

Thanks for your contribution. Sorry for the delay.

Since there are no objections, I'm going to merge it.

@adamcstephens adamcstephens merged commit af810fc into NixOS:master Feb 26, 2024
@AshleyYakeley
Copy link

Thanks!

@K900 K900 mentioned this pull request Feb 26, 2024
13 tasks
@vcunat
Copy link
Member

vcunat commented Feb 26, 2024

FYI the merge blocked channels. See PR #291544

K900 pushed a commit that referenced this pull request Feb 26, 2024
I accidentally removed this in f6fc51d (I missed the leading comma on
line 160), which was merged as part of #284874

This should be removed eventually, but it should be done intentionally
with proper release notes.
pull bot pushed a commit to b-/nixpkgs that referenced this pull request Feb 28, 2024
I accidentally removed this in f6fc51d (I missed the leading comma on
line 160), which was merged as part of NixOS#284874

This should be removed eventually, but it should be done intentionally
with proper release notes.
@nikstur
Copy link
Contributor

nikstur commented Mar 1, 2024

This breaks a lot of things. Most notably it makes secure boot with aarch64 impossible because of weird defaults, an assertion and a qemu machine type that is x86 only. I'm biased to revert it.

@shlevy
Copy link
Member Author

shlevy commented Mar 1, 2024

@nikstur Can you explain the issue/show a repro? The only x86-only code here is the usage of q35 when system management mode is enabled, but SMM is an x86 feature…

@shlevy
Copy link
Member Author

shlevy commented Mar 1, 2024

@adamcstephens
Copy link
Contributor

This breaks a lot of things.

If this is that critical, I'm happy to revert, but it would be helpful to know what and why. It's possible we can just fix and move forward instead of rolling back completely.

@JulienMalka
Copy link
Member

Maintainer of systemd-boot here. I'm surprised to find out that this PR adds a new test the the systemd-boot tests, but I was never pinged for review, and this test doesn't specify maintainers. I am not planing to maintain tests that are getting merged without my approval, so I will revert at least this part of the PR.

@hypersw
Copy link
Contributor

hypersw commented Mar 25, 2024

libvirtd.nix adds nvram options for the default .fd files (I suppose this makes them selectable in virt-manager), and with its libvirtd-config service symlinks them into a fixed path under /var/lib/libvirt so that they could be referenced by that path from xmls and remain valid between system upgrades.

Nothing is offered for these .ms. secure-boot files, even if you set your QEMU's OVMF to use OVMFFull.fd as the package.

Should we add some way, controlled from editing the virtualisation.libvirtd.qemu configuration, to ship the secure boot versions in a way usable from virt-manager nicely?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.