Skip to content

tpm: Track the response read position internally

Rustam Mustafin linux-integrity linux-kselftest lkml stable 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 5 repliesIn review
  2. v11 patch 8 repliesSuperseded

Changes in v2 from the cover letter

- commit message reworked per review, read()/write() race trace added
- add a kselftest

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2tpm: Track the response read position internallydrivers/char/tpm/tpm-dev-common.c drivers/char/tpm/tpm-dev.h+7 -53 replies
2/2selftests: tpm2: test that io_uring reads ignore the file offsettools/testing/selftests/tpm2/.gitignore tools/testing/selftests/tpm2/Makefile tools/testing/selftests/tpm2/tpm_uring.c+136 -06 replies

Reviews trailers per patch

1 of 2 patches has a Reviewed-by or Acked-by.

PatchJarkko Sakkinen
1/2
2/2R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/2] tpm: Track the response read position internally

tpm_common_read() uses *off as an index into priv->data_buffer. nonseekable_open() makes pread() fail, but an IORING_OP_READ request still reaches tpm_common_read() through loop_rw_iter() with *off set to sqe->off, and a plain read() racing a write() reaches it with a stale f_pos. Both allow out-of-bounds reads and zeroing of kernel memory.

Patch 1 moves the read position into struct file_priv, under buffer_mutex, and ignores *off.

Patch 2 adds a kselftest: an io_uring read with sqe->off inside the response buffer must return the whole response from its start.

Blocking io_uring, suggested in the v1 review, is no longer needed for safety with patch 1; I discuss it in the v1 thread.

Tested in a QEMU guest with swtpm and KASAN: the tpm2 selftests pass with patch 1, and the new one fails without it.
Claude Opus 5.5 was used in preparing this series.

Changes in v2:
- commit message reworked per review, read()/write() race trace added
- add a kselftest

v1: https://lore.kernel.org/all/[email protected]/

Rustam Mustafin (2):
tpm: Track the response read position internally
selftests: tpm2: test that io_uring reads ignore the file offset

 drivers/char/tpm/tpm-dev-common.c        |  11 +-
 drivers/char/tpm/tpm-dev.h               |   1 +
 tools/testing/selftests/tpm2/.gitignore  |   1 +
 tools/testing/selftests/tpm2/Makefile    |   4 +
 tools/testing/selftests/tpm2/tpm_uring.c | 131 +++++++++++++++++++++++
 5 files changed, 143 insertions(+), 5 deletions(-)
 create mode 100644 tools/testing/selftests/tpm2/tpm_uring.c

base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4

Signature · 1 line
2.52.0