From: Jarkko Sakkinen <jarkko@kernel.org>
To: Rustam Mustafin <rmustafin@cloudlinux.com>
Cc: Peter Huewe <peterhuewe@gmx.de>, Jason Gunthorpe <jgg@ziepe.ca>,
Jaewon Yang <yong010301@gmail.com>,
Tadeusz Struk <tadeusz.struk@intel.com>,
linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] tpm: track the response read position internally, not via the file offset
Date: Wed, 18 Nov 2026 16:33:19 +0200 [thread overview]
Message-ID: <av23L5HBpy2gbm3m@kernel.org> (raw)
In-Reply-To: <CAG6=z5sxUo1x6mpotkNZXk=nQYvD2AyMLSDhzD3B3kqxJ1=iaw@mail.gmail.com>
On Wed, Nov 18, 2026 at 04:49:46PM +0700, Rustam Mustafin wrote:
> On Tue, Nov 17, 2026 at 7:38 PM Jarkko Sakkinen <jarkko@kernel.org> wrote:
> > On Tue, Nov 17, 2026 at 02:35:04PM +0200, Jarkko Sakkinen wrote:
> > > I think this would be more feasible:
> > >
> > > if (current->flags & PF_IO_WORKER)
> > > return -EIO;
> > >
> > > if ((current->flags & PF_KTHREAD) && current->io_uring)
> > > return -EIO;
> > >
> > > I.e., block io_uring entirely.
>
> Hi Jarkko, thanks for the review.
>
> These checks do not fully block io_uring. With O_NONBLOCK set and a
> response ready, io_uring calls ->read() inline from the caller's own
> task, where neither PF_IO_WORKER nor PF_KTHREAD is set.
> loop_rw_iter() declines the inline attempt only when the file lacks
> O_NONBLOCK:
>
> if ((kiocb->ki_flags & IOCB_NOWAIT) &&
> !(kiocb->ki_filp->f_flags & O_NONBLOCK))
> return -EAGAIN;
>
> I built a kernel with both checks applied and the injected offset
> still reaches tpm_common_read():
>
> BUG: KASAN: slab-out-of-bounds in _copy_to_user+0x4b/0x70
> Read of size 16 at addr ffff88810c3455d2 by task python3/134
> Call Trace:
> _copy_to_user+0x4b/0x70
> tpm_common_read+0x1e6/0x360
> loop_rw_iter+0x235/0x5a0
> __io_read+0xc6e/0x11a0
> io_read+0x8a/0x180
>
> Reproducer:
> - open("/dev/tpm0", O_RDWR | O_NONBLOCK)
> - write() a command, then poll() until POLLIN
> - submit IORING_OP_READ with sqe->off = 0x1400, without IOSQE_ASYNC
> (this is how tpm2-tss opens the device O_RDWR | O_NONBLOCK).
>
> Checking current->io_uring alone would catch the inline path, but
> then a process that uses io_uring for anything else would also lose
> plain read()/write() on the device.
>
> For v2 I propose:
>
> 1. The read position fix, with your review comments applied.
> 2. stream_open() instead of nonseekable_open(), on top of 1. With
> FMODE_STREAM both the VFS and io_uring pass a NULL offset to the
> driver. This follows c5bf68fe0c86 ("*: convert stream-like files
> from nonseekable_open -> stream_open").
> 3. A kselftest: lseek() and pread() fail with -ESPIPE, chunked reads
> of a TPM2_GetCapability(TPM_PT_FAMILY_INDICATOR) response match a
> one-shot read, and an io_uring read with an explicit sqe->off
> returns the start of the response.
>
> Br,
> Rustam
I wrote that out of my memory. I did not expect to be exactly out.
Block uring.
Br, Jarkko
next prev parent reply other threads:[~2026-11-18 14:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 9:02 [PATCH] tpm: Reject reads outside the response buffer Jaewon Yang
2026-07-11 17:08 ` Jarkko Sakkinen
2026-07-11 18:58 ` Linus Torvalds
2026-07-12 17:11 ` [PATCH v2] tpm: Make the TPM character devices non-seekable Jaewon Yang
2026-07-12 19:54 ` Linus Torvalds
2026-07-18 18:13 ` Jarkko Sakkinen
2026-07-18 18:20 ` Jarkko Sakkinen
2026-11-17 10:48 ` [PATCH] tpm: track the response read position internally, not via the file offset Rustam Mustafin
2026-11-17 10:59 ` Jarkko Sakkinen
2026-11-17 12:35 ` Jarkko Sakkinen
2026-11-17 12:38 ` Jarkko Sakkinen
2026-11-18 9:55 ` Rustam Mustafin
[not found] ` <CAG6=z5sxUo1x6mpotkNZXk=nQYvD2AyMLSDhzD3B3kqxJ1=iaw@mail.gmail.com>
2026-11-18 14:33 ` Jarkko Sakkinen [this message]
2026-11-19 17:49 ` Rustam Mustafin
2026-11-19 18:13 ` Jarkko Sakkinen
2026-11-20 12:20 ` Rustam Mustafin
2026-07-18 18:17 ` [PATCH] tpm: Reject reads outside the response buffer Jarkko Sakkinen
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=av23L5HBpy2gbm3m@kernel.org \
--to=jarkko@kernel.org \
--cc=jgg@ziepe.ca \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterhuewe@gmx.de \
--cc=rmustafin@cloudlinux.com \
--cc=stable@vger.kernel.org \
--cc=tadeusz.struk@intel.com \
--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 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.