Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create_disk: fix UEFI secure boot #1105

Merged
merged 1 commit into from
Feb 6, 2020
Merged

create_disk: fix UEFI secure boot #1105

merged 1 commit into from
Feb 6, 2020

Conversation

darkmuggle
Copy link
Contributor

@darkmuggle darkmuggle commented Feb 6, 2020

Ensure that all the efi binaries are included from the target.
Fixes #1090

We have a couple problems with our UEFI Secure Boot story:

  1. The full UEFI/EFI binaries were not copied over. In order to do a
    compliant EFI boot, BOOT.EFI should be there.
  2. /usr/lib/ostree-boot/efi/BOOT/BOOT.EFI is a symlink
    to /usr/lib/ostree-boot/efi//shim.efi.
    This requires that a copy be made.
  3. /boot/efi/EFI//grub2.cfg was not complete. It needed to
    load the /boot/grub2/grub2.cfg file and then boot.
  4. Without mmx64.efi, Secure Boot will not work since key-regristration does not happen.

@darkmuggle darkmuggle added bug Something isn't working WIP PR still being worked on hold waiting on something labels Feb 6, 2020
@darkmuggle
Copy link
Contributor Author

Tested with:

  • No UEFI
  • UEFI Secure Boot (aka shim boot)
  • UEFI unsigned

Calling this a draft because I'm not sure how it will play with the $OTHER_ARCHES

Confirmed that this works with UEFI in KVM:

[root@localhost ben]# dmesg | grep efi
[    0.000000] efi: EFI v2.70 by EDK II
[    0.000000] efi:  SMBIOS=0x7ebd2000  ACPI=0x7ebf9000  ACPI 2.0=0x7ebf9014  MEMATTR=0x7dcdb018  TPMEventLog=0x7d022018
[    0.000000] clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1910969940391419 ns
[    0.097083] pci 0000:00:01.0: BAR 0: assigned to efifb
[    0.146021] Registered efivars operations
[    1.070086] efifb: probing for efifb
[    1.070489] efifb: framebuffer at 0xc0000000, using 1876k, total 1875k
[    1.071153] efifb: mode is 800x600x32, linelength=3200, pages=1
[    1.071757] efifb: scrolling: redraw
[    1.072128] efifb: Truecolor: size=8:8:8:8, shift=24:16:8:0

@cgwalters
Copy link
Member

OK as far as I can tell, this bug started when someone just did an ls -al /boot/efi and noticed shim wasn't there. In other words, we're not doing exactly what Anaconda does. Sure - that's something to investigate.

When I discussed with Andrew he said something about shim being unnecessary, and I didn't pursue it further at the time.

However, I did notice that secure boot was broken in qemu, and the previous PR fixed it. We also now have test coverage for all of that via cosa kola --basic-qemu-scenarios.

I didn't test on bare metal.

So my question is: Concretely what exactly is this fixing? For example, does it fix booting on bare metal (are our qemu tests broken?). What does "compliant EFI boot" mean?

AIUI, what shim is doing is ensuring that a system that only has the Microsoft keys enrolled (common for real hardware) can boot kernels signed with the Fedora/RH keys. So I could completely imagine that for example our --uefi-secure tests just happen to work because the Fedora key is already in the firmware we're using for qemu.

That would be a real bug.

But I'd like to have it spelled out exactly what user-visible scenario we're fixing.

cgwalters added a commit to cgwalters/coreos-assembler that referenced this pull request Feb 6, 2020
Same rationale as coreos/fedora-coreos-pipeline#187
Motivated by ensuring we're covering proposed changes like
coreos#1105
in CI here too.
cgwalters added a commit to cgwalters/coreos-assembler that referenced this pull request Feb 6, 2020
Same rationale as coreos/fedora-coreos-pipeline#187
Motivated by ensuring we're covering proposed changes like
coreos#1105
in CI here too.
cgwalters added a commit to cgwalters/coreos-assembler that referenced this pull request Feb 6, 2020
Same rationale as coreos/fedora-coreos-pipeline#187
Motivated by ensuring we're covering proposed changes like
coreos#1105
in CI here too.
@darkmuggle
Copy link
Contributor Author

