Page MenuHomeFreeBSD

tpm20: Harden the common device lifecycle
ClosedPublic

Authored by kbowling on Fri, Aug 28, 12:53 AM.
Tags
None
Referenced Files
F170863693: D59240.id185431.diff
Mon, Sep 7, 3:02 AM
F170863313: D59240.id185669.diff
Mon, Sep 7, 2:59 AM
F170829767: D59240.id185669.diff
Sun, Sep 6, 9:40 PM
F170828914: D59240.diff
Sun, Sep 6, 9:32 PM
F170822670: D59240.id185293.diff
Sun, Sep 6, 8:39 PM
F170717134: D59240.id185293.diff
Sun, Sep 6, 4:47 AM
Unknown Object (File)
Sun, Sep 6, 12:25 AM
Unknown Object (File)
Sat, Sep 5, 3:47 AM
Subscribers

Details

Summary
Mark the device as dying before teardown and destroy the character
device before freeing its private state or lock.  This prevents cdev
methods from entering with a freed internal buffer or a destroyed sx.

Check the teardown state in command paths, honor failures from the cdev
private data interface, and keep the lifecycle lock across TPM retry
delays so detach cannot interpose between retries.

Block new cdev operations after a successful Shutdown(STATE).  Keep the
suspend gate and the TPM command under the same lock so a userspace
command cannot invalidate the saved state before S3 entry.  Clear the
gate only after Startup(STATE) succeeds.

Keep entropy harvesting scheduled after a transient command or suspend
failure, but stop it while suspended or once teardown begins.  Queue the
next timeout while holding the lifecycle lock so release cannot miss a
concurrent requeue.

Validated on two TPM 2.0 FIFO systems.  Each completed five device
suspend/resume cycles, rejected both new and already-open cdev
operations with EBUSY while suspended, completed 200 concurrent PCR
reads, and detached cleanly while four PCR readers were active.  A
ThinkPad P50 also completed a full S3 cycle with PCR 0 unchanged and
50 successful reads after resume.

MFC after:      2 weeks

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/dev/tpm/tpm20.c
393

I think I agree with holding the lock prior to calling tpm20_command, but I kind of suspect we actually do want to drop it between retry attempts and recheck for sc->dying between them. We may need something to block concurrent entrance to tpm20_command, but depending on why the detach was initiated trying to talk to the hardware seems like it could be fraught with peril and it's maybe better to catch that sooner.

446–447

I'd maybe move this up above the cmd construction just to get error cases out of the way earlier, but I don't insist

This revision is now accepted and ready to land.Thu, Sep 3, 2:53 AM