Commit 27c70036 authored by Milan Broz's avatar Milan Broz Committed by Mike Snitzer

dm crypt: fix crash by adding missing check for auth key size

If dm-crypt uses authenticated mode with separate MAC, there are two
concatenated part of the key structure - key(s) for encryption and
authentication key.

Add a missing check for authenticated key length.  If this key length is
smaller than actually provided key, dm-crypt now properly fails instead
of crashing.

Fixes: ef43aa38 ("dm crypt: add cryptographic data integrity protection (authenticated encryption)")
Cc: stable@vger.kernel.org # 4.12+
Reported-by: default avatarSalah Coronya <salahx@yahoo.com>
Signed-off-by: default avatarMilan Broz <gmazyland@gmail.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent bc68d0a4
...@@ -1954,10 +1954,15 @@ static int crypt_setkey(struct crypt_config *cc) ...@@ -1954,10 +1954,15 @@ static int crypt_setkey(struct crypt_config *cc)
/* Ignore extra keys (which are used for IV etc) */ /* Ignore extra keys (which are used for IV etc) */
subkey_size = crypt_subkey_size(cc); subkey_size = crypt_subkey_size(cc);
if (crypt_integrity_hmac(cc)) if (crypt_integrity_hmac(cc)) {
if (subkey_size < cc->key_mac_size)
return -EINVAL;
crypt_copy_authenckey(cc->authenc_key, cc->key, crypt_copy_authenckey(cc->authenc_key, cc->key,
subkey_size - cc->key_mac_size, subkey_size - cc->key_mac_size,
cc->key_mac_size); cc->key_mac_size);
}
for (i = 0; i < cc->tfms_count; i++) { for (i = 0; i < cc->tfms_count; i++) {
if (crypt_integrity_hmac(cc)) if (crypt_integrity_hmac(cc))
r = crypto_aead_setkey(cc->cipher_tfm.tfms_aead[i], r = crypto_aead_setkey(cc->cipher_tfm.tfms_aead[i],
......
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