Repository navigation
uefi-services: Return event in init - #920
Merged
nicholasbishop merged 1 commit intoOct 25, 2023
Merged
Conversation
JohnAZoidberg
force-pushed
the
init-return-event
branch
2 times, most recently
from
August 15, 2023 07:03
04a0037 to
e386fc8
Compare
As mentioned in rust-osdev#917 If the app built with uefi-services exits before ExitBootServices, UEFI will call `UnloadImage` on it. Then the callback function is not in memory anymore and when ExitBootServices runs, invalid memory is accessed. QEMU will crash like this when the Linux EFISTUB calls ExitBootServices: ``` !!!! X64 Exception Type - 06(#UD - Invalid Opcode) CPU Apic ID - 00000000 !!!! RIP - 000000003E13F018, CS - 0000000000000038, RFLAGS - 0000000000210246 RAX - 0000000000000000, RCX - 000000003E191E98, RDX - 0000000000000000 RBX - 0000000000000004, RSP - 000000003FF0FD08, RBP - 000000003FF28740 RSI - 000000003E167518, RDI - 000000003FF6A5E0 R8 - 000000003FF27140, R9 - 000000003F4807A0, R10 - 0000000000000001 R11 - 00000000000000E1, R12 - 000000003E191EE0, R13 - 0000000000000100 R14 - 000000003FF28840, R15 - 000000003E191E98 DS - 0000000000000030, ES - 0000000000000030, FS - 0000000000000030 GS - 0000000000000030, SS - 0000000000000030 CR0 - 0000000080010033, CR2 - 0000000000000000, CR3 - 000000003FC01000 CR4 - 0000000000000668, CR8 - 0000000000000000 DR0 - 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000 DR3 - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0000000000000400 GDTR - 000000003F9DE000 0000000000000047, LDTR - 0000000000000000 IDTR - 000000003F471018 0000000000000FFF, TR - 0000000000000000 FXSAVE_STATE - 000000003FF0F960 !!!! Find image based on IP(0x3E13F018) (No PDB) (ImageBase=000000003DF1E000, EntryPoint=000000003DF1F000) !!!! ``` To avoid the crash, the user should close the event before the app exits. ```rs fn main(image_handle: Handle, mut system_table: SystemTable<Boot>) -> Status { let event: Option<Event> = uefi_services::init(&mut system_table).unwrap(); let boot_services = system_table.boot_services(); println!("Hello World"); if let Some(event) = event { // Will creash when Linux boots if we don't call this boot_services.close_event(event).unwrap(); } Status::SUCCESS } ``` It would be nice to have this happen automatically by a Drop implementation but this already lets users do it on their own, if they need. Signed-off-by: Daniel Schaefer <dhs@frame.work>
JohnAZoidberg
force-pushed
the
init-return-event
branch
from
August 31, 2023 06:03
e386fc8 to
e6995a5
Compare
Member
|
Taking another look at this, I think we're still not quite ready to implement a fix from #943. So I will go ahead and merge your fix, as it's a sensible and minimal update that allows applications to solve the issue. Thanks for the PR, sorry it took a while :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As mentioned in #917 If the app built with uefi-services exits before ExitBootServices, UEFI will call
UnloadImageon it. Then the callback function is not in memory anymore and when ExitBootServices runs, invalid memory is accessed.QEMU will crash like this when the Linux EFISTUB calls ExitBootServices:
To avoid the crash, the user should close the event before the app exits.
It would be nice to have this happen automatically by a Drop implementation but this already lets users do it on their own, if they need.
Checklist