We are missing a couple of notable files:

  • mmx64.efi: used to enroll the Shim's Keys
  • fbx64.efi: needed if you move the disk
  • BOOTX64.CSV: needed in case the keys are removed
  • shimx64.efi: needed for Secure boot

I reached out to the Red Hat's UEFI SME and the answer is that we got really lucky that the current way works. Further, since there is no efi/EFI/BOOT/grub.cfg we were using automatic fallback that might not work depending on the hardware.

The bug here is that our UEFI story is broken on some hardware but not all. If the hardware requires key enrollment then our UEFI images will not boot.

What we ship:

[root@ibm-p8-kvm-03-guest-02 boot]# find efi -type f -exec md5sum {} \; | sort
805369650ed821476003893402c7c8df  efi/EFI/redhat/grub.cfg
a1a08d1393070ef05a912cd08f132a70  efi/EFI/BOOT/grubx64.efi
c748cde9827385f9832a4f0ab1f02550  efi/EFI/BOOT/BOOTX64.EFI

After my patch:

05cc95b356fb10e84dcdccb09aa0f032  efi/EFI/redhat/shimx64-redhat.efi
3a0b681a2558863e117d71f3e5c504fc  efi/EFI/redhat/grub.cfg
5a1d0059397afc447de3561d7d508ff3  efi/EFI/redhat/mmx64.efi
a1a08d1393070ef05a912cd08f132a70  efi/EFI/redhat/grubx64.efi
b90ffff182e4b99380e6e4d2a9e33753  efi/EFI/redhat/BOOTX64.CSV
c748cde9827385f9832a4f0ab1f02550  efi/EFI/BOOT/BOOTX64.EFI
c748cde9827385f9832a4f0ab1f02550  efi/EFI/redhat/shimx64.efi
f8b0bf703a67a957d946f7278e01dc08  efi/EFI/BOOT/fbx64.efi

@darkmuggle darkmuggle removed WIP PR still being worked on hold waiting on something labels Feb 6, 2020
@darkmuggle darkmuggle marked this pull request as ready for review February 6, 2020 18:31
@darkmuggle darkmuggle added WIP PR still being worked on and removed WIP PR still being worked on labels Feb 6, 2020
@darkmuggle
Copy link
Contributor Author

Okay, this is ready for review.

@darkmuggle
Copy link
Contributor Author

So my question is: Concretely what exactly is this fixing? For example, does it fix booting on bare metal (are our qemu tests broken?). What does "compliant EFI boot" mean?

Our current EFI boot layout has the removable media layout, but not support key-registration via the mmx64.efi. When I tested on bare-metal, the 4.4 images would not boot. Depending on what UEFI spec the hardware requires, then missing mmx64.efi would result in a failed boot.

AIUI, what shim is doing is ensuring that a system that only has the Microsoft keys enrolled (common for real hardware) can boot kernels signed with the Fedora/RH keys. So I could completely imagine that for example our --uefi-secure tests just happen to work because the Fedora key is already in the firmware we're using for qemu.

shimx64.efi is only part of the boot story. BOOTX64.EFI the same as shimx64.efi. After reaching out our UEFI SME, I was advised that we need boot. BOOTX64.EFI is used in the removal case, while shimx64.efi is used for fixed disks. Further, we have been advised to use the fixed disk layout.

On first boot with the full layout, the firmware registers the signing keys and then reloads and boots normally.

Copy link
Member

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve
Thanks, that sounds reasonable. Did you test this on real hardware (with SB enabled ideally?) Do we have any idea of what hardware would be affected by this that we could use to verify - or a way to do so by e.g. changing the qemu firmware setup?

I'm OK merging without, it may be easier to test afterwards.

Though hopefully you verified at least the existing cosa kola --qemu-basic-scenarios works? (One gap we still have is that we should probably change that to pass Ignitition to verify UEFI/lockdown etc.)

