Commit 87f27e7b authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'queue' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/tpmdd

Pull tpm fixes from James Bottomley:
 "Fix a regression in the TPM trusted keys caused by the generic rework
  to add ARM TEE based trusted keys.

  Without this fix, the TPM trusted key subsystem fails to add or load
  any keys"

* tag 'queue' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/tpmdd:
  KEYS: trusted: fix TPM trusted keys for generic framework
parents 7dd1ce1a 60dc5f1b
...@@ -62,7 +62,7 @@ static const match_table_t key_tokens = { ...@@ -62,7 +62,7 @@ static const match_table_t key_tokens = {
* *
* On success returns 0, otherwise -EINVAL. * On success returns 0, otherwise -EINVAL.
*/ */
static int datablob_parse(char *datablob, struct trusted_key_payload *p) static int datablob_parse(char **datablob, struct trusted_key_payload *p)
{ {
substring_t args[MAX_OPT_ARGS]; substring_t args[MAX_OPT_ARGS];
long keylen; long keylen;
...@@ -71,14 +71,14 @@ static int datablob_parse(char *datablob, struct trusted_key_payload *p) ...@@ -71,14 +71,14 @@ static int datablob_parse(char *datablob, struct trusted_key_payload *p)
char *c; char *c;
/* main command */ /* main command */
c = strsep(&datablob, " \t"); c = strsep(datablob, " \t");
if (!c) if (!c)
return -EINVAL; return -EINVAL;
key_cmd = match_token(c, key_tokens, args); key_cmd = match_token(c, key_tokens, args);
switch (key_cmd) { switch (key_cmd) {
case Opt_new: case Opt_new:
/* first argument is key size */ /* first argument is key size */
c = strsep(&datablob, " \t"); c = strsep(datablob, " \t");
if (!c) if (!c)
return -EINVAL; return -EINVAL;
ret = kstrtol(c, 10, &keylen); ret = kstrtol(c, 10, &keylen);
...@@ -89,7 +89,7 @@ static int datablob_parse(char *datablob, struct trusted_key_payload *p) ...@@ -89,7 +89,7 @@ static int datablob_parse(char *datablob, struct trusted_key_payload *p)
break; break;
case Opt_load: case Opt_load:
/* first argument is sealed blob */ /* first argument is sealed blob */
c = strsep(&datablob, " \t"); c = strsep(datablob, " \t");
if (!c) if (!c)
return -EINVAL; return -EINVAL;
p->blob_len = strlen(c) / 2; p->blob_len = strlen(c) / 2;
...@@ -140,7 +140,7 @@ static int trusted_instantiate(struct key *key, ...@@ -140,7 +140,7 @@ static int trusted_instantiate(struct key *key,
{ {
struct trusted_key_payload *payload = NULL; struct trusted_key_payload *payload = NULL;
size_t datalen = prep->datalen; size_t datalen = prep->datalen;
char *datablob; char *datablob, *orig_datablob;
int ret = 0; int ret = 0;
int key_cmd; int key_cmd;
size_t key_len; size_t key_len;
...@@ -148,7 +148,7 @@ static int trusted_instantiate(struct key *key, ...@@ -148,7 +148,7 @@ static int trusted_instantiate(struct key *key,
if (datalen <= 0 || datalen > 32767 || !prep->data) if (datalen <= 0 || datalen > 32767 || !prep->data)
return -EINVAL; return -EINVAL;
datablob = kmalloc(datalen + 1, GFP_KERNEL); orig_datablob = datablob = kmalloc(datalen + 1, GFP_KERNEL);
if (!datablob) if (!datablob)
return -ENOMEM; return -ENOMEM;
memcpy(datablob, prep->data, datalen); memcpy(datablob, prep->data, datalen);
...@@ -160,7 +160,7 @@ static int trusted_instantiate(struct key *key, ...@@ -160,7 +160,7 @@ static int trusted_instantiate(struct key *key,
goto out; goto out;
} }
key_cmd = datablob_parse(datablob, payload); key_cmd = datablob_parse(&datablob, payload);
if (key_cmd < 0) { if (key_cmd < 0) {
ret = key_cmd; ret = key_cmd;
goto out; goto out;
...@@ -196,7 +196,7 @@ static int trusted_instantiate(struct key *key, ...@@ -196,7 +196,7 @@ static int trusted_instantiate(struct key *key,
ret = -EINVAL; ret = -EINVAL;
} }
out: out:
kfree_sensitive(datablob); kfree_sensitive(orig_datablob);
if (!ret) if (!ret)
rcu_assign_keypointer(key, payload); rcu_assign_keypointer(key, payload);
else else
...@@ -220,7 +220,7 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep) ...@@ -220,7 +220,7 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep)
struct trusted_key_payload *p; struct trusted_key_payload *p;
struct trusted_key_payload *new_p; struct trusted_key_payload *new_p;
size_t datalen = prep->datalen; size_t datalen = prep->datalen;
char *datablob; char *datablob, *orig_datablob;
int ret = 0; int ret = 0;
if (key_is_negative(key)) if (key_is_negative(key))
...@@ -231,7 +231,7 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep) ...@@ -231,7 +231,7 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep)
if (datalen <= 0 || datalen > 32767 || !prep->data) if (datalen <= 0 || datalen > 32767 || !prep->data)
return -EINVAL; return -EINVAL;
datablob = kmalloc(datalen + 1, GFP_KERNEL); orig_datablob = datablob = kmalloc(datalen + 1, GFP_KERNEL);
if (!datablob) if (!datablob)
return -ENOMEM; return -ENOMEM;
...@@ -243,7 +243,7 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep) ...@@ -243,7 +243,7 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep)
memcpy(datablob, prep->data, datalen); memcpy(datablob, prep->data, datalen);
datablob[datalen] = '\0'; datablob[datalen] = '\0';
ret = datablob_parse(datablob, new_p); ret = datablob_parse(&datablob, new_p);
if (ret != Opt_update) { if (ret != Opt_update) {
ret = -EINVAL; ret = -EINVAL;
kfree_sensitive(new_p); kfree_sensitive(new_p);
...@@ -267,7 +267,7 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep) ...@@ -267,7 +267,7 @@ static int trusted_update(struct key *key, struct key_preparsed_payload *prep)
rcu_assign_keypointer(key, new_p); rcu_assign_keypointer(key, new_p);
call_rcu(&p->rcu, trusted_rcu_free); call_rcu(&p->rcu, trusted_rcu_free);
out: out:
kfree_sensitive(datablob); kfree_sensitive(orig_datablob);
return ret; return ret;
} }
......
...@@ -747,6 +747,9 @@ static int getoptions(char *c, struct trusted_key_payload *pay, ...@@ -747,6 +747,9 @@ static int getoptions(char *c, struct trusted_key_payload *pay,
opt->hash = tpm2 ? HASH_ALGO_SHA256 : HASH_ALGO_SHA1; opt->hash = tpm2 ? HASH_ALGO_SHA256 : HASH_ALGO_SHA1;
if (!c)
return 0;
while ((p = strsep(&c, " \t"))) { while ((p = strsep(&c, " \t"))) {
if (*p == '\0' || *p == ' ' || *p == '\t') if (*p == '\0' || *p == ' ' || *p == '\t')
continue; continue;
...@@ -944,7 +947,7 @@ static int trusted_tpm_unseal(struct trusted_key_payload *p, char *datablob) ...@@ -944,7 +947,7 @@ static int trusted_tpm_unseal(struct trusted_key_payload *p, char *datablob)
goto out; goto out;
dump_options(options); dump_options(options);
if (!options->keyhandle) { if (!options->keyhandle && !tpm2) {
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
......
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