Repository navigation
feat: Secure TSC for AMD SEV-SNP, and secure_time refuses a host-controlled clock - #1642
Conversation
ea744bc to
1b97ccf
Compare
Without Secure TSC the hypervisor can intercept RDTSC and change the TSC offset and scale, so guest time is host-controlled between NTS syncs. Add cvm.snp_secure_tsc (off by default, needs QEMU >= 11.1 and host kernel >= 6.18). It adds secure-tsc=on to the sev-snp-guest object and sets SEV_FEATURES bit 9 in the measurement document; dstack-mr now accepts that bit. Signed-off-by: Kevin Wang <wy721@qq.com>
secure_time waits for an NTS sync, but between syncs the clock follows the TSC. Before waiting, require the tsc clocksource, require Secure TSC on AMD SEV-SNP, and reject AWS. The guest kernel has no userspace interface for the Secure TSC status, so add a kernel patch exposing it as /sys/devices/system/cpu/sev/secure_tsc. Signed-off-by: Kevin Wang <wy721@qq.com>
Drop cvm.snp_secure_tsc. A host option could break every SNP guest on a QEMU without secure-tsc, including apps that never asked for a secure clock. Only an app whose compose sets secure_time now gets secure-tsc=on, so every other app launches exactly as before, with the same launch digest. Signed-off-by: Kevin Wang <wy721@qq.com>
Move the secure_tsc -> SEV_FEATURES mapping into dstack-mr, build the sev-snp-guest object in one function, and cover the secure_time launch on both sides: guest_features in the measurement document and secure-tsc=on on the QEMU object. Name secure_time when platform detection fails. Signed-off-by: Kevin Wang <wy721@qq.com>
3ef637a to
0c6923b
Compare
QEMU documents secure-tsc as "since 11.1", but v11.1.3 does not have the property; v11.2.0-rc1 does. /proc/cpuinfo has no snp_secure_tsc flag either: the kernel does not list that feature there. Signed-off-by: Kevin Wang <wy721@qq.com>
The yocto backend is going away, so the new patch lives with the mkosi kernel component instead. Signed-off-by: Kevin Wang <wy721@qq.com>
requirements and secure_time both come from the app compose, so take the compose itself instead of one argument per field. Signed-off-by: Kevin Wang <wy721@qq.com>
Leechael
left a comment
There was a problem hiding this comment.
A note on the QEMU requirement, since it decides who this breaks on upgrade. I have no SNP host to launch on, so this is from reading the code at 3489413 and the upstream trees.
secure-tsc is not in any released QEMU yet. Checked target/i386/sev.c at each tag:
| QEMU tag | secure-tsc property |
|---|---|
| v10.2.0, v11.0.0, v11.1.0, v11.1.3 | absent |
| v11.2.0-rc0 / rc1 / rc2, master | present |
The host side lines up with the description otherwise: KVM has Secure TSC from v6.18 (absent in v6.17), the guest from v6.14.
So after this merges and a VMM is upgraded, an SNP app with secure_time cannot launch on any host running a released QEMU, and the only way to run it is a release candidate. That is stated as breaking, but two things make it wider and harder to diagnose than the notes suggest, inline.
Suggest holding the VMM half until 11.2.0 is out, or gating it (see inline) so that hosts on a released QEMU keep launching what they launch today.
…P app The upgrade note said apps without secure_time launch as before, but secure_time defaults to true when the app compose omits it. Only apps with secure_time: false are unaffected. Signed-off-by: Kevin Wang <wy721@qq.com>
Signed-off-by: Kevin Wang <wy721@qq.com> # Conflicts: # CHANGELOG.md
Without Secure TSC the hypervisor can intercept
RDTSCand change the TSC offset and scale, so on AMD SEV-SNP guest time is host-controlled between NTS syncs.VMM / verification
secure_timeon (the default when the app compose omits it) is launched withsecure-tsc=onon thesev-snp-guestobject andSEV_FEATURESbit 9 in the measurement document. Apps withsecure_time: falselaunch exactly as before, with the same launch digest.dstack-mracceptsSNPActive | SecureTSCinguest_features.v11.2.0-rc1exists today; QEMU's docs say 11.1, butv11.1.3lacks the property), host kernel >= 6.18 and a CPU that supports it. A KMS or verifier without this change rejects such a guest.Guest
secure_timeenabled,dstack-utilnow refuses to boot unless the clocksource istsc; on AMD SEV-SNP it also requires Secure TSC, and on AWS it always refuses.sev_statusbit as/sys/devices/system/cpu/sev/secure_tsc.Breaking: an app with
secure_timeon, including one that omits the key, no longer boots on AWS, or on an SNP host that cannot launch with Secure TSC (an older QEMU exits on the unknownsecure-tscproperty). Apps withsecure_time: falseare unaffected, including on older QEMU.Testing
Unit:
cargo test -p dstack-mr --lib,cargo test -p dstack-vmm,cargo test -p dstack-utilpass.On SEV-SNP hardware: EPYC 7763 (Milan), host kernel 7.0.0, QEMU
v11.2.0-rc1, VMM and verifier from0c6923bbe6, dev image built from the same commit with mkosi (guest kernel 6.18.59), 2 vCPU / 4 GiB, no KMS or gateway.secure_time, launched by the VMMSEV: Status: SEV SEV-ES SEV-SNP SecureTSC; sysfssecure_tsc= 1; clocksourcetsc; NTS sync passesguest_features513; verifier:is_valid,os_image_hash_verifiedsecure_timesecure-tsc; sysfssecure_tsc= 0;guest_features1; verifier:is_validsecure_time, QEMU run by hand withoutsecure-tsc=ondstack-preparefails:secure_time requires amd sev-snp Secure TSC, which the host did not enablesecure_timeon the released 0.6.5 imageis_validOn TDX (tdxlab): Xeon Gold 6526Y, host kernel 6.8.0-1028-intel, QEMU 8.2.2 (Ubuntu tdx1.1), shared VMM, KMS 0.6.5 with dev-auth webhook, dev image built from
ea065c4b1b, 2 vCPU / 4 GiB.secure_timetsc; secure clock check passes, waits for NTS sync, gets app keys from KMS, containers startsecure_timeNot tested: GCP and AWS guests with the new image.