mirror of https://github.com/torvalds/linux.git
Hi,
This pull request includes couple of updates for trusted keys:
1. Remove duplicate 'tpm2_hash_map' and use the one in the drive via new
function 'tpm2_find_hash_alg'.
2. Fix a memory leak on failure paths of 'tpm2_load_cmd'.
BR, Jarkko
-----BEGIN PGP SIGNATURE-----
iHUEABYKAB0WIQRE6pSOnaBC00OEHEIaerohdGur0gUCaStg0gAKCRAaerohdGur
0gdUAQCit+7Vwpc2oArfJoCFI1ILhLArPSUlBI0ZUB+BpBNZbQD/T1TwdT3Ytekf
jwkKrJbavuFQ+u5pUb2WShQJ7WOcBg4=
=jor5
-----END PGP SIGNATURE-----
Merge tag 'keys-trusted-next-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd
Pull trusted key updates from Jarkko Sakkinen:
- Remove duplicate 'tpm2_hash_map' in favor of 'tpm2_find_hash_alg()'
- Fix a memory leak on failure paths of 'tpm2_load_cmd'
* tag 'keys-trusted-next-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd:
KEYS: trusted: Fix a memory leak in tpm2_load_cmd
KEYS: trusted: Replace a redundant instance of tpm2_hash_map
This commit is contained in:
commit
7fc2cd2e4b
|
|
@ -18,7 +18,7 @@ static bool disable_pcr_integrity;
|
||||||
module_param(disable_pcr_integrity, bool, 0444);
|
module_param(disable_pcr_integrity, bool, 0444);
|
||||||
MODULE_PARM_DESC(disable_pcr_integrity, "Disable integrity protection of TPM2_PCR_Extend");
|
MODULE_PARM_DESC(disable_pcr_integrity, "Disable integrity protection of TPM2_PCR_Extend");
|
||||||
|
|
||||||
static struct tpm2_hash tpm2_hash_map[] = {
|
struct tpm2_hash tpm2_hash_map[] = {
|
||||||
{HASH_ALGO_SHA1, TPM_ALG_SHA1},
|
{HASH_ALGO_SHA1, TPM_ALG_SHA1},
|
||||||
{HASH_ALGO_SHA256, TPM_ALG_SHA256},
|
{HASH_ALGO_SHA256, TPM_ALG_SHA256},
|
||||||
{HASH_ALGO_SHA384, TPM_ALG_SHA384},
|
{HASH_ALGO_SHA384, TPM_ALG_SHA384},
|
||||||
|
|
@ -26,6 +26,18 @@ static struct tpm2_hash tpm2_hash_map[] = {
|
||||||
{HASH_ALGO_SM3_256, TPM_ALG_SM3_256},
|
{HASH_ALGO_SM3_256, TPM_ALG_SM3_256},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int tpm2_find_hash_alg(unsigned int crypto_id)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_SIZE(tpm2_hash_map); i++)
|
||||||
|
if (crypto_id == tpm2_hash_map[i].crypto_id)
|
||||||
|
return tpm2_hash_map[i].tpm_id;
|
||||||
|
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(tpm2_find_hash_alg);
|
||||||
|
|
||||||
int tpm2_get_timeouts(struct tpm_chip *chip)
|
int tpm2_get_timeouts(struct tpm_chip *chip)
|
||||||
{
|
{
|
||||||
chip->timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A);
|
chip->timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A);
|
||||||
|
|
|
||||||
|
|
@ -473,6 +473,7 @@ extern int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
|
||||||
extern int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max);
|
extern int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max);
|
||||||
extern struct tpm_chip *tpm_default_chip(void);
|
extern struct tpm_chip *tpm_default_chip(void);
|
||||||
void tpm2_flush_context(struct tpm_chip *chip, u32 handle);
|
void tpm2_flush_context(struct tpm_chip *chip, u32 handle);
|
||||||
|
int tpm2_find_hash_alg(unsigned int crypto_id);
|
||||||
|
|
||||||
static inline void tpm_buf_append_empty_auth(struct tpm_buf *buf, u32 handle)
|
static inline void tpm_buf_append_empty_auth(struct tpm_buf *buf, u32 handle)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -18,14 +18,6 @@
|
||||||
|
|
||||||
#include "tpm2key.asn1.h"
|
#include "tpm2key.asn1.h"
|
||||||
|
|
||||||
static struct tpm2_hash tpm2_hash_map[] = {
|
|
||||||
{HASH_ALGO_SHA1, TPM_ALG_SHA1},
|
|
||||||
{HASH_ALGO_SHA256, TPM_ALG_SHA256},
|
|
||||||
{HASH_ALGO_SHA384, TPM_ALG_SHA384},
|
|
||||||
{HASH_ALGO_SHA512, TPM_ALG_SHA512},
|
|
||||||
{HASH_ALGO_SM3_256, TPM_ALG_SM3_256},
|
|
||||||
};
|
|
||||||
|
|
||||||
static u32 tpm2key_oid[] = { 2, 23, 133, 10, 1, 5 };
|
static u32 tpm2key_oid[] = { 2, 23, 133, 10, 1, 5 };
|
||||||
|
|
||||||
static int tpm2_key_encode(struct trusted_key_payload *payload,
|
static int tpm2_key_encode(struct trusted_key_payload *payload,
|
||||||
|
|
@ -244,20 +236,13 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
|
||||||
off_t offset = TPM_HEADER_SIZE;
|
off_t offset = TPM_HEADER_SIZE;
|
||||||
struct tpm_buf buf, sized;
|
struct tpm_buf buf, sized;
|
||||||
int blob_len = 0;
|
int blob_len = 0;
|
||||||
u32 hash;
|
int hash;
|
||||||
u32 flags;
|
u32 flags;
|
||||||
int i;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(tpm2_hash_map); i++) {
|
hash = tpm2_find_hash_alg(options->hash);
|
||||||
if (options->hash == tpm2_hash_map[i].crypto_id) {
|
if (hash < 0)
|
||||||
hash = tpm2_hash_map[i].tpm_id;
|
return hash;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == ARRAY_SIZE(tpm2_hash_map))
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
if (!options->keyhandle)
|
if (!options->keyhandle)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
@ -387,6 +372,7 @@ static int tpm2_load_cmd(struct tpm_chip *chip,
|
||||||
struct trusted_key_options *options,
|
struct trusted_key_options *options,
|
||||||
u32 *blob_handle)
|
u32 *blob_handle)
|
||||||
{
|
{
|
||||||
|
u8 *blob_ref __free(kfree) = NULL;
|
||||||
struct tpm_buf buf;
|
struct tpm_buf buf;
|
||||||
unsigned int private_len;
|
unsigned int private_len;
|
||||||
unsigned int public_len;
|
unsigned int public_len;
|
||||||
|
|
@ -400,6 +386,9 @@ static int tpm2_load_cmd(struct tpm_chip *chip,
|
||||||
/* old form */
|
/* old form */
|
||||||
blob = payload->blob;
|
blob = payload->blob;
|
||||||
payload->old_format = 1;
|
payload->old_format = 1;
|
||||||
|
} else {
|
||||||
|
/* Bind for cleanup: */
|
||||||
|
blob_ref = blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* new format carries keyhandle but old format doesn't */
|
/* new format carries keyhandle but old format doesn't */
|
||||||
|
|
@ -464,8 +453,6 @@ static int tpm2_load_cmd(struct tpm_chip *chip,
|
||||||
(__be32 *) &buf.data[TPM_HEADER_SIZE]);
|
(__be32 *) &buf.data[TPM_HEADER_SIZE]);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (blob != payload->blob)
|
|
||||||
kfree(blob);
|
|
||||||
tpm_buf_destroy(&buf);
|
tpm_buf_destroy(&buf);
|
||||||
|
|
||||||
if (rc > 0)
|
if (rc > 0)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue