Commit 24073043 authored by Roberto Sassu's avatar Roberto Sassu Committed by Jarkko Sakkinen

KEYS: trusted: explicitly use tpm_chip structure from tpm_default_chip()

When crypto agility support will be added to the TPM driver, users of the
driver have to retrieve the allocated banks from chip->allocated_banks and
use this information to prepare the array of tpm_digest structures to be
passed to tpm_pcr_extend().

This patch retrieves a tpm_chip pointer from tpm_default_chip() so that the
pointer can be used to prepare the array of tpm_digest structures.
Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
parent 901615cb
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
static const char hmac_alg[] = "hmac(sha1)"; static const char hmac_alg[] = "hmac(sha1)";
static const char hash_alg[] = "sha1"; static const char hash_alg[] = "sha1";
static struct tpm_chip *chip;
struct sdesc { struct sdesc {
struct shash_desc shash; struct shash_desc shash;
...@@ -362,7 +363,7 @@ int trusted_tpm_send(unsigned char *cmd, size_t buflen) ...@@ -362,7 +363,7 @@ int trusted_tpm_send(unsigned char *cmd, size_t buflen)
int rc; int rc;
dump_tpm_buf(cmd); dump_tpm_buf(cmd);
rc = tpm_send(NULL, cmd, buflen); rc = tpm_send(chip, cmd, buflen);
dump_tpm_buf(cmd); dump_tpm_buf(cmd);
if (rc > 0) if (rc > 0)
/* Can't return positive return codes values to keyctl */ /* Can't return positive return codes values to keyctl */
...@@ -384,10 +385,10 @@ static int pcrlock(const int pcrnum) ...@@ -384,10 +385,10 @@ static int pcrlock(const int pcrnum)
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
ret = tpm_get_random(NULL, hash, SHA1_DIGEST_SIZE); ret = tpm_get_random(chip, hash, SHA1_DIGEST_SIZE);
if (ret != SHA1_DIGEST_SIZE) if (ret != SHA1_DIGEST_SIZE)
return ret; return ret;
return tpm_pcr_extend(NULL, pcrnum, hash) ? -EINVAL : 0; return tpm_pcr_extend(chip, pcrnum, hash) ? -EINVAL : 0;
} }
/* /*
...@@ -400,7 +401,7 @@ static int osap(struct tpm_buf *tb, struct osapsess *s, ...@@ -400,7 +401,7 @@ static int osap(struct tpm_buf *tb, struct osapsess *s,
unsigned char ononce[TPM_NONCE_SIZE]; unsigned char ononce[TPM_NONCE_SIZE];
int ret; int ret;
ret = tpm_get_random(NULL, ononce, TPM_NONCE_SIZE); ret = tpm_get_random(chip, ononce, TPM_NONCE_SIZE);
if (ret != TPM_NONCE_SIZE) if (ret != TPM_NONCE_SIZE)
return ret; return ret;
...@@ -496,7 +497,7 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype, ...@@ -496,7 +497,7 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype,
if (ret < 0) if (ret < 0)
goto out; goto out;
ret = tpm_get_random(NULL, td->nonceodd, TPM_NONCE_SIZE); ret = tpm_get_random(chip, td->nonceodd, TPM_NONCE_SIZE);
if (ret != TPM_NONCE_SIZE) if (ret != TPM_NONCE_SIZE)
goto out; goto out;
ordinal = htonl(TPM_ORD_SEAL); ordinal = htonl(TPM_ORD_SEAL);
...@@ -606,7 +607,7 @@ static int tpm_unseal(struct tpm_buf *tb, ...@@ -606,7 +607,7 @@ static int tpm_unseal(struct tpm_buf *tb,
ordinal = htonl(TPM_ORD_UNSEAL); ordinal = htonl(TPM_ORD_UNSEAL);
keyhndl = htonl(SRKHANDLE); keyhndl = htonl(SRKHANDLE);
ret = tpm_get_random(NULL, nonceodd, TPM_NONCE_SIZE); ret = tpm_get_random(chip, nonceodd, TPM_NONCE_SIZE);
if (ret != TPM_NONCE_SIZE) { if (ret != TPM_NONCE_SIZE) {
pr_info("trusted_key: tpm_get_random failed (%d)\n", ret); pr_info("trusted_key: tpm_get_random failed (%d)\n", ret);
return ret; return ret;
...@@ -751,7 +752,7 @@ static int getoptions(char *c, struct trusted_key_payload *pay, ...@@ -751,7 +752,7 @@ static int getoptions(char *c, struct trusted_key_payload *pay,
int i; int i;
int tpm2; int tpm2;
tpm2 = tpm_is_tpm2(NULL); tpm2 = tpm_is_tpm2(chip);
if (tpm2 < 0) if (tpm2 < 0)
return tpm2; return tpm2;
...@@ -920,7 +921,7 @@ static struct trusted_key_options *trusted_options_alloc(void) ...@@ -920,7 +921,7 @@ static struct trusted_key_options *trusted_options_alloc(void)
struct trusted_key_options *options; struct trusted_key_options *options;
int tpm2; int tpm2;
tpm2 = tpm_is_tpm2(NULL); tpm2 = tpm_is_tpm2(chip);
if (tpm2 < 0) if (tpm2 < 0)
return NULL; return NULL;
...@@ -970,7 +971,7 @@ static int trusted_instantiate(struct key *key, ...@@ -970,7 +971,7 @@ static int trusted_instantiate(struct key *key,
size_t key_len; size_t key_len;
int tpm2; int tpm2;
tpm2 = tpm_is_tpm2(NULL); tpm2 = tpm_is_tpm2(chip);
if (tpm2 < 0) if (tpm2 < 0)
return tpm2; return tpm2;
...@@ -1011,7 +1012,7 @@ static int trusted_instantiate(struct key *key, ...@@ -1011,7 +1012,7 @@ static int trusted_instantiate(struct key *key,
switch (key_cmd) { switch (key_cmd) {
case Opt_load: case Opt_load:
if (tpm2) if (tpm2)
ret = tpm_unseal_trusted(NULL, payload, options); ret = tpm_unseal_trusted(chip, payload, options);
else else
ret = key_unseal(payload, options); ret = key_unseal(payload, options);
dump_payload(payload); dump_payload(payload);
...@@ -1021,13 +1022,13 @@ static int trusted_instantiate(struct key *key, ...@@ -1021,13 +1022,13 @@ static int trusted_instantiate(struct key *key,
break; break;
case Opt_new: case Opt_new:
key_len = payload->key_len; key_len = payload->key_len;
ret = tpm_get_random(NULL, payload->key, key_len); ret = tpm_get_random(chip, payload->key, key_len);
if (ret != key_len) { if (ret != key_len) {
pr_info("trusted_key: key_create failed (%d)\n", ret); pr_info("trusted_key: key_create failed (%d)\n", ret);
goto out; goto out;
} }
if (tpm2) if (tpm2)
ret = tpm_seal_trusted(NULL, payload, options); ret = tpm_seal_trusted(chip, payload, options);
else else
ret = key_seal(payload, options); ret = key_seal(payload, options);
if (ret < 0) if (ret < 0)
...@@ -1225,17 +1226,26 @@ static int __init init_trusted(void) ...@@ -1225,17 +1226,26 @@ static int __init init_trusted(void)
{ {
int ret; int ret;
chip = tpm_default_chip();
if (!chip)
return -ENOENT;
ret = trusted_shash_alloc(); ret = trusted_shash_alloc();
if (ret < 0) if (ret < 0)
return ret; goto err_put;
ret = register_key_type(&key_type_trusted); ret = register_key_type(&key_type_trusted);
if (ret < 0) if (ret < 0)
trusted_shash_release(); goto err_release;
return 0;
err_release:
trusted_shash_release();
err_put:
put_device(&chip->dev);
return ret; return ret;
} }
static void __exit cleanup_trusted(void) static void __exit cleanup_trusted(void)
{ {
put_device(&chip->dev);
trusted_shash_release(); trusted_shash_release();
unregister_key_type(&key_type_trusted); unregister_key_type(&key_type_trusted);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment