trusted-keys: check hex2bin result.
[opensuse:kernel-source.git] / patches.fixes / 0001-trusted-keys-check-hex2bin-result.patch
1 From 2684bf7f29cfb13ef2c60f3b3a53ee47d0db7022 Mon Sep 17 00:00:00 2001
2 From: Mimi Zohar <zohar@linux.vnet.ibm.com>
3 Date: Tue, 20 Sep 2011 11:23:52 -0400
4 Subject: [PATCH] trusted-keys: check hex2bin result
5
6 Git-commit: 2684bf7f29cfb13ef2c60f3b3a53ee47d0db7022
7 Patch-mainline: v3.2
8 References: fate#314508
9 Target: SLE-11 SP3
10
11 For each hex2bin call in trusted keys, check that the ascii hex string is
12 valid.  On failure, return -EINVAL.
13
14 Changelog v1:
15 - hex2bin now returns an int
16
17 Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
18 Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com>
19 Acked-by: Lee, Chun-Yi <jlee@suse.com>
20 ---
21  security/keys/trusted.c |   19 +++++++++++++++----
22  1 file changed, 15 insertions(+), 4 deletions(-)
23
24 --- a/security/keys/trusted.c
25 +++ b/security/keys/trusted.c
26 @@ -779,7 +779,10 @@ static int getoptions(char *c, struct tr
27                         opt->pcrinfo_len = strlen(args[0].from) / 2;
28                         if (opt->pcrinfo_len > MAX_PCRINFO_SIZE)
29                                 return -EINVAL;
30 -                       hex2bin(opt->pcrinfo, args[0].from, opt->pcrinfo_len);
31 +                       res = hex2bin(opt->pcrinfo, args[0].from,
32 +                                     opt->pcrinfo_len);
33 +                       if (res < 0)
34 +                               return -EINVAL;
35                         break;
36                 case Opt_keyhandle:
37                         res = strict_strtoul(args[0].from, 16, &handle);
38 @@ -791,12 +794,18 @@ static int getoptions(char *c, struct tr
39                 case Opt_keyauth:
40                         if (strlen(args[0].from) != 2 * SHA1_DIGEST_SIZE)
41                                 return -EINVAL;
42 -                       hex2bin(opt->keyauth, args[0].from, SHA1_DIGEST_SIZE);
43 +                       res = hex2bin(opt->keyauth, args[0].from,
44 +                                     SHA1_DIGEST_SIZE);
45 +                       if (res < 0)
46 +                               return -EINVAL;
47                         break;
48                 case Opt_blobauth:
49                         if (strlen(args[0].from) != 2 * SHA1_DIGEST_SIZE)
50                                 return -EINVAL;
51 -                       hex2bin(opt->blobauth, args[0].from, SHA1_DIGEST_SIZE);
52 +                       res = hex2bin(opt->blobauth, args[0].from,
53 +                                     SHA1_DIGEST_SIZE);
54 +                       if (res < 0)
55 +                               return -EINVAL;
56                         break;
57                 case Opt_migratable:
58                         if (*args[0].from == '0')
59 @@ -860,7 +869,9 @@ static int datablob_parse(char *datablob
60                 p->blob_len = strlen(c) / 2;
61                 if (p->blob_len > MAX_BLOB_SIZE)
62                         return -EINVAL;
63 -               hex2bin(p->blob, c, p->blob_len);
64 +               ret = hex2bin(p->blob, c, p->blob_len);
65 +               if (ret < 0)
66 +                       return -EINVAL;
67                 ret = getoptions(datablob, p, o);
68                 if (ret < 0)
69                         return ret;