local vendordir="${target_efi}/EFI/${vendor_id}"

# Some of the files in EFI/BOOT are _symlinks_ to EFI/$VENDOR
# in the OS tree. We need to make copies here.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it's just grubenv that's a symlink; may be easier to special case that?

Also worth commenting here probably are
coreos/rpm-ostree#969
and
ostreedev/ostree#1873

which may be related to some of this being awkward.

In fact we should probably change coreos-assembler (and/or rpm-ostree) to download the grub/efi bits separately and not commit them to the ostree as discussed. But, definitely that can come later.

cd "${source_efidir}"/EFI/${t}
for i in *; do
/usr/lib/coreos-assembler/cp-reflink -vRL \
$(readlink -f $i) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having both -L and explicit readlink seems odd?

@darkmuggle
Copy link
Contributor Author

Confirmed that this produces images for both RHCOS and FCOS boot in a secure boot situation and that keys are registered.

Ensure that all the efi binaries are included from the target.
Fixes #1090
Fixes BZ 1799891

Our UEFI boot today is a bit lucky. This fixes a couple problems:
1. The full UEFI/EFI binaries were not copied over. In order to do a
   compliant EFI boot, BOOT<ARCH>.EFI should be there.
2. /usr/lib/ostree-boot/efi/BOOT/BOOT<ARCH>.EFI is a symlink
   to /usr/lib/ostree-boot/efi/<VENDOR>/shim<ARCH>.efi.
   This requires that a copy be made.
3. /boot/efi/EFI/<VENDOR>/grub2.cfg was not complete. It needed to
   load the /boot/grub2/grub2.cfg file and then boot. Previous images
   were booting using fallback.
4. Missing mmx64.efi means that secure UEFI could not happen since the
   the keys are no registered. mmx64.efi is needed to ensure GPL
   compliance on the shim. Without this file, the shim has is not
   recorded in the nvram.
@miabbott
Copy link
Member

miabbott commented Feb 6, 2020

/approve

IMO, it makes sense for RHCOS to operate as closely as RHEL for this feature, so I believe this is the right thing to do.

@darkmuggle
Copy link
Contributor Author

@ashcrow given that we're late in the game for 4.4 can you git this a sanity check and approval (if so inclined)?

@cgwalters
Copy link
Member

/lgtm

@cgwalters
Copy link
Member

We can address some of the review comments above as followup; merging in favor of shipping a tested patch.

@openshift-merge-robot openshift-merge-robot merged commit 1159022 into coreos:master Feb 6, 2020
Copy link
Member

@ashcrow ashcrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sane to me.

@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ashcrow, cgwalters, darkmuggle, miabbott

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [ashcrow,cgwalters,darkmuggle,miabbott]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

openshift-merge-robot pushed a commit that referenced this pull request Feb 6, 2020
Same rationale as coreos/fedora-coreos-pipeline#187
Motivated by ensuring we're covering proposed changes like
#1105
in CI here too.
arithx pushed a commit to arithx/coreos-assembler that referenced this pull request Feb 7, 2020
```
Benjamin Gilbert (3):
      cmd/ore/aws: let list-regions list disabled regions, or all regions
      Merge pull request coreos#1102 from bgilbert/regions
      Merge pull request coreos#1104 from jcajka/bcrypt

Jakub Čajka (1):
      kola/tests/rpmostree: use NVR instead of NVRA

Jonathan Lebon (5):
      auth/aliyun: fix parsing config file
      Merge pull request coreos#1105 from jlebon/pr/aliyun-profile-fix
      ore/aliyun: add --delete-object and default to true
      platform/api/aliyun: sprinkle with some logging
      Merge pull request coreos#1107 from jlebon/pr/aliyun-delete-object
```
@darkmuggle darkmuggle deleted the pr/shims-1090 branch February 18, 2020 21:48
jcajka pushed a commit to jcajka/coreos-assembler that referenced this pull request Mar 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved bug Something isn't working lgtm size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

provide way to use non-Fedora EFI shim when building a CoreOS system
6 participants