diff options
| author | Jarkko Sakkinen <jarkko@kernel.org> | 2025-10-18 13:30:36 +0300 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2026-01-19 13:09:48 +0100 |
| commit | 3fd7df4636d8fd5e3592371967a5941204368936 (patch) | |
| tree | 9c9990c98197a51e6be5859b7feefc2589c0dac4 /security | |
| parent | 8a69b95bc8c47995ed6357769f19e8d9fb8b0825 (diff) | |
| download | linux-3fd7df4636d8fd5e3592371967a5941204368936.tar.gz linux-3fd7df4636d8fd5e3592371967a5941204368936.tar.bz2 linux-3fd7df4636d8fd5e3592371967a5941204368936.zip | |
KEYS: trusted: Fix a memory leak in tpm2_load_cmd
commit 62cd5d480b9762ce70d720a81fa5b373052ae05f upstream.
'tpm2_load_cmd' allocates a tempoary blob indirectly via 'tpm2_key_decode'
but it is not freed in the failure paths. Address this by wrapping the blob
into with a cleanup helper.
Cc: stable@vger.kernel.org # v5.13+
Fixes: f2219745250f ("security: keys: trusted: use ASN.1 TPM2 key format for the blobs")
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'security')
| -rw-r--r-- | security/keys/trusted-keys/trusted_tpm2.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trusted-keys/trusted_tpm2.c index ea277c55a38d..190dd32f8113 100644 --- a/security/keys/trusted-keys/trusted_tpm2.c +++ b/security/keys/trusted-keys/trusted_tpm2.c @@ -375,6 +375,7 @@ static int tpm2_load_cmd(struct tpm_chip *chip, struct trusted_key_options *options, u32 *blob_handle) { + u8 *blob_ref __free(kfree) = NULL; struct tpm_buf buf; unsigned int private_len; unsigned int public_len; @@ -388,6 +389,9 @@ static int tpm2_load_cmd(struct tpm_chip *chip, /* old form */ blob = payload->blob; payload->old_format = 1; + } else { + /* Bind for cleanup: */ + blob_ref = blob; } /* new format carries keyhandle but old format doesn't */ @@ -446,8 +450,6 @@ static int tpm2_load_cmd(struct tpm_chip *chip, (__be32 *) &buf.data[TPM_HEADER_SIZE]); out: - if (blob != payload->blob) - kfree(blob); tpm_buf_destroy(&buf); if (rc > 0) |
