TPM Core、命令设备与 Resource Manager

TPM Core、命令设备与 Resource Manager

1. 分层

1
2
3
4
5
6
Userspace TSS
-> /dev/tpmN or /dev/tpmrmN
-> TPM Core
-> TPM 1.2/2.0 command helpers
-> transport ops
-> physical TPM / fTPM / vTPM

TPM Core不等于可信启动策略;它只提供命令、资源、事件日志和chip生命周期。

2. tpm_chip

struct tpm_chip包含:

  • struct device
  • tpm_class_ops transport;
  • TPM版本/flags;
  • command buffer和超时;
  • ops semaphore;
  • dev_num;
  • cdev与resource-manager cdev;
  • PCR bank和event log;
  • shutdown/work状态。

Transport通过tpmm_chip_alloc()创建并 tpm_chip_register()发布。

3. Device Nodes

  • /dev/tpmN:直通式命令设备;
  • /dev/tpmrmN:TPM 2.0 resource manager;
  • sysfs/securityfs:PCR、caps、event log等。

普通tpmN更接近独占硬件上下文;tpmrmN为每fd维护virtualized handle/session空间。

4. 命令路径

1
2
3
4
5
6
7
8
9
write TPM command
-> validate header/length/tag
-> lock chip ops
-> transmit
-> transport send/recv/status/cancel
-> validate response
-> cache response in file context
read
-> copy response

一个write对应一个command,read取得结果。非法size或命令状态返回errno。

5. File Context

tpm_file_priv保存:

  • response buffer;
  • response length;
  • timeout work;
  • TPM space;
  • chip引用。

每fd上下文避免不同进程命令/响应串线。Release取消work并清理space。

6. Resource Manager

tpmrm-dev.ctpm2-space.c在context switch时:

  • load该fd的transient objects/sessions;
  • 重写virtual handle到physical handle;
    -执行命令;
  • 保存/flush对象;
  • 将response handle映射回virtual值。

它不虚拟化PCR或所有global TPM state,应用仍可能互相影响。

7. TPM 1.2与2.0

  • tpm1-cmd.c:startup、PCR、capability、self-test、random;
  • tpm2-cmd.c:PCR banks、properties、startup、self-test、random;
  • TPM 2.0支持resource manager;
  • timeouts根据命令duration和设备属性计算。

8. Event Log

eventlog/支持OF、EFI和ACPI来源,并解析TPM1/TPM2 measurement records。

Event log是boot measurement记录,不是TPM实时读出的PCR镜像。验证需重新扩展日志并与PCR比较。

9. HWRNG

HW_RANDOM_TPM可将TPM GetRandom注册为hwrng。TPM随机接口通常吞吐低,且会与TPM命令竞争,不应作为高带宽随机源。

10. 并发

TPM物理命令串行化;ops lock防止并发传输。Long command、cancel和timeout work会与remove/suspend竞争。

Shutdown必须:

  • 阻止新command;
  • cancel timeout work;
  • 等当前transmit;
    -注销cdev;
  • 释放transport。

11. 权限

TPM并非“只有root才能安全使用”。Node权限、TSS daemon和resource manager共同决定多用户隔离。

高风险命令包括:

  • hierarchy/owner授权修改;
  • NV define/write;
  • PCR extend;
  • dictionary attack参数;
  • clear/change EPS;
  • firmware vendor command。

应使用policy session和最小设备权限。

12. 可信启动

完整链路还需要:

  • boot ROM/bootloader measurement;
  • event log传递;
  • kernel IMA/EVM;
  • PCR policy;
  • remote attestation;
  • key sealing;
  • 安全更新和anti-rollback。

只看到/dev/tpm0不代表系统已实现可信启动。

文章互动

阅读 --

留言

0 条留言

正在加载留言…