All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] tpm: Track the response read position internally
@ 2026-11-20 12:16 Rustam Mustafin
  2026-11-20 12:16 ` [PATCH v2 1/2] " Rustam Mustafin
  2026-11-20 12:16 ` [PATCH v2 2/2] selftests: tpm2: test that io_uring reads ignore the file offset Rustam Mustafin
  0 siblings, 2 replies; 6+ messages in thread
From: Rustam Mustafin @ 2026-11-20 12:16 UTC (permalink / raw)
  To: Peter Huewe, Jarkko Sakkinen
  Cc: Jason Gunthorpe, Shuah Khan, Jaewon Yang, linux-integrity,
	linux-kselftest, linux-kernel, Rustam Mustafin

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/20261117104838.2650999-1-rmustafin@cloudlinux.com/

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
-- 
2.52.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-20 14:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 12:16 [PATCH v2 0/2] tpm: Track the response read position internally Rustam Mustafin
2026-11-20 12:16 ` [PATCH v2 1/2] " Rustam Mustafin
2026-11-20 12:27   ` Jarkko Sakkinen
2026-11-20 14:28     ` Rustam Mustafin
2026-11-20 14:50       ` Jarkko Sakkinen
2026-11-20 12:16 ` [PATCH v2 2/2] selftests: tpm2: test that io_uring reads ignore the file offset Rustam Mustafin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.