Skip to content

Commit fb5abce

Browse files
James Bottomleyjarkkojs
authored andcommitted
tpm: use try_get_ops() in tpm-space.c
As part of the series conversion to remove nested TPM operations: https://lore.kernel.org/all/[email protected]/ exposure of the chip->tpm_mutex was removed from much of the upper level code. In this conversion, tpm2_del_space() was missed. This didn't matter much because it's usually called closely after a converted operation, so there's only a very tiny race window where the chip can be removed before the space flushing is done which causes a NULL deref on the mutex. However, there are reports of this window being hit in practice, so fix this by converting tpm2_del_space() to use tpm_try_get_ops(), which performs all the teardown checks before acquring the mutex. Cc: [email protected] # 5.4.x Signed-off-by: James Bottomley <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent 590bfb5 commit fb5abce

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/char/tpm/tpm2-space.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ int tpm2_init_space(struct tpm_space *space, unsigned int buf_size)
5858

5959
void tpm2_del_space(struct tpm_chip *chip, struct tpm_space *space)
6060
{
61-
mutex_lock(&chip->tpm_mutex);
62-
if (!tpm_chip_start(chip)) {
61+
62+
if (tpm_try_get_ops(chip) == 0) {
6363
tpm2_flush_sessions(chip, space);
64-
tpm_chip_stop(chip);
64+
tpm_put_ops(chip);
6565
}
66-
mutex_unlock(&chip->tpm_mutex);
66+
6767
kfree(space->context_buf);
6868
kfree(space->session_buf);
6969
}

0 commit comments

Comments
 (0)