linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tpm: Fix TPM 1.2 Shutdown sequence to prevent future TPM operations
@ 2019-07-11 16:29 Douglas Anderson
  2019-07-11 16:39 ` Jason Gunthorpe
  2019-07-11 18:34 ` Jarkko Sakkinen
  0 siblings, 2 replies; 26+ messages in thread
From: Douglas Anderson @ 2019-07-11 16:29 UTC (permalink / raw)
  To: stable
  Cc: groeck, gregkh, sukhomlinov, jarkko.sakkinen, Douglas Anderson,
	Arnd Bergmann, Peter Huewe, linux-kernel, Jason Gunthorpe,
	linux-integrity

From: Vadim Sukhomlinov <sukhomlinov@google.com>

commit db4d8cb9c9f2af71c4d087817160d866ed572cc9 upstream.

TPM 2.0 Shutdown involve sending TPM2_Shutdown to TPM chip and disabling
future TPM operations. TPM 1.2 behavior was different, future TPM
operations weren't disabled, causing rare issues. This patch ensures
that future TPM operations are disabled.

Fixes: d1bd4a792d39 ("tpm: Issue a TPM2_Shutdown for TPM2 devices.")
Cc: stable@vger.kernel.org
Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com>
[dianders: resolved merge conflicts with mainline]
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
This is the backport of the patch referenced above to 4.19 as was done
in Chrome OS.  See <https://crrev.com/c/1495114> for details.  It
presumably applies to some older kernels.  NOTE that the problem
itself has existed for a long time, but continuing to backport this
exact solution to super old kernels is out of scope for me.  For those
truly interested feel free to reference the past discussion [1].

Reason for backport: mainline has commit a3fbfae82b4c ("tpm: take TPM
chip power gating out of tpm_transmit()") and commit 719b7d81f204
("tpm: introduce tpm_chip_start() and tpm_chip_stop()") and it didn't
seem like a good idea to backport 17 patches to avoid the conflict.

[1] https://lkml.kernel.org/r/CAD=FV=UoSV9LKOTMuXKRfgFir+7_qPkuhSLN6XJEKPiRPuJJwg@mail.gmail.com

 drivers/char/tpm/tpm-chip.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index 46caadca916a..f784b6fd93b4 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -187,12 +187,11 @@ static int tpm_class_shutdown(struct device *dev)
 {
 	struct tpm_chip *chip = container_of(dev, struct tpm_chip, dev);
 
-	if (chip->flags & TPM_CHIP_FLAG_TPM2) {
-		down_write(&chip->ops_sem);
+	down_write(&chip->ops_sem);
+	if (chip->flags & TPM_CHIP_FLAG_TPM2)
 		tpm2_shutdown(chip, TPM2_SU_CLEAR);
-		chip->ops = NULL;
-		up_write(&chip->ops_sem);
-	}
+	chip->ops = NULL;
+	up_write(&chip->ops_sem);
 
 	return 0;
 }
-- 
2.22.0.410.gd8fdbe21b5-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread
* [PATCH] tpm: Fix TPM 1.2 Shutdown sequence to prevent future TPM operations
@ 2019-06-10 22:01 Douglas Anderson
  2019-06-12 19:16 ` Jarkko Sakkinen
  0 siblings, 1 reply; 26+ messages in thread
From: Douglas Anderson @ 2019-06-10 22:01 UTC (permalink / raw)
  To: Jarkko Sakkinen, Peter Huewe
  Cc: groeck, Vadim Sukhomlinov, apronin, mka, swboyd,
	Douglas Anderson, Arnd Bergmann, linux-kernel, Jason Gunthorpe,
	Greg Kroah-Hartman, linux-integrity

From: Vadim Sukhomlinov <sukhomlinov@google.com>

TPM 2.0 Shutdown involve sending TPM2_Shutdown to TPM chip and disabling
future TPM operations. TPM 1.2 behavior was different, future TPM
operations weren't disabled, causing rare issues. This patch ensures
that future TPM operations are disabled.

Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com>
[dianders: resolved merge conflicts with mainline]
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

 drivers/char/tpm/tpm-chip.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index 8804c9e916fd..f566fa8bf704 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -294,15 +294,15 @@ static int tpm_class_shutdown(struct device *dev)
 {
 	struct tpm_chip *chip = container_of(dev, struct tpm_chip, dev);
 
+	down_write(&chip->ops_sem);
 	if (chip->flags & TPM_CHIP_FLAG_TPM2) {
-		down_write(&chip->ops_sem);
 		if (!tpm_chip_start(chip)) {
 			tpm2_shutdown(chip, TPM2_SU_CLEAR);
 			tpm_chip_stop(chip);
 		}
-		chip->ops = NULL;
-		up_write(&chip->ops_sem);
 	}
+	chip->ops = NULL;
+	up_write(&chip->ops_sem);
 
 	return 0;
 }
-- 
2.22.0.rc2.383.gf4fbbf30c2-goog


^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2019-08-05 21:05 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-11 16:29 [PATCH] tpm: Fix TPM 1.2 Shutdown sequence to prevent future TPM operations Douglas Anderson
2019-07-11 16:39 ` Jason Gunthorpe
2019-07-11 16:41   ` Doug Anderson
2019-07-11 17:04   ` Greg KH
2019-07-11 17:17     ` Jason Gunthorpe
2019-07-11 17:26       ` Greg KH
2019-07-11 17:28         ` Doug Anderson
2019-07-12 11:50           ` Greg KH
2019-07-12 15:00             ` Doug Anderson
2019-07-12 15:27               ` Greg KH
2019-08-05 21:05                 ` Jarkko Sakkinen
2019-07-12 15:47               ` Jarkko Sakkinen
2019-07-12 15:21             ` Jarkko Sakkinen
2019-07-11 18:35   ` Jarkko Sakkinen
2019-07-11 19:43     ` Jarkko Sakkinen
2019-07-11 19:46       ` Jason Gunthorpe
2019-07-12  3:31         ` Jarkko Sakkinen
2019-07-12  3:35           ` Jarkko Sakkinen
2019-07-12 11:58             ` Jason Gunthorpe
2019-07-11 19:55       ` Doug Anderson
2019-07-11 18:34 ` Jarkko Sakkinen
  -- strict thread matches above, loose matches on Subject: below --
2019-06-10 22:01 Douglas Anderson
2019-06-12 19:16 ` Jarkko Sakkinen
2019-06-13 13:58   ` Jarkko Sakkinen
2019-06-13 15:20     ` Doug Anderson
2019-06-14 15:15       ` Jarkko Sakkinen

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).