Skip to content

Commit e3aaebc

Browse files
u1f35cjarkkojs
authored andcommitted
tpm: Clean up TPM space after command failure
tpm_dev_transmit prepares the TPM space before attempting command transmission. However if the command fails no rollback of this preparation is done. This can result in transient handles being leaked if the device is subsequently closed with no further commands performed. Fix this by flushing the space in the event of command transmission failure. Fixes: 745b361 ("tpm: infrastructure for TPM spaces") Signed-off-by: Jonathan McDowell <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent 2f27fce commit e3aaebc

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

drivers/char/tpm/tpm-dev-common.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space,
4747

4848
if (!ret)
4949
ret = tpm2_commit_space(chip, space, buf, &len);
50+
else
51+
tpm2_flush_space(chip);
5052

5153
out_rc:
5254
return ret ? ret : len;

drivers/char/tpm/tpm2-space.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ void tpm2_flush_space(struct tpm_chip *chip)
169169
struct tpm_space *space = &chip->work_space;
170170
int i;
171171

172+
if (!space)
173+
return;
174+
172175
for (i = 0; i < ARRAY_SIZE(space->context_tbl); i++)
173176
if (space->context_tbl[i] && ~space->context_tbl[i])
174177
tpm2_flush_context(chip, space->context_tbl[i]);

0 commit comments

Comments
 (0)