diff options
author | Eric Biggers <ebiggers@google.com> | 2017-06-08 09:48:32 -0400 |
---|---|---|
committer | James Morris <james.l.morris@oracle.com> | 2017-06-08 23:29:47 -0400 |
commit | 0f534e4a13496b02ae284f50fcb0263f6ea37007 (patch) | |
tree | a5200ddfa62a42340dd2ee2e918fb5b001240382 | |
parent | 64d107d3acca1565c39c044c459fd18f70943534 (diff) |
KEYS: encrypted: use constant-time HMAC comparison
MACs should, in general, be compared using crypto_memneq() to prevent
timing attacks.
Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <james.l.morris@oracle.com>
-rw-r--r-- | security/keys/encrypted-keys/encrypted.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/security/keys/encrypted-keys/encrypted.c b/security/keys/encrypted-keys/encrypted.c index 702c80662069..5c98c2fe03f0 100644 --- a/security/keys/encrypted-keys/encrypted.c +++ b/security/keys/encrypted-keys/encrypted.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/scatterlist.h> | 30 | #include <linux/scatterlist.h> |
31 | #include <linux/ctype.h> | 31 | #include <linux/ctype.h> |
32 | #include <crypto/aes.h> | 32 | #include <crypto/aes.h> |
33 | #include <crypto/algapi.h> | ||
33 | #include <crypto/hash.h> | 34 | #include <crypto/hash.h> |
34 | #include <crypto/sha.h> | 35 | #include <crypto/sha.h> |
35 | #include <crypto/skcipher.h> | 36 | #include <crypto/skcipher.h> |
@@ -534,8 +535,8 @@ static int datablob_hmac_verify(struct encrypted_key_payload *epayload, | |||
534 | ret = calc_hmac(digest, derived_key, sizeof derived_key, p, len); | 535 | ret = calc_hmac(digest, derived_key, sizeof derived_key, p, len); |
535 | if (ret < 0) | 536 | if (ret < 0) |
536 | goto out; | 537 | goto out; |
537 | ret = memcmp(digest, epayload->format + epayload->datablob_len, | 538 | ret = crypto_memneq(digest, epayload->format + epayload->datablob_len, |
538 | sizeof digest); | 539 | sizeof(digest)); |
539 | if (ret) { | 540 | if (ret) { |
540 | ret = -EINVAL; | 541 | ret = -EINVAL; |
541 | dump_hmac("datablob", | 542 | dump_hmac("datablob", |