Skip to content

Commit 9fe44b3

Browse files
committed
feature/tpm: use withSRK to probe TPM availability (tailscale#17627)
On some platforms e.g. ChromeOS the owner hierarchy might not always be available to us. To avoid stale sealing exceptions later we probe to confirm it's working rather than rely solely on family indicator status. Updates tailscale#17622 Signed-off-by: Patrick O'Doherty <patrick@tailscale.com> (cherry picked from commit 672b1f0)
1 parent a8ae316 commit 9fe44b3

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

feature/tpm/tpm.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,22 @@ func tpmSupported() bool {
5959
if hi == nil {
6060
return false
6161
}
62-
return hi.FamilyIndicator == "2.0"
62+
if hi.FamilyIndicator != "2.0" {
63+
return false
64+
}
65+
66+
tpm, err := open()
67+
if err != nil {
68+
return false
69+
}
70+
defer tpm.Close()
71+
72+
if err := withSRK(logger.Discard, tpm, func(srk tpm2.AuthHandle) error {
73+
return nil
74+
}); err != nil {
75+
return false
76+
}
77+
return true
6378
}
6479

6580
var verboseTPM = envknob.RegisterBool("TS_DEBUG_TPM")

feature/tpm/tpm_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ func BenchmarkInfo(b *testing.B) {
146146
b.StopTimer()
147147
}
148148

149+
func BenchmarkTPMSupported(b *testing.B) {
150+
b.StopTimer()
151+
skipWithoutTPM(b)
152+
b.StartTimer()
153+
for i := 0; i < b.N; i++ {
154+
if !tpmSupported() {
155+
b.Fatalf("tpmSupported returned false")
156+
}
157+
}
158+
b.StopTimer()
159+
}
160+
149161
func BenchmarkStore(b *testing.B) {
150162
skipWithoutTPM(b)
151163
b.StopTimer()

0 commit comments

Comments
 (0)