Commit 9d9fb930 authored by Eric Biggers's avatar Eric Biggers Committed by Greg Kroah-Hartman

crypto: chelsio - fix writing tfm flags to wrong place

commit bd56cea0 upstream.

The chelsio crypto driver is casting 'struct crypto_aead' directly to
'struct crypto_tfm', which is incorrect because the crypto_tfm isn't the
first field of 'struct crypto_aead'.  Consequently, the calls to
crypto_tfm_set_flags() are modifying some other field in the struct.

Also, the driver is setting CRYPTO_TFM_RES_BAD_KEY_LEN in
->setauthsize(), not just in ->setkey().  This is incorrect since this
flag is for bad key lengths, not for bad authentication tag lengths.

Fix these bugs by removing the broken crypto_tfm_set_flags() calls from
->setauthsize() and by fixing them in ->setkey().

Fixes: 324429d7 ("chcr: Support for Chelsio's Crypto Hardware")
Cc: <stable@vger.kernel.org> # v4.9+
Cc: Atul Gupta <atul.gupta@chelsio.com>
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3c1f0162
...@@ -3135,9 +3135,6 @@ static int chcr_gcm_setauthsize(struct crypto_aead *tfm, unsigned int authsize) ...@@ -3135,9 +3135,6 @@ static int chcr_gcm_setauthsize(struct crypto_aead *tfm, unsigned int authsize)
aeadctx->mayverify = VERIFY_SW; aeadctx->mayverify = VERIFY_SW;
break; break;
default: default:
crypto_tfm_set_flags((struct crypto_tfm *) tfm,
CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
return crypto_aead_setauthsize(aeadctx->sw_cipher, authsize); return crypto_aead_setauthsize(aeadctx->sw_cipher, authsize);
...@@ -3162,8 +3159,6 @@ static int chcr_4106_4309_setauthsize(struct crypto_aead *tfm, ...@@ -3162,8 +3159,6 @@ static int chcr_4106_4309_setauthsize(struct crypto_aead *tfm,
aeadctx->mayverify = VERIFY_HW; aeadctx->mayverify = VERIFY_HW;
break; break;
default: default:
crypto_tfm_set_flags((struct crypto_tfm *)tfm,
CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
return crypto_aead_setauthsize(aeadctx->sw_cipher, authsize); return crypto_aead_setauthsize(aeadctx->sw_cipher, authsize);
...@@ -3204,8 +3199,6 @@ static int chcr_ccm_setauthsize(struct crypto_aead *tfm, ...@@ -3204,8 +3199,6 @@ static int chcr_ccm_setauthsize(struct crypto_aead *tfm,
aeadctx->mayverify = VERIFY_HW; aeadctx->mayverify = VERIFY_HW;
break; break;
default: default:
crypto_tfm_set_flags((struct crypto_tfm *)tfm,
CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
return crypto_aead_setauthsize(aeadctx->sw_cipher, authsize); return crypto_aead_setauthsize(aeadctx->sw_cipher, authsize);
...@@ -3230,8 +3223,7 @@ static int chcr_ccm_common_setkey(struct crypto_aead *aead, ...@@ -3230,8 +3223,7 @@ static int chcr_ccm_common_setkey(struct crypto_aead *aead,
ck_size = CHCR_KEYCTX_CIPHER_KEY_SIZE_256; ck_size = CHCR_KEYCTX_CIPHER_KEY_SIZE_256;
mk_size = CHCR_KEYCTX_MAC_KEY_SIZE_256; mk_size = CHCR_KEYCTX_MAC_KEY_SIZE_256;
} else { } else {
crypto_tfm_set_flags((struct crypto_tfm *)aead, crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
CRYPTO_TFM_RES_BAD_KEY_LEN);
aeadctx->enckey_len = 0; aeadctx->enckey_len = 0;
return -EINVAL; return -EINVAL;
} }
...@@ -3269,8 +3261,7 @@ static int chcr_aead_rfc4309_setkey(struct crypto_aead *aead, const u8 *key, ...@@ -3269,8 +3261,7 @@ static int chcr_aead_rfc4309_setkey(struct crypto_aead *aead, const u8 *key,
int error; int error;
if (keylen < 3) { if (keylen < 3) {
crypto_tfm_set_flags((struct crypto_tfm *)aead, crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
CRYPTO_TFM_RES_BAD_KEY_LEN);
aeadctx->enckey_len = 0; aeadctx->enckey_len = 0;
return -EINVAL; return -EINVAL;
} }
...@@ -3320,8 +3311,7 @@ static int chcr_gcm_setkey(struct crypto_aead *aead, const u8 *key, ...@@ -3320,8 +3311,7 @@ static int chcr_gcm_setkey(struct crypto_aead *aead, const u8 *key,
} else if (keylen == AES_KEYSIZE_256) { } else if (keylen == AES_KEYSIZE_256) {
ck_size = CHCR_KEYCTX_CIPHER_KEY_SIZE_256; ck_size = CHCR_KEYCTX_CIPHER_KEY_SIZE_256;
} else { } else {
crypto_tfm_set_flags((struct crypto_tfm *)aead, crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
CRYPTO_TFM_RES_BAD_KEY_LEN);
pr_err("GCM: Invalid key length %d\n", keylen); pr_err("GCM: Invalid key length %d\n", keylen);
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
......
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