diff options
author | Eric Biggers <ebiggers@google.com> | 2017-06-08 09:49:34 -0400 |
---|---|---|
committer | James Morris <james.l.morris@oracle.com> | 2017-06-08 23:29:49 -0400 |
commit | bbe240454d86be95151e0ecfd6ac55fe5ef5a6f5 (patch) | |
tree | 662839ffc98b691fe598cef81a1bab0c2b123ccd /security | |
parent | 0620fddb56dfaf0e1034eeb69d79c73b361debbf (diff) |
KEYS: DH: forbid using digest_null as the KDF hash
Requesting "digest_null" in the keyctl_kdf_params caused an infinite
loop in kdf_ctr() because the "null" hash has a digest size of 0. Fix
it by rejecting hash algorithms with a digest size of 0.
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: James Morris <james.l.morris@oracle.com>
Diffstat (limited to 'security')
-rw-r--r-- | security/keys/dh.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/security/keys/dh.c b/security/keys/dh.c index e603bd912e4c..8abc70ebe22d 100644 --- a/security/keys/dh.c +++ b/security/keys/dh.c | |||
@@ -89,6 +89,7 @@ static int kdf_alloc(struct kdf_sdesc **sdesc_ret, char *hashname) | |||
89 | struct crypto_shash *tfm; | 89 | struct crypto_shash *tfm; |
90 | struct kdf_sdesc *sdesc; | 90 | struct kdf_sdesc *sdesc; |
91 | int size; | 91 | int size; |
92 | int err; | ||
92 | 93 | ||
93 | /* allocate synchronous hash */ | 94 | /* allocate synchronous hash */ |
94 | tfm = crypto_alloc_shash(hashname, 0, 0); | 95 | tfm = crypto_alloc_shash(hashname, 0, 0); |
@@ -97,16 +98,25 @@ static int kdf_alloc(struct kdf_sdesc **sdesc_ret, char *hashname) | |||
97 | return PTR_ERR(tfm); | 98 | return PTR_ERR(tfm); |
98 | } | 99 | } |
99 | 100 | ||
101 | err = -EINVAL; | ||
102 | if (crypto_shash_digestsize(tfm) == 0) | ||
103 | goto out_free_tfm; | ||
104 | |||
105 | err = -ENOMEM; | ||
100 | size = sizeof(struct shash_desc) + crypto_shash_descsize(tfm); | 106 | size = sizeof(struct shash_desc) + crypto_shash_descsize(tfm); |
101 | sdesc = kmalloc(size, GFP_KERNEL); | 107 | sdesc = kmalloc(size, GFP_KERNEL); |
102 | if (!sdesc) | 108 | if (!sdesc) |
103 | return -ENOMEM; | 109 | goto out_free_tfm; |
104 | sdesc->shash.tfm = tfm; | 110 | sdesc->shash.tfm = tfm; |
105 | sdesc->shash.flags = 0x0; | 111 | sdesc->shash.flags = 0x0; |
106 | 112 | ||
107 | *sdesc_ret = sdesc; | 113 | *sdesc_ret = sdesc; |
108 | 114 | ||
109 | return 0; | 115 | return 0; |
116 | |||
117 | out_free_tfm: | ||
118 | crypto_free_shash(tfm); | ||
119 | return err; | ||
110 | } | 120 | } |
111 | 121 | ||
112 | static void kdf_dealloc(struct kdf_sdesc *sdesc) | 122 | static void kdf_dealloc(struct kdf_sdesc *sdesc) |