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

edk2: disable EFI memory attributes protocol again #153

Merged

Conversation

mihalicyn
Copy link
Member

Unfortunately, we have to disable EFI memory attributes protocol that was introduced in
tianocore/edk2@1c4dfad starting from edk2-stable202305 as it leads to crash of SecureBoot shim

There is a fix for shim that addresses this issue, but it will take a few month until this fix will be landed to different Linux distros and we can't make our users wait for it.
Fix for shim:
rhboot/shim@c7b3051

This commit was reverted as a part of ("edk2: disable NX protection feature") but it was a mistake. Somehow, I made a systematic error in my test of edk2 with ("edk2: disable EFI memory attributes protocol") reverted and found that it works. But it's not. And I found why I made this mistake.

Just to be clear EFI_MEMORY_ATTRIBUTES protocol and "ArmVirtPkg: make EFI_LOADER_DATA non-executable" are about setting NX flags on some pages on arm64. And both of commits led to regressions but on the different stages of boot process.

I. "ArmVirtPkg: make EFI_LOADER_DATA non-executable" makes boot process to fail with Synchronous Exception after efi-shim/grub2 finished their work: ================
BdsDxe: loading Boot0001 "UEFI QEMU QEMU HARDDISK " from PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/Scsi(0x0,0x1) BdsDxe: starting Boot0001 "UEFI QEMU QEMU HARDDISK " from PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/Scsi(0x0,0x1) Welcome to GRUB!
Booting `openSUSE Leap 15.5'

Loading Linux 5.14.21-150500.55.19-default ...
Loading initial ramdisk ...

Synchronous Exception at 0x000000006C217504

II. EFI_MEMORY_ATTRIBUTES ("ArmPkg/CpuDxe: Implement EFI memory attributes protocol") makes shim (!) to fail with Synchronous Exception like that: ================
BdsDxe: loading Boot0001 "UEFI QEMU QEMU HARDDISK " from PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/Scsi(0x0,0x1) BdsDxe: starting Boot0001 "UEFI QEMU QEMU HARDDISK " from PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/Scsi(0x0,0x1)

Synchronous Exception at 0x000000007C318000

Synchronous Exception at 0x000000007C318000

Now about how I made this mistake during testing. $ lxc launch ubuntu:jammy jammy-secboot1 --vm -c security.secureboot=true --console Synchronous Exception
$ lxc stop jammy-secboot1 --force
$ ./replace_firmware.sh
$ lxc start jammy-secboot1 --console
Everything works!
$ lxc stop jammy-secboot1 --force
$ ./revert_firmware.sh
$ lxc start jammy-secboot1 --console
Everything is still working!

The catch here is that Synchronous Exception that happens in shim happens only on a clean NVRAM! If VM was boot successfully one time, then it will boot successfuly even after upgrade to a new firmware. (only about EFI_MEMORY_ATTRIBUTE protocol thing!)

Fixes canonical/lxd#12211

Unfortunately, we have to disable EFI memory attributes
protocol that was introduced in
tianocore/edk2@1c4dfad
starting from edk2-stable202305 as it leads to crash of SecureBoot shim

There is a fix for shim that addresses this issue, but it will take a few
month until this fix will be landed to different Linux distros and we can't
make our users wait for it.
Fix for shim:
rhboot/shim@c7b3051

This commit was reverted as a part of ("edk2: disable NX protection feature")
but it was a mistake. Somehow, I made a systematic error in my test of
edk2 with ("edk2: disable EFI memory attributes protocol") reverted and
found that it works. But it's not. And I found *why* I made this mistake.

Just to be clear EFI_MEMORY_ATTRIBUTES protocol and "ArmVirtPkg: make EFI_LOADER_DATA non-executable"
are about setting NX flags on some pages on arm64. And both of commits led
to regressions but on the *different* stages of boot process.

I. "ArmVirtPkg: make EFI_LOADER_DATA non-executable" makes boot process
to fail with Synchronous Exception *after* efi-shim/grub2 finished their work:
================
BdsDxe: loading Boot0001 "UEFI QEMU QEMU HARDDISK " from PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/Scsi(0x0,0x1)
BdsDxe: starting Boot0001 "UEFI QEMU QEMU HARDDISK " from PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/Scsi(0x0,0x1)
Welcome to GRUB!
  Booting `openSUSE Leap 15.5'

Loading Linux 5.14.21-150500.55.19-default ...
Loading initial ramdisk ...

Synchronous Exception at 0x000000006C217504
================

II. EFI_MEMORY_ATTRIBUTES ("ArmPkg/CpuDxe: Implement EFI memory attributes protocol")
makes shim (!) to fail with Synchronous Exception like that:
================
BdsDxe: loading Boot0001 "UEFI QEMU QEMU HARDDISK " from PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/Scsi(0x0,0x1)
BdsDxe: starting Boot0001 "UEFI QEMU QEMU HARDDISK " from PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/Scsi(0x0,0x1)

Synchronous Exception at 0x000000007C318000

Synchronous Exception at 0x000000007C318000
================

Now about *how* I made this mistake during testing.
$ lxc launch ubuntu:jammy jammy-secboot1 --vm -c security.secureboot=true --console
Synchronous Exception
$ lxc stop jammy-secboot1 --force
$ ./replace_firmware.sh
$ lxc start jammy-secboot1 --console
Everything works!
$ lxc stop jammy-secboot1 --force
$ ./revert_firmware.sh
$ lxc start jammy-secboot1 --console
Everything is still working!

The catch here is that Synchronous Exception that happens in shim
happens only on a clean NVRAM! If VM was boot successfully one time,
then it will boot successfuly even after upgrade to a new firmware.
(only about EFI_MEMORY_ATTRIBUTE protocol thing!)

Fixes canonical/lxd#12211

Signed-off-by: Alexander Mikhalitsyn <[email protected]>
@tomponline tomponline merged commit 2539687 into canonical:latest-edge Sep 19, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Booting VMs on Arm64 with standard Ubuntu images leads to Synchronous Exception
2 participants