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

attester: az_snp_vtpm: Check cpuid bits in detect_platform() #169

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion attestation-agent/attester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ az-snp-vtpm = { git = "https://github.com/kinvolk/azure-cvm-tooling", rev = "2c2
base64.workspace = true
log.workspace = true
occlum_dcap = { git = "https://github.com/occlum/occlum", rev = "dbe404f", optional = true }
raw-cpuid = { version = "11", optional = true }
serde.workspace = true
serde_json.workspace = true
sev = { git = "https://github.com/virtee/sev", rev = "3dca05d2c93388cb00534ad18f5928fd812e99cc", optional = true }
Expand All @@ -23,5 +24,5 @@ all-attesters = ["tdx-attester", "occlum-attester", "az-snp-vtpm-attester", "snp

tdx-attester = ["tdx-attest-rs"]
occlum-attester = ["occlum_dcap"]
az-snp-vtpm-attester = ["az-snp-vtpm"]
az-snp-vtpm-attester = ["az-snp-vtpm", "dep:raw-cpuid"]
snp-attester = ["sev"]
34 changes: 32 additions & 2 deletions attestation-agent/attester/src/az_snp_vtpm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,41 @@ use super::Attester;
use anyhow::*;
use az_snp_vtpm::{imds, vtpm};
use log::debug;
use raw_cpuid::{cpuid, CpuId, Hypervisor};
use serde::{Deserialize, Serialize};
use std::path::Path;

pub fn detect_platform() -> bool {
if let Err(err) = vtpm::get_report() {
debug!("Failed to retrieve Azure HCL data from vTPM: {err}");
if !Path::new("/dev/tpm0").exists() {
debug!("vTPM device not found");
return false;
}

let cpuid = CpuId::new();
let Some(hyper_info) = cpuid.get_hypervisor_info() else {
debug!("Not a VM");
return false;
};
let hypervisor = hyper_info.identify();
debug!("Hypervisor: {:?}", hypervisor);
if hypervisor != Hypervisor::HyperV {
return false;
}

const HYPERV_CPUID_FEATURES: u32 = 0x40000003;
const HV_ISOLATION: u32 = 1 << 22;
let hv_features = cpuid!(HYPERV_CPUID_FEATURES);
if hv_features.ebx & HV_ISOLATION == 0 {
debug!("VM is not an isolation VM");
return false;
}

const HYPERV_CPUID_ISOLATION_CONFIG: u32 = 0x4000000C;
const HV_ISOLATION_TYPE: u32 = 0xF;
const HV_ISOLATION_TYPE_SNP: u32 = 2;
let hv_isol_config = cpuid!(HYPERV_CPUID_ISOLATION_CONFIG);
if hv_isol_config.ebx & HV_ISOLATION_TYPE != HV_ISOLATION_TYPE_SNP {
debug!("VM is not an SNP VM");
return false;
}
true
Expand Down