grub-efi crashes upon `exit`

Bug #2054127 reported by Mate Kukri
258
This bug affects 1 person
Affects Status Importance Assigned to Milestone
grub2 (Debian)
New
Undecided
Unassigned
grub2-unsigned (Ubuntu)
Fix Released
Medium
Mate Kukri
Mantic
New
Undecided
Unassigned
Noble
Fix Released
Medium
Mate Kukri

Bug Description

[Impact]

Signed grub2 binaries in Ubuntu Mantic are affected by CVE-2024-2312. Please see details below.

[Test Plan]

Make sure Ubuntu Mantic still boots with the new GRUB.

[Where problems could occur]

Not very likely, Ubuntu Mantic fix is a simple git revert of the faulty change.

================================================================================
This was the original issue description, which is kept for reference.

grub> exit
!!!! X64 Exception Type - 06(#UD - Invalid Opcode) CPU Apic ID - 00000000 !!!!
RIP - 000000005AE781A6, CS - 0000000000000038, RFLAGS - 0000000000210202
RAX - 000000005C903E90, RCX - 000000005D93B918, RDX - 000000E8DB694800
RBX - 8000000000000001, RSP - 000000007EEF4AE8, RBP - 000000007EEF04A0
RSI - 000000007EF09440, RDI - 000000007F703B48
R8 - 0000000000000000, R9 - 0000000000000000, R10 - 000000005C8F147C
R11 - 000000005ABB1340, R12 - 0000000000000000, R13 - 000000005ADA7C13
R14 - 000000005C8F15AB, R15 - 000000005C9040A0
DS - 0000000000000030, ES - 0000000000000030, FS - 0000000000000030
GS - 0000000000000030, SS - 0000000000000030
CR0 - 0000000080010033, CR2 - 0000000000000000, CR3 - 000000005EC01000
CR4 - 0000000000000668, CR8 - 0000000000000000
DR0 - 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000
DR3 - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0000000000000400
GDTR - 000000005E9E0000 0000000000000047, LDTR - 0000000000000000
IDTR - 000000005E39F018 0000000000000FFF, TR - 0000000000000000
FXSAVE_STATE - 000000007EEF4740
!!!! Find image based on IP(0x5AE781A6) (No PDB) (ImageBase=0000000054CDB000, EntryPoint=0000000055A70304) !!!!

Exiting grub-efi causes my OVMF virtual machine to crash with the above error.

The #UD likely comes from some global hook not being uninstalled.

Related branches

CVE References

Mate Kukri (mkukri)
Changed in grub2-unsigned (Ubuntu):
assignee: nobody → Mate Kukri (mkukri)
importance: Undecided → Medium
tags: added: foundations-todo
description: updated
Revision history for this message
Mate Kukri (mkukri) wrote :

I am setting this to "Private Security" as I believe this potentially is exploitable to gain unsigned code execution and bypass UEFI Secure Boot.

information type: Public → Private Security
Revision history for this message
Mate Kukri (mkukri) wrote :

Marking Debian as affected to as this issue was introduced there.

Revision history for this message
Mate Kukri (mkukri) wrote :
Revision history for this message
Seth Arnold (seth-arnold) wrote :

In the teardown version, when the original functions are put back, do we run the risk of putting back functions from another module that have also been unloaded?

eg:

load A
load B
unload A
unload B

The Unload B operation may be putting back hooks that were installed by A when it was loaded first.

Unloading modules is often very challenging to get correct. Does grub actually *need* this functionality? It might be better to just pave over the functionality and prevent dangling pointers to functions by just never allowing the functions to be unmapped.

Thanks

Revision history for this message
Mate Kukri (mkukri) wrote (last edit ):

Do you mean by "teardown version" the original one in peimage code? I don't think there is that specific problem because the only signed grub module that hooks these functions is peimage. And if you chainload multiple copies of GRUB itself (by extension the peimage module contained within) they always load-unload in a stack like manner because we only support chainloading applications.

We can and should get rid of unloading modules at least in secure boot mode, but that wouldnt help with this specific bug sadly. the problem here is that when grub itself exits, the module fini functions are *not called*, apparently by design.
But the systab pointers hooked are system global to UEFI, so we have to re-install them if we want to allow exiting grub itself without resetting the system.

I think moving the hook install/removal to before/after EFI image entry and exit is the right approach here, because with that the hooks arent installed by the time anything can interact with the copy of grub that installed the hooks, and child images running via peimage cannot unload their parent without first exiting themselves. (because there are stackframes pointing to the parent grub anyhow)

Revision history for this message
Mate Kukri (mkukri) wrote (last edit ):

Current proposed plan is:

1. Assign CVE ourselves
2. Prepare package updates for noble and sid and set the "CRD" as to whenever we are ready to upload
3. Bump SbatLevel to "grub.peimage,2" in the July update for everyone

+1 Spend some time auditing peimage.c to make sure this is all

Revision history for this message
Seth Arnold (seth-arnold) wrote :

Disabling unloading in secure boot mode sounds like a good idea to me.

Your comment about "allow exiting grub without resetting the system" makes me wonder if we strictly need that feature, too. I can see some sense to "once you're in grub you either have to boot the next operating system or you have to reboot". Anything else would allow whatever functionality is in grub to change UEFI context that might mess with some other operating system, right?

Thanks

Revision history for this message
Mate Kukri (mkukri) wrote :

Currently MAAS relies on exiting GRUB when booting a 3rd party operating system that isn't currently bootable via the Canonical shim. We do plan on fixing this by allowing shim chainloading, but currently exit is required for MAAS.

After that it would be possible to get rid of exit, and from a security engineering perspective it would be nice as it would avoid all the resource deallocation paths, but as a user it would annoy me a little bit, so I am not entirely sure what is the right choice.

Revision history for this message
Mark Esler (eslerm) wrote :

Please refer to this issue as CVE-2024-2312.

Máté will implement Debian fix, so extra coordination is not needed.

Revision history for this message
Mark Esler (eslerm) wrote :

The public Coordinated Release Date for CVE-2024-2312 has been set to March 20th at 2PM UTC.

Mate Kukri (mkukri)
description: updated
Revision history for this message
Mark Esler (eslerm) wrote :

A fix has been released to Noble proposed and the CVE has been published.

https://launchpad.net/ubuntu/+source/grub2/2.12-1ubuntu7

information type: Private Security → Public Security
Changed in grub2-unsigned (Ubuntu):
status: New → Fix Committed
Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "0001-peimage-Move-systab-hook-un-installation-to-be-right.patch" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package grub2-unsigned - 2.12-1ubuntu7

---------------
grub2-unsigned (2.12-1ubuntu7) noble; urgency=medium

  * d/p/grub-sort-version.patch: Also patch grub-mkconfig to export GRUB_FLAVOUR_ORDER
  * d/grub-sort-version: Update regex to correctly match kernel flavour
  * d/grub-sort-version: Append `-0` to abi strings before passing to python-apt (Fixes LP: #2041827)
  * debian/: Add tests for grub-sort-version
  * Revert peimage to re-use GRUB's image handle (LP: #2057679) (LP: #2054127)
  * Increase SBAT level to "grub.ubuntu,2" and "grub.peimage,2"
  * d/build-efi-images: Make sure downstream didn't remove peimage SBAT entry
  * SECURITY UPDATE: Use-after-free in peimage module [LP: #2054127]
    - CVE-2024-2312
  * Source package generated from src:grub2 using make -f ./debian/rules
    generate-grub2-unsigned

 -- Mate Kukri <email address hidden> Thu, 04 Apr 2024 11:12:35 +0100

Changed in grub2-unsigned (Ubuntu Noble):
status: Fix Committed → Fix Released
Revision history for this message
Julian Andres Klode (juliank) wrote :

This bug needs verification for mantic, added tags.

tags: added: verification-needed verification-needed-mantic
removed: foundations-todo
Revision history for this message
Mate Kukri (mkukri) wrote :

Verification OK, mantic remains bootable after upgrading to proposed package.

tags: added: verification-done verification-done-mantic
removed: verification-needed verification-needed-mantic
To post a comment you must log in.
This report contains Public Security information  
Everyone can see this security related information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.