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

Don't unhook ExitBootServices when EBS protection is disabled #378

Merged
merged 1 commit into from
Jul 20, 2021

Conversation

sforshee
Copy link

@sforshee sforshee commented Jun 5, 2021

When EBS protection is disabled unhook_system_services() still
"restores" EBS in the boot services table. However, EBS was not
replaced and the original value not saved, so NULL is written. Then
when the OS tries to call EBS it ends up jumping to NULL.

Fix this by also compiling out the code to unhook EBS when
DISABLE_EBS_PROTECTION is defined.

Fixes: 4b0a61d ("shim: compile time option to bypass the ExitBootServices() check")
Signed-off-by: Seth Forshee [email protected]

Copy link
Collaborator

@julian-klode julian-klode left a comment

Choose a reason for hiding this comment

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

LGTM. Love how it adds a safety check by ifdefing the variable.

Copy link
Contributor

@xnox xnox left a comment

Choose a reason for hiding this comment

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

Is there one more place similar to this that is not taken care of in hook_exit() and unhook_exit()?

It looks like hook_exit replaces system_exit, but unhook_exit never restores the original one when DISABLE_EBS_PROTENCTION is on. It feels like unhook_exit should be unhooking things even with DISABLE_EBS_PROTECTION on.

@sforshee
Copy link
Author

sforshee commented Jun 7, 2021

It looks like hook_exit replaces system_exit, but unhook_exit never restores the original one when DISABLE_EBS_PROTENCTION is on. It feels like unhook_exit should be unhooking things even with DISABLE_EBS_PROTECTION on.

Yeah, looking again you are probably right that the mistake was putting the ifdef around the code around unhooking Exit() instead of ExitBootServices(). I'll update the patch.

When EBS protection is disabled the code which hooks into EBS is
complied out, but on unhook it's the code which restores Exit() that
is disabled. This appears to be a mistake, and it can result in
writing NULL to EBS in the boot services table.

Fix this by moving the ifdefs to compile out the code to unhook EBS
instead of the code to unhook Exit(). Also ifdef the definition of
system_exit_boot_services to safeguard against its accidental use.

Fixes: 4b0a61d ("shim: compile time option to bypass the ExitBootServices() check")
Signed-off-by: Seth Forshee <[email protected]>
@sforshee sforshee force-pushed the fix-ebs-protection-unhook branch from e7ece65 to c5928d5 Compare June 7, 2021 13:09
Copy link
Collaborator

@julian-klode julian-klode left a comment

Choose a reason for hiding this comment

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

Launching shimx64.efi from EFI shell, and then exiting the grub it chainloads. With the change applied, it correctly exits back to the shell; before it was resetting the system.

@vathpela vathpela merged commit 4583db4 into rhboot:main Jul 20, 2021
@sforshee sforshee deleted the fix-ebs-protection-unhook branch July 29, 2021 14:55
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.

4 participants