Mattiwatti / EfiGuard

Disable PatchGuard and Driver Signature Enforcement at boot time
GNU General Public License v3.0
1.71k stars 329 forks source link

UEFI question #32

Closed BlackBunnyHunter closed 1 year ago

BlackBunnyHunter commented 3 years ago

Why does the EFI image have a PE header? Is the windows kernel responsible for loading the efi image?

I ask because I tought the EFI image is loaded before the kernel.

BlackBunnyHunter commented 3 years ago

Another question I have is why can't it be used with HVCI, the documentation says that HVCI runs at a greater privilege level. How is that possible? Isn't EFI the first thing that runs after the motherboard firmware has done its setup.

Mattiwatti commented 3 years ago

Why does the EFI image have a PE header? Is the windows kernel responsible for loading the efi image?

What is "the" EFI image you are wondering about in particular?

In general however the answer to this question is pretty straightforward: the PE format is mandated by the UEFI specification. (Some PEI/PEIM images may also use the smaller TE ("Terse Executable") format, which is different in some details but mostly similar.)

I ask because I tought the EFI image is loaded before the kernel.

That is correct. You can see the load flow and order in the graph in the README.

Another question I have is why can't it be used with HVCI, the documentation says that HVCI runs at a greater privilege level. How is that possible? Isn't EFI the first thing that runs after the motherboard firmware has done its setup.

This is an interesting question. First a minor technical correction: EfiGuard can be used with HVCI (you can try it if you want), it just won't do anything useful. So the question you probably meant to ask is: why doesn't EfiGuard work when HVCI is enabled?

It's true that, as a hypervisor, HVCI's privilege level trumps that of EfiGuard (barring some as-yet unknown disastrous vulnerability in Hyper-V), but (as you correctly point out) EfiGuard does run before HVCI is initialized. So which one 'wins'? That depends on how you look at it. First a note: I'm going to gloss over some differences in the boot process when HVCI is enabled which are actually pretty significant, but not super relevant here. So this is not exactly how it really works, but should give an idea.

Winload.efi starts the hypervisor is HVCI is enabled (or if automatic hypervisor startup is requested for any reason at all). At this point, EfiGuard could intercept winload, right? Well yes, that's true. You have to consider however what exactly EfiGuard could do at this point.

I am aware of some alternative possibilities that might allow EfiGuard to disable or bypass HVCI, but I am not willing to discuss these at the moment, because (A) they are probably vulnerabilities, and as such would be patched if I disclosed them, and (B) were not discovered by me, and as such are not for me to disclose.

DavidXanatos commented 3 years ago

What about patching hvix64.exe/hvax64.exe such that it leaks the address of the loaded securekernel.exe and allows the boot-kit to do modifications? I mean in the end if we have first execution there must be a way to win this.

Mattiwatti commented 1 year ago

This is now fixed as somewhat of a side effect of 2f4a666, which makes it so that VBS (this includes HVCI) will be disabled during boot if the EfiGuard DXE driver was loaded.

DavidXanatos commented 1 year ago

nice thank you