Thread (8 messages) 8 messages, 3 authors, 2021-12-29

Re: [PATCH v2] tpm: fix potential NULL pointer access in tpm_del_char_device

From: Lino Sanfilippo <LinoSanfilippo@gmx.de>
Date: 2021-12-22 06:56:39
Also in: linux-integrity, lkml

Hi Stefan,


On 22.12.21 at 05:53, Stefan Berger wrote:
quoted
  drivers/char/tpm/tpm-chip.c | 16 +++++++++++-----
  1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index ddaeceb7e109..7960da490e72 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -474,13 +474,19 @@ 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 (!tpm_chip_start(chip)) {
-            tpm2_shutdown(chip, TPM2_SU_CLEAR);
-            tpm_chip_stop(chip);
+    /* Check if chip->ops is still valid: In case that the controller
+     * drivers shutdown handler unregisters the controller in its
+     * shutdown handler we are called twice and chip->ops to NULL.
+     */
+    if (chip->ops) {
+        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;
      }
-    chip->ops = NULL;
      up_write(&chip->ops_sem);
  }
 
base-commit: a7904a538933c525096ca2ccde1e60d0ee62c08e

Fixes: 39d0099f9439 ("powerpc/pseries: Add shutdown() to vio_driver and vio_bus")

Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>

Tested-by: Stefan Berger <stefanb@linux.ibm.com>
Thanks a lot for testing this.

Best regards,
Lino
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help