Linux Integrity Measurement development
 help / color / mirror / Atom feed
From: Rustam Mustafin <rmustafin@cloudlinux.com>
To: Peter Huewe <peterhuewe@gmx.de>, Jarkko Sakkinen <jarkko@kernel.org>
Cc: Jason Gunthorpe <jgg@ziepe.ca>, Shuah Khan <shuah@kernel.org>,
	Jaewon Yang <yong010301@gmail.com>,
	linux-integrity@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Rustam Mustafin <rmustafin@cloudlinux.com>
Subject: [PATCH v2 0/2] tpm: Track the response read position internally
Date: Fri, 20 Nov 2026 19:16:12 +0700	[thread overview]
Message-ID: <20261120121614.978396-1-rmustafin@cloudlinux.com> (raw)

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


             reply	other threads:[~2026-11-20 12:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 12:16 Rustam Mustafin [this message]
2026-11-20 12:16 ` [PATCH v2 1/2] tpm: Track the response read position internally Rustam Mustafin
2026-11-20 12:27   ` Jarkko Sakkinen
2026-11-20 12:16 ` [PATCH v2 2/2] selftests: tpm2: test that io_uring reads ignore the file offset Rustam Mustafin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120121614.978396-1-rmustafin@cloudlinux.com \
    --to=rmustafin@cloudlinux.com \
    --cc=jarkko@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    --cc=shuah@kernel.org \
    --cc=yong010301@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox