From: "Jarkko Sakkinen" <jarkko@kernel.org>
To: "Jonathan McDowell" <noodles@earth.li>,
"Peter Huewe" <peterhuewe@gmx.de>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
"James Bottomley" <James.Bottomley@hansenpartnership.com>,
<linux-integrity@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] tpm: Clean up TPM space after command failure
Date: Fri, 16 Aug 2024 16:44:01 +0300 [thread overview]
Message-ID: <D3HDPTAXDU8P.5CUQ1ECMIG2X@kernel.org> (raw)
In-Reply-To: <Zr8-QijwOpDLkol3@earth.li>
On Fri Aug 16, 2024 at 2:55 PM EEST, Jonathan McDowell wrote:
> 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.
>
> Fixes: 745b361e989a ("tpm: infrastructure for TPM spaces")
> Signed-off-by: Jonathan McDowell <noodles@meta.com>
> ---
> v2:
> - Add 'Fixes:'
> - Cc James as one of the original authors
> - Add space sanity check in tpm2_flush_space
>
> drivers/char/tpm/tpm-dev-common.c | 2 ++
> drivers/char/tpm/tpm2-space.c | 3 +++
> 2 files changed, 5 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;
> diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c
> index 4892d491da8d..25a66870c165 100644
> --- a/drivers/char/tpm/tpm2-space.c
> +++ b/drivers/char/tpm/tpm2-space.c
> @@ -169,6 +169,9 @@ void tpm2_flush_space(struct tpm_chip *chip)
> struct tpm_space *space = &chip->work_space;
> int i;
>
> + if (!space)
> + return;
> +
> for (i = 0; i < ARRAY_SIZE(space->context_tbl); i++)
> if (space->context_tbl[i] && ~space->context_tbl[i])
> tpm2_flush_context(chip, space->context_tbl[i]);
I'll pick this for 6.12: I think it is a legit fix but not worth of
disturbing the in-progress release cycle (which is going almost rc4
already):
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Thank you.
BR, Jarkko
prev parent reply other threads:[~2024-08-16 13:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-14 16:19 [RFC] [PATCH] tpm: Clean up TPM space after command failure Jonathan McDowell
2024-08-15 18:44 ` Jarkko Sakkinen
2024-08-16 11:55 ` [PATCH v2] " Jonathan McDowell
2024-08-16 13:44 ` Jarkko Sakkinen [this message]
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=D3HDPTAXDU8P.5CUQ1ECMIG2X@kernel.org \
--to=jarkko@kernel.org \
--cc=James.Bottomley@hansenpartnership.com \
--cc=jgg@ziepe.ca \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=noodles@earth.li \
--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).