From: Jarkko Sakkinen <jarkko@kernel.org>
To: Lino Sanfilippo <LinoSanfilippo@gmx.de>
Cc: peterhuewe@gmx.de, jgg@ziepe.ca, stefanb@linux.vnet.ibm.com,
linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org,
Lino Sanfilippo <l.sanfilippo@kunbus.com>
Subject: Re: [PATCH v2 3/3] tpm: in tpm2_del_space check if ops pointer is still valid
Date: Wed, 3 Feb 2021 03:17:07 +0200 [thread overview]
Message-ID: <YBn5kwEIoggc71xY@kernel.org> (raw)
In-Reply-To: <1612303743-29017-4-git-send-email-LinoSanfilippo@gmx.de>
On Tue, Feb 02, 2021 at 11:09:03PM +0100, Lino Sanfilippo wrote:
> From: Lino Sanfilippo <l.sanfilippo@kunbus.com>
>
> In tpm2_del_space() the sessions are flushed by means of the tpm_chip
> operations. However the concerning operations pointer my already be NULL at
~~
may
What is "concerniog operations"? Unfamiliar term. Maybe just consistently
se chip->ops? Now you have also "tpm_chip operations" and chip->ops, in
addition to "concerning operations" in one paragraph commit message.
> this time in case that the chip has been unregistered (see
> tpm_chip_unregister() which calls tpm_del_char_device() which sets
> chip->ops to NULL).
> Before accessing chip->ops check if it is still valid. Skip flushing
> the sessions in this case.
>
> Signed-off-by: Lino Sanfilippo <l.sanfilippo@kunbus.com>
Instead of cross referencing please describe the scenario (i.e.
the sequence of operations) of failure.
Fixes tag is also missing.
> ---
> drivers/char/tpm/tpm2-space.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c
> index 784b8b3..9a29a40 100644
> --- a/drivers/char/tpm/tpm2-space.c
> +++ b/drivers/char/tpm/tpm2-space.c
> @@ -58,12 +58,17 @@ int tpm2_init_space(struct tpm_space *space, unsigned int buf_size)
>
> void tpm2_del_space(struct tpm_chip *chip, struct tpm_space *space)
> {
> - mutex_lock(&chip->tpm_mutex);
> - if (!tpm_chip_start(chip)) {
> - tpm2_flush_sessions(chip, space);
> - tpm_chip_stop(chip);
> + down_read(&chip->ops_sem);
> + if (chip->ops) {
> + mutex_lock(&chip->tpm_mutex);
> + if (!tpm_chip_start(chip)) {
> + tpm2_flush_sessions(chip, space);
> + tpm_chip_stop(chip);
> + }
> + mutex_unlock(&chip->tpm_mutex);
> }
> - mutex_unlock(&chip->tpm_mutex);
> + up_read(&chip->ops_sem);
> +
> kfree(space->context_buf);
> kfree(space->session_buf);
> }
> --
> 2.7.4
>
/Jarkko
next prev parent reply other threads:[~2021-02-03 1:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-02 22:09 [PATCH v2 0/3] TPM fixes Lino Sanfilippo
2021-02-02 22:09 ` [PATCH v2 1/3] tpm: fix reference counting for struct tpm_chip Lino Sanfilippo
2021-02-03 1:09 ` Jarkko Sakkinen
2021-02-03 14:06 ` Lino Sanfilippo
2021-02-03 21:43 ` Jarkko Sakkinen
2021-02-02 22:09 ` [PATCH v2 2/3] tpm: Provide a function tpm_chip_free() to free tpm chips Lino Sanfilippo
2021-02-03 1:28 ` Jarkko Sakkinen
2021-02-03 14:09 ` Lino Sanfilippo
2021-02-02 22:09 ` [PATCH v2 3/3] tpm: in tpm2_del_space check if ops pointer is still valid Lino Sanfilippo
2021-02-03 1:17 ` Jarkko Sakkinen [this message]
2021-02-03 14:22 ` Lino Sanfilippo
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=YBn5kwEIoggc71xY@kernel.org \
--to=jarkko@kernel.org \
--cc=LinoSanfilippo@gmx.de \
--cc=jgg@ziepe.ca \
--cc=l.sanfilippo@kunbus.com \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterhuewe@gmx.de \
--cc=stefanb@linux.vnet.ibm.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.