vTPM: a TPM command that takes swtpm longer than 100 ms fails the guest's TPM permanently (tpm_recv: error -5)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Start in tpm/src/emulator.rs, especially prepare_data_fd and Emulator::deliver_request, then check the response handling in devices/src/tpm.rs. Read the receive timeout and current recvfrom logic first. Implement complete response reads with a bounded wait and validate the declared size; done when delayed and partial swtpm responses are handled without leaving a stale response for the next command.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
Emulator::deliver_request reads each TPM response from swtpm with a single
recvfrom on the data socket, which prepare_data_fd gives a 100 ms
SO_RCVTIMEO:
- https://github.com/cloud-hypervisor/cloud-hypervisor/blob/v53.0/tpm/src/emulator.rs#L189-L203 (100 ms receive timeout)
- https://github.com/cloud-hypervisor/cloud-hypervisor/blob/v53.0/tpm/src/emulator.rs#L425-L440 (one
recvfrom, error on-1)
If swtpm needs more than 100 ms to answer a command (key generation such as
TPM2_CreatePrimary on a loaded host does), recvfrom returns EAGAIN and
deliver_request fails. The CRB device then sets CTRL_STS.tpmSts:
- https://github.com/cloud-hypervisor/cloud-hypervisor/blob/v53.0/devices/src/tpm.rs#L249-L254 (
complete_request) - https://github.com/cloud-hypervisor/cloud-hypervisor/blob/v53.0/devices/src/tpm.rs#L526
The guest's tpm_crb driver returns -EIO when that bit is set, and nothing
clears it, so the TPM is unusable for the rest of the guest's life. Two
further effects:
- swtpm still finishes the command and writes its response, which stays
queued on the socket and would be read as the response to the next
command. - On a
SOCK_STREAMsocket a singlerecvfromcan return part of a
response, which is treated as complete.
Nothing is logged by Cloud Hypervisor (the failure is folded into
request_completed(status)), and swtpm logs nothing because from its side
the command succeeded.
The same code is on main as of 2026-10-11.
Impact we observed
Unattended Linux installs that seal a LUKS volume to the vTPM (Kairos, with
encrypted_partitions) failed in 5 of about 28 runs on one host, more often
when several guests installed at once. Guest kernel log at the failure,
0.2 to 0.4 s after the installer first opened the TPM:
kernel: tpm tpm0: tpm_transmit: tpm_recv: error -5
kernel: tpm tpm0: tpm_transmit: tpm_recv: error -5
systemd-udevd: ERROR:tcti:src/tss2-tcti/tcti-device.c:489:Tss2_Tcti_Device_Init() Failed to read response header fd 51, got errno 5: I/O error
(udev-worker): tpmrm0: Failed to open device node '/dev/tpmrm0': State not recoverable
To Reproduce
The fault becomes deterministic when swtpm is slowed down. With swtpm
running as a systemd unit, cap its CPU before the guest boots:
swtpm socket --tpm2 --tpmstate dir=/var/lib/vtpm --ctrl type=unixio,path=/run/vtpm/swtpm.sock
# as a unit, then:
systemctl set-property --runtime <swtpm unit> CPUQuota=3%
cloud-hypervisor --api-socket path=/run/vm/api.sock ...
# VM config with: "tpm": {"socket": "/run/vtpm/swtpm.sock"}
With swtpm at 3 % CPU, the Linux guest's boot failed already at the
kernel's TPM probe:
kernel: tpm tpm0: tpm_transmit: tpm_recv: error -5
kernel: tpm tpm0: tpm_transmit: tpm_recv: error -5
kernel: tpm_crb_acpi MSFT0101:00: probe with driver tpm_crb_acpi failed with error -5
systemd: Timed out waiting for device /dev/tpmrm0.
Without the throttle the failure is intermittent and load-dependent, as
above.
Expected behaviour
A slow command completes slowly. The kernel allows TPM2 commands up to
TPM2_DURATION_LONG_LONG (300 s); swtpm taking a few hundred milliseconds
should not fail the TPM. QEMU's swtpm backend reads the response header and
then the declared length, without a short per-read timeout.
Suggested fix
In deliver_request, read the 10-byte response header, then exactly the
responseSize it declares, looping over short reads; treat
EAGAIN/EINTR from the 100 ms socket timeout as "keep waiting" until an
overall deadline (we used 120 s), and reject a declared size smaller than a
header or larger than the buffer.
We tested this change on v53.0. Under the same 3 % CPU throttle that failed
the boot, the guest's TPM works and the encrypted install completes in
normal time, and 10 of 10 unthrottled installs (6 concurrent) succeeded. We
have the patch with unit tests (a response split across a delay longer than
the socket timeout, the deadline, an impossible size, swtpm closing
mid-response) and can share it.
Version
Output of cloud-hypervisor --version: cloud-hypervisor v53.0
Did you build from source: no, the cloud-hypervisor-static v53.0 release asset.
VM configuration
VMs created through the REST API (vm.create, vm.boot) with
"tpm": {"socket": "<swtpm ctrl socket>"}, 2 vCPUs, 4 GiB, firmware
CLOUDHV.fd (edk2 ch-97eeb7b09), virtio-blk disks, one virtio-net
interface on a tap.
Guest OS version details: Kairos Hadron v0.4.0 (core), installer and
installed system; tpm_crb driver.
Host OS version details: Debian 13 (trixie), kernel 6.12.100+deb13-amd64,
2× Intel Xeon E5-2630 v3 (32 threads); swtpm 0.7.1, libtpms 0.9.2.
swtpm started as
swtpm socket --tpm2 --tpmstate dir=<dir> --ctrl type=unixio,path=<socket>.
Logs
Output of cloud-hypervisor -v: nothing is logged for the failed command
(see above).
Linux kernel output: as quoted above.
- 主要言語
- Rust
- スター
- 6.3k
- フォーク
- 786
- 平均マージ
- 1日 3時間
- マージ済み PR(30日)
- 195
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
cloud-hypervisor/cloud-hypervisor のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
cloud-hypervisor/cloud-hypervisor#9562 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
cloud-hypervisor/cloud-hypervisor#9553 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
cloud-hypervisor/cloud-hypervisor#9551 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 46/100
cloud-hypervisor/cloud-hypervisor#9550 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
cloud-hypervisor/cloud-hypervisor#9528 · リアクション 2 件 ·
メンテナーはふだん 1 日以内に返信
cloud-hypervisor/cloud-hypervisor の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
Choochmeque/tauri-plugin-webdriver#134 ·
メンテナーはふだん 17 日以内に返信
-
bug rust SDK & CLI & REST API
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
boxlite-ai/boxlite#3292 ·
メンテナーはふだん 1 日以内に返信
-
Android bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
anefzaoui/misterdownloadmanager#2516 ·
メンテナーはふだん 1 日以内に返信
-
editor ui
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
state:triage tech-debt
難易度 2/5 1〜3時間 初心者へのやさしさ 89/100
agent8-cash/ethpayserver#731 ·
メンテナーはふだん 1 日以内に返信