Skip to content

Commit a8ae316

Browse files
committed
feature/tpm: check TPM family data for compatibility (tailscale#17624)
Check that the TPM we have opened is advertised as a 2.0 family device before using it for state sealing / hardware attestation. Updates tailscale#17622 Signed-off-by: Patrick O'Doherty <patrick@tailscale.com> (cherry picked from commit 36ad24b)
1 parent 75b0c6f commit a8ae316

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

feature/tpm/tpm.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@ func init() {
5555
}
5656

5757
func tpmSupported() bool {
58-
tpm, err := open()
59-
if err != nil {
58+
hi := infoOnce()
59+
if hi == nil {
6060
return false
6161
}
62-
tpm.Close()
63-
return true
62+
return hi.FamilyIndicator == "2.0"
6463
}
6564

6665
var verboseTPM = envknob.RegisterBool("TS_DEBUG_TPM")
@@ -104,6 +103,7 @@ func info() *tailcfg.TPMInfo {
104103
{tpm2.TPMPTVendorTPMType, func(info *tailcfg.TPMInfo, value uint32) { info.Model = int(value) }},
105104
{tpm2.TPMPTFirmwareVersion1, func(info *tailcfg.TPMInfo, value uint32) { info.FirmwareVersion += uint64(value) << 32 }},
106105
{tpm2.TPMPTFirmwareVersion2, func(info *tailcfg.TPMInfo, value uint32) { info.FirmwareVersion += uint64(value) }},
106+
{tpm2.TPMPTFamilyIndicator, toStr(&info.FamilyIndicator)},
107107
} {
108108
resp, err := tpm2.GetCapability{
109109
Capability: tpm2.TPMCapTPMProperties,

feature/tpm/tpm_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,19 @@ func TestStore(t *testing.T) {
133133
})
134134
}
135135

136+
func BenchmarkInfo(b *testing.B) {
137+
b.StopTimer()
138+
skipWithoutTPM(b)
139+
b.StartTimer()
140+
for i := 0; i < b.N; i++ {
141+
hi := info()
142+
if hi == nil {
143+
b.Fatalf("tpm info error")
144+
}
145+
}
146+
b.StopTimer()
147+
}
148+
136149
func BenchmarkStore(b *testing.B) {
137150
skipWithoutTPM(b)
138151
b.StopTimer()

ipn/ipnlocal/c2n_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ func TestRedactNetmapPrivateKeys(t *testing.T) {
384384
f(tailcfg.Service{}, "Port"): false,
385385
f(tailcfg.Service{}, "Proto"): false,
386386
f(tailcfg.Service{}, "_"): false,
387+
f(tailcfg.TPMInfo{}, "FamilyIndicator"): false,
387388
f(tailcfg.TPMInfo{}, "FirmwareVersion"): false,
388389
f(tailcfg.TPMInfo{}, "Manufacturer"): false,
389390
f(tailcfg.TPMInfo{}, "Model"): false,

tailcfg/tailcfg.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,10 @@ type TPMInfo struct {
928928
// https://trustedcomputinggroup.org/resource/tpm-library-specification/.
929929
// Before revision 184, TCG used the "01.83" format for revision 183.
930930
SpecRevision int `json:",omitempty"`
931+
932+
// FamilyIndicator is the TPM spec family, like "2.0".
933+
// Read from TPM_PT_FAMILY_INDICATOR.
934+
FamilyIndicator string `json:",omitempty"`
931935
}
932936

933937
// Present reports whether a TPM device is present on this machine.

0 commit comments

Comments
 (0)