Skip to content

Commit 2684bf7

Browse files
author
Mimi Zohar
committed
trusted-keys: check hex2bin result
For each hex2bin call in trusted keys, check that the ascii hex string is valid. On failure, return -EINVAL. Changelog v1: - hex2bin now returns an int Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com> Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com>
1 parent b780498 commit 2684bf7

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

‎security/keys/trusted.c‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,10 @@ static int getoptions(char *c, struct trusted_key_payload *pay,
779779
opt->pcrinfo_len = strlen(args[0].from) / 2;
780780
if (opt->pcrinfo_len > MAX_PCRINFO_SIZE)
781781
return -EINVAL;
782-
hex2bin(opt->pcrinfo, args[0].from, opt->pcrinfo_len);
782+
res = hex2bin(opt->pcrinfo, args[0].from,
783+
opt->pcrinfo_len);
784+
if (res < 0)
785+
return -EINVAL;
783786
break;
784787
case Opt_keyhandle:
785788
res = strict_strtoul(args[0].from, 16, &handle);
@@ -791,12 +794,18 @@ static int getoptions(char *c, struct trusted_key_payload *pay,
791794
case Opt_keyauth:
792795
if (strlen(args[0].from) != 2 * SHA1_DIGEST_SIZE)
793796
return -EINVAL;
794-
hex2bin(opt->keyauth, args[0].from, SHA1_DIGEST_SIZE);
797+
res = hex2bin(opt->keyauth, args[0].from,
798+
SHA1_DIGEST_SIZE);
799+
if (res < 0)
800+
return -EINVAL;
795801
break;
796802
case Opt_blobauth:
797803
if (strlen(args[0].from) != 2 * SHA1_DIGEST_SIZE)
798804
return -EINVAL;
799-
hex2bin(opt->blobauth, args[0].from, SHA1_DIGEST_SIZE);
805+
res = hex2bin(opt->blobauth, args[0].from,
806+
SHA1_DIGEST_SIZE);
807+
if (res < 0)
808+
return -EINVAL;
800809
break;
801810
case Opt_migratable:
802811
if (*args[0].from == '0')
@@ -860,7 +869,9 @@ static int datablob_parse(char *datablob, struct trusted_key_payload *p,
860869
p->blob_len = strlen(c) / 2;
861870
if (p->blob_len > MAX_BLOB_SIZE)
862871
return -EINVAL;
863-
hex2bin(p->blob, c, p->blob_len);
872+
ret = hex2bin(p->blob, c, p->blob_len);
873+
if (ret < 0)
874+
return -EINVAL;
864875
ret = getoptions(datablob, p, o);
865876
if (ret < 0)
866877
return ret;

0 commit comments

Comments
 (0)