tpm: Check the bios_dir entry for NULL before accessing it
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Wed, 16 Nov 2016 13:56:13 +0000 (08:56 -0500)
committerJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Sun, 27 Nov 2016 23:31:32 +0000 (01:31 +0200)
Check the bios_dir entry for NULL before accessing it. Currently
this crashes the driver when a TPM 2 is attached and the entries
are NULL.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
drivers/char/tpm/tpm_eventlog.c

index 8ee4ea1..34f0921 100644 (file)
@@ -449,10 +449,12 @@ void tpm_bios_log_teardown(struct tpm_chip *chip)
         * This design ensures that open() either safely gets kref or fails.
         */
        for (i = (TPM_NUM_EVENT_LOG_FILES - 1); i >= 0; i--) {
-               inode = d_inode(chip->bios_dir[i]);
-               inode_lock(inode);
-               inode->i_private = NULL;
-               inode_unlock(inode);
-               securityfs_remove(chip->bios_dir[i]);
+               if (chip->bios_dir[i]) {
+                       inode = d_inode(chip->bios_dir[i]);
+                       inode_lock(inode);
+                       inode->i_private = NULL;
+                       inode_unlock(inode);
+                       securityfs_remove(chip->bios_dir[i]);
+               }
        }
 }