]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
tpm: Clean up TPM space after command failure
authorJonathan McDowell <noodles@meta.com>
Fri, 16 Aug 2024 11:55:46 +0000 (12:55 +0100)
committerJarkko Sakkinen <jarkko@kernel.org>
Tue, 17 Sep 2024 15:56:36 +0000 (18:56 +0300)
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: 745b361e989a ("tpm: infrastructure for TPM spaces")
Signed-off-by: Jonathan McDowell <noodles@meta.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
drivers/char/tpm/tpm-dev-common.c
drivers/char/tpm/tpm2-space.c

index 30b4c288c1bbc3ba4dfedd38abf9663ace12e819..c3fbbf4d3db79a9b4523611aecc6772bcddffed8 100644 (file)
@@ -47,6 +47,8 @@ static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space,
 
        if (!ret)
                ret = tpm2_commit_space(chip, space, buf, &len);
+       else
+               tpm2_flush_space(chip);
 
 out_rc:
        return ret ? ret : len;
index 4892d491da8dae1aace910e0f2ff75136097a1d5..25a66870c165c503b58cbb45c4c6906583384bb9 100644 (file)
@@ -169,6 +169,9 @@ void tpm2_flush_space(struct tpm_chip *chip)
        struct tpm_space *space = &chip->work_space;
        int i;
 
+       if (!space)
+               return;
+
        for (i = 0; i < ARRAY_SIZE(space->context_tbl); i++)
                if (space->context_tbl[i] && ~space->context_tbl[i])
                        tpm2_flush_context(chip, space->context_tbl[i]);