Skip to content

Commit 2c51618

Browse files
authored
TPM: Break dependency on underhill_confidentiality (#1884)
underhill_confidentiality is an openhcl-specific crate, and should not be depended on by a generic device. The TPM slipped this by. Fix it by passing in the needed info at construction instead.
1 parent fd2e4fb commit 2c51618

File tree

9 files changed

+17
-8
lines changed

9 files changed

+17
-8
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7189,7 +7189,6 @@ dependencies = [
71897189
"tpm_resources",
71907190
"tracelimit",
71917191
"tracing",
7192-
"underhill_confidentiality",
71937192
"vm_resource",
71947193
"vmcore",
71957194
"zerocopy 0.8.24",

openhcl/underhill_core/src/worker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,6 +2575,7 @@ async fn new_underhill_vm(
25752575
register_layout,
25762576
guest_secret_key: platform_attestation_data.guest_secret_key,
25772577
logger: Some(GetTpmLoggerHandle.into_resource()),
2578+
is_confidential_vm: isolation.is_isolated(),
25782579
}
25792580
.into_resource(),
25802581
});

openvmm/openvmm_entry/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,7 @@ fn vm_config_from_command_line(
10181018
register_layout,
10191019
guest_secret_key: None,
10201020
logger: None,
1021+
is_confidential_vm: false,
10211022
}
10221023
.into_resource(),
10231024
});

petri/src/vm/openvmm/modify.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl PetriVmConfigOpenVmm {
5555
register_layout: TpmRegisterLayout::IoPort,
5656
guest_secret_key: None,
5757
logger: None,
58+
is_confidential_vm: self.firmware.isolation().is_some(),
5859
}
5960
.into_resource(),
6061
});

vm/devices/tpm/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ chipset_device.workspace = true
1919
chipset_device_resources.workspace = true
2020
cvm_tracing.workspace = true
2121
guestmem.workspace = true
22-
underhill_confidentiality = { workspace = true, features = ["std"] }
2322
vmcore.workspace = true
2423
vm_resource.workspace = true
2524

vm/devices/tpm/src/lib.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ use tpm20proto::NV_INDEX_RANGE_BASE_TCG_ASSIGNED;
5757
use tpm20proto::ReservedHandle;
5858
use tpm20proto::TPM20_HT_PERSISTENT;
5959
use tpm20proto::TPM20_RH_PLATFORM;
60-
use underhill_confidentiality::is_confidential_vm;
6160
use vmcore::device_state::ChangeDeviceState;
6261
use vmcore::non_volatile_store::NonVolatileStore;
6362
use vmcore::non_volatile_store::NonVolatileStoreError;
@@ -347,6 +346,7 @@ impl Tpm {
347346
ak_cert_type: TpmAkCertType,
348347
guest_secret_key: Option<Vec<u8>>,
349348
logger: Option<Arc<dyn TpmLogger>>,
349+
is_confidential_vm: bool,
350350
) -> Result<Self, TpmError> {
351351
tracing::info!("initializing TPM");
352352

@@ -428,7 +428,8 @@ impl Tpm {
428428
};
429429

430430
if !is_restoring {
431-
tpm.on_first_boot(guest_secret_key).await?;
431+
tpm.on_first_boot(guest_secret_key, is_confidential_vm)
432+
.await?;
432433
}
433434

434435
tracing::info!("TPM initialized");
@@ -449,7 +450,11 @@ impl Tpm {
449450
Ok(())
450451
}
451452

452-
async fn on_first_boot(&mut self, guest_secret_key: Option<Vec<u8>>) -> Result<(), TpmError> {
453+
async fn on_first_boot(
454+
&mut self,
455+
guest_secret_key: Option<Vec<u8>>,
456+
is_confidential_vm: bool,
457+
) -> Result<(), TpmError> {
453458
use ms_tpm_20_ref::NvError;
454459
let mut force_ak_regen = false;
455460
let fixup_16k_ak_cert;
@@ -482,9 +487,8 @@ impl Tpm {
482487
// If this is a confidential VM or has a vTPM blob size that indicates that it was
483488
// HCL-provisioned, regenerate the AK from TPM seeds. This prevents an attack where
484489
// the VTL0 admin can replace the AK and get an AKCert for it.
485-
force_ak_regen = self.refresh_tpm_seeds
486-
|| blob.len() != LEGACY_VTPM_SIZE
487-
|| is_confidential_vm();
490+
force_ak_regen =
491+
self.refresh_tpm_seeds || blob.len() != LEGACY_VTPM_SIZE || is_confidential_vm;
488492

489493
// If this is a small vTPM blob, potentially fixup the AK cert.
490494
fixup_16k_ak_cert = blob.len() == LEGACY_VTPM_SIZE;

vm/devices/tpm/src/resolver.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ impl AsyncResolveResource<ChipsetDeviceHandleKind, TpmDeviceHandle> for TpmDevic
117117
ak_cert_type,
118118
resource.guest_secret_key,
119119
logger,
120+
resource.is_confidential_vm,
120121
)
121122
.await
122123
.map_err(ResolveTpmError::Tpm)?;

vm/devices/tpm/src/tpm_helper.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3754,6 +3754,7 @@ mod tests {
37543754
TpmAkCertType::Trusted(Arc::new(TestRequestAkCertHelper {})),
37553755
None,
37563756
None,
3757+
false,
37573758
)
37583759
.await
37593760
.unwrap();

vm/devices/tpm_resources/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub struct TpmDeviceHandle {
3030
pub guest_secret_key: Option<Vec<u8>>,
3131
/// Optional logger to send event to the host
3232
pub logger: Option<Resource<TpmLoggerKind>>,
33+
/// Whether or not the TPM is in a confidential VM
34+
pub is_confidential_vm: bool,
3335
}
3436

3537
impl ResourceId<ChipsetDeviceHandleKind> for TpmDeviceHandle {

0 commit comments

Comments
 (0)