linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan McDowell <noodles@earth.li>
To: linux-integrity@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Jarkko Sakkinen <jarkko@kernel.org>,
	Peter Huewe <peterhuewe@gmx.de>, Jason Gunthorpe <jgg@ziepe.ca>
Subject: [RFC] [PATCH] tpm: Clean up TPM space after command failure
Date: Wed, 14 Aug 2024 17:19:08 +0100	[thread overview]
Message-ID: <ZrzY_LWIXABkqd-S@earth.li> (raw)

We've been seeing a problem where TPM commands time out, which if
they're the last command before the TPM device is closed causes a leak
of transient handles. They can be seen and cleaned up (with a flush
context) if the /dev/tpm0 device is used instead of /dev/tpmrm0, but it
seems like we should be doing this automatically on the transmit error
path. Patch below adds a tpm2_flush_space on error to avoid this.

Does this seem reasonable? The other query is whether tpm2_del_space
should cleanup the contexts as well, rather than just the sessions.

(Obviously in an ideal world we wouldn't see the timeouts at all, and
I'm still trying to work on getting to the bottom of these, which are
generally infrequent, but happening enough across our fleet that we were
able to observe this handle leak.)

From: Jonathan McDowell <noodles@meta.com>

tpm_dev_transmit prepares the TPM space before attempting command
transmission. However if the command fails no rollback of this
preparation is done. This can result in transient handles being leaked
if the device is subsequently closed with no further commands performed.

Fix this by flushing the space in the event of command transmission
failure.

Signed-off-by: Jonathan McDowell <noodles@meta.com>

---
 drivers/char/tpm/tpm-dev-common.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/char/tpm/tpm-dev-common.c b/drivers/char/tpm/tpm-dev-common.c
index 30b4c288c1bb..c3fbbf4d3db7 100644
--- a/drivers/char/tpm/tpm-dev-common.c
+++ b/drivers/char/tpm/tpm-dev-common.c
@@ -47,6 +47,8 @@ static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space,
 
 	if (!ret)
 		ret = tpm2_commit_space(chip, space, buf, &len);
+	else
+		tpm2_flush_space(chip);
 
 out_rc:
 	return ret ? ret : len;
-- 
2.46.0


             reply	other threads:[~2024-08-14 16:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-14 16:19 Jonathan McDowell [this message]
2024-08-15 18:44 ` [RFC] [PATCH] tpm: Clean up TPM space after command failure Jarkko Sakkinen
2024-08-16 11:55   ` [PATCH v2] " Jonathan McDowell
2024-08-16 13:44     ` 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=ZrzY_LWIXABkqd-S@earth.li \
    --to=noodles@earth.li \
    --cc=jarkko@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    /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;
as well as URLs for NNTP newsgroup(s).