From: Tyrel Datwyler <tyreld@linux.ibm.com>
To: Stefan Berger <stefanb@linux.ibm.com>, Jason Gunthorpe <jgg@ziepe.ca>
Cc: jarkko@kernel.org, peterhuewe@gmx.de,
linux-integrity@vger.kernel.org, Korrapati.Likhitha@ibm.com,
pavrampu@in.ibm.com, linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org, gcwilson@us.ibm.com,
linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH] tpm: Fix kexec crash due to access to ops NULL pointer (powerpc)
Date: Mon, 20 Dec 2021 17:37:36 -0800 [thread overview]
Message-ID: <bad84f8a-9e07-0920-5c07-475e30e710e9@linux.ibm.com> (raw)
In-Reply-To: <f80e33d2-948d-f885-b063-245eb37de8c1@linux.ibm.com>
On 12/20/21 5:31 PM, Stefan Berger wrote:
>
> On 12/20/21 20:13, Jason Gunthorpe wrote:
>> On Mon, Dec 20, 2021 at 08:05:58PM -0500, Stefan Berger wrote:
>>
>>> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
>>> index ddaeceb7e109..4cb908349b31 100644
>>> +++ b/drivers/char/tpm/tpm-chip.c
>>> @@ -473,15 +473,8 @@ static void tpm_del_char_device(struct tpm_chip *chip)
>>> mutex_unlock(&idr_lock);
>>>
>>> /* Make the driver uncallable. */
>>> - down_write(&chip->ops_sem);
>>> - if (chip->flags & TPM_CHIP_FLAG_TPM2) {
>>> - if (!tpm_chip_start(chip)) {
>>> - tpm2_shutdown(chip, TPM2_SU_CLEAR);
>>> - tpm_chip_stop(chip);
>>> - }
>>> - }
>>> - chip->ops = NULL;
>>> - up_write(&chip->ops_sem);
>>> + if (chip->ops)
>> ops cannot be read without locking
>
> This here could be an alternative:
I still think code de-duplication is a good thing. Maybe combine the two
approaches. Call tpm_class_shutdown from tpm_del_char_device and add a chip->ops
check in tpm_class_shutdown to ensure we only do the shutdown when chip->ops is
valid.
-Tyrel
>
> diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
> index ddaeceb7e109..7772b475ebc0 100644
> --- a/drivers/char/tpm/tpm-chip.c
> +++ b/drivers/char/tpm/tpm-chip.c
> @@ -474,7 +474,7 @@ static void tpm_del_char_device(struct tpm_chip *chip)
>
> /* Make the driver uncallable. */
> down_write(&chip->ops_sem);
> - if (chip->flags & TPM_CHIP_FLAG_TPM2) {
> + if (chip->ops && chip->flags & TPM_CHIP_FLAG_TPM2) {
> if (!tpm_chip_start(chip)) {
> tpm2_shutdown(chip, TPM2_SU_CLEAR);
> tpm_chip_stop(chip);
>
> Stefan
>
>
>>
>> Jason
next prev parent reply other threads:[~2021-12-21 1:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-12 1:28 [PATCH] tpm: Fix kexec crash due to access to ops NULL pointer (powerpc) Stefan Berger
2021-12-20 5:17 ` Sachin Sant
2021-12-21 0:39 ` Tyrel Datwyler
2021-12-21 1:05 ` Stefan Berger
2021-12-21 1:13 ` Jason Gunthorpe
2021-12-21 1:31 ` Stefan Berger
2021-12-21 1:37 ` Tyrel Datwyler [this message]
2021-12-21 1:34 ` Tyrel Datwyler
2021-12-21 8:47 ` Jarkko Sakkinen
2021-12-21 14:01 ` Stefan Berger
2021-12-21 14:17 ` Stefan Berger
2021-12-29 0:10 ` 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=bad84f8a-9e07-0920-5c07-475e30e710e9@linux.ibm.com \
--to=tyreld@linux.ibm.com \
--cc=Korrapati.Likhitha@ibm.com \
--cc=gcwilson@us.ibm.com \
--cc=jarkko@kernel.org \
--cc=jgg@ziepe.ca \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=pavrampu@in.ibm.com \
--cc=peterhuewe@gmx.de \
--cc=stefanb@linux.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 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).