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

Ensure CPUID triggered the #VC exception #4974

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions oak_restricted_kernel/src/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ mutable_interrupt_handler_with_error_code!(
) {
match error_code {
0x72 => {
// Make sure it was triggered from a CPUID instruction.
const CPUID_INSTRUCTION: u16 = 0xa20f;
// Safety: we are copying two bytes and interpreting it as a
// 16-bit number without making any other assumptions about
// the layout.
let instruction: u16 =
unsafe { core::ptr::read_unaligned(stack_frame.rip.as_ptr()) };
if instruction != CPUID_INSTRUCTION {
panic!("INSTRUCTION WAS NOT CPUID");
}

if let Some(cpuid_page) = CPUID_PAGE.get() {
let target = stack_frame.into();
let count = cpuid_page.count as usize;
Expand Down
Loading