Commit eabad7ba authored by Lino Sanfilippo's avatar Lino Sanfilippo Committed by Jarkko Sakkinen
Browse files

tpm: fix potential NULL pointer access in tpm_del_char_device



Some SPI controller drivers unregister the controller in the shutdown
handler (e.g. BCM2835). If such a controller is used with a TPM 2 slave
chip->ops may be accessed when it is already NULL:

At system shutdown the pre-shutdown handler tpm_class_shutdown() shuts down
TPM 2 and sets chip->ops to NULL. Then at SPI controller unregistration
tpm_tis_spi_remove() is called and eventually calls tpm_del_char_device()
which tries to shut down TPM 2 again. Thereby it accesses chip->ops again:
(tpm_del_char_device calls tpm_chip_start which calls tpm_clk_enable which
calls chip->ops->clk_enable).

Avoid the NULL pointer access by testing if chip->ops is valid and skipping
the TPM 2 shutdown procedure in case it is NULL.

Cc: stable@vger.kernel.org
Signed-off-by: default avatarLino Sanfilippo <LinoSanfilippo@gmx.de>
Fixes: 39d0099f ("powerpc/pseries: Add shutdown() to vio_driver and vio_bus")
Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
Tested-by: default avatarStefan Berger <stefanb@linux.ibm.com>
Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
parent 0aa69878
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -474,6 +474,13 @@ static void tpm_del_char_device(struct tpm_chip *chip)

	/* Make the driver uncallable. */
	down_write(&chip->ops_sem);

	/*
	 * 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);
@@ -481,6 +488,7 @@ static void tpm_del_char_device(struct tpm_chip *chip)
			}
		}
		chip->ops = NULL;
	}
	up_write(&chip->ops_sem);
}