Exploit database

GH-a3db17127ece06a31875fad73afc3123

freax13/cve-2024-21978-poc

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2024-21978

1 source

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.

Repository files4
freax13/cve-2024-21978-pocRevision c923fb3a0329

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

src/snp_types.rs

Rust · 2,373 bytes
use bitflags::bitflags;
use bytemuck::NoUninit;

use bit_field::BitField;
use bytemuck::CheckedBitPattern;

#[derive(Clone, Copy, PartialEq, Eq)]
#[repr(transparent)]
pub struct GuestPolicy {
    policy: u64,
}

impl GuestPolicy {
    pub fn new(abi_major: u8, abi_minor: u8) -> Self {
        let mut policy = 0;
        policy.set_bits(0..=7, u64::from(abi_minor));
        policy.set_bits(8..=15, u64::from(abi_major));
        policy.set_bit(17, true); // Reserved. Must be one.
        Self { policy }
    }

    pub fn abi_major(&self) -> u8 {
        self.policy.get_bits(8..=15) as u8
    }

    pub fn abi_minor(&self) -> u8 {
        self.policy.get_bits(0..=7) as u8
    }

    pub fn allow_smt(self) -> bool {
        self.policy.get_bit(16)
    }

    pub fn with_allow_smt(self, allow: bool) -> Self {
        let mut policy = self.policy;
        policy.set_bit(16, allow);
        Self { policy }
    }

    pub fn allow_migration_agent_association(self) -> bool {
        self.policy.get_bit(18)
    }

    pub fn allow_debugging(self) -> bool {
        self.policy.get_bit(19)
    }

    pub fn single_socket_only(self) -> bool {
        self.policy.get_bit(17)
    }
}

unsafe impl CheckedBitPattern for GuestPolicy {
    type Bits = u64;

    fn is_valid_bit_pattern(bits: &Self::Bits) -> bool {
        bits.get_bit(17) && bits.get_bits(20..) == 0
    }
}

impl core::fmt::Debug for GuestPolicy {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        f.debug_struct("GuestPolicy")
            .field("abi_major", &self.abi_major())
            .field("abi_minor", &self.abi_minor())
            .field("allow_smt", &self.allow_smt())
            .field("single_socket_only", &self.single_socket_only())
            .field(
                "allow_migration_agent_association",
                &self.allow_migration_agent_association(),
            )
            .field("allow_debugging", &self.allow_debugging())
            .finish()
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PageType {
    Secrets = 0x5,
}

bitflags! {
    #[derive(NoUninit)]
    #[repr(transparent)]
    pub struct VmplPermissions: u8 {
        const READ = 1 << 0;
        const WRITE = 1 << 1;
        const EXECUTE_USER = 1 << 2;
        const EXECUTE_SUPERVISOR = 1 << 3;
        const SUPERVISOR_SHADOW_STACK = 1 << 4;
    }
}