From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org
Cc: Atul Gupta <atul.gupta@chelsio.com>
Subject: Re: [PATCH 1/8] crypto: chelsio - fix writing tfm flags to wrong place
Date: Mon, 30 Dec 2019 22:42:22 -0600 [thread overview]
Message-ID: <20191231044222.GA180988@zzz.localdomain> (raw)
In-Reply-To: <20191231031938.241705-2-ebiggers@kernel.org>
[+Cc the person with a Cc tag in the patch, who I accidentally didn't Cc...
Original message was
https://lkml.kernel.org/linux-crypto/20191231031938.241705-2-ebiggers@kernel.org/]
On Mon, Dec 30, 2019 at 09:19:31PM -0600, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
>
> 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: 324429d74127 ("chcr: Support for Chelsio's Crypto Hardware")
> Cc: <stable@vger.kernel.org> # v4.9+
> Cc: Atul Gupta <atul.gupta@chelsio.com>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
> drivers/crypto/chelsio/chcr_algo.c | 16 +++-------------
> 1 file changed, 3 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/crypto/chelsio/chcr_algo.c b/drivers/crypto/chelsio/chcr_algo.c
> index 586dbc69d0cd..5b7dbe7cdb17 100644
> --- a/drivers/crypto/chelsio/chcr_algo.c
> +++ b/drivers/crypto/chelsio/chcr_algo.c
> @@ -3196,9 +3196,6 @@ static int chcr_gcm_setauthsize(struct crypto_aead *tfm, unsigned int authsize)
> aeadctx->mayverify = VERIFY_SW;
> break;
> default:
> -
> - crypto_tfm_set_flags((struct crypto_tfm *) tfm,
> - CRYPTO_TFM_RES_BAD_KEY_LEN);
> return -EINVAL;
> }
> return crypto_aead_setauthsize(aeadctx->sw_cipher, authsize);
> @@ -3223,8 +3220,6 @@ static int chcr_4106_4309_setauthsize(struct crypto_aead *tfm,
> aeadctx->mayverify = VERIFY_HW;
> break;
> default:
> - crypto_tfm_set_flags((struct crypto_tfm *)tfm,
> - CRYPTO_TFM_RES_BAD_KEY_LEN);
> return -EINVAL;
> }
> return crypto_aead_setauthsize(aeadctx->sw_cipher, authsize);
> @@ -3265,8 +3260,6 @@ static int chcr_ccm_setauthsize(struct crypto_aead *tfm,
> aeadctx->mayverify = VERIFY_HW;
> break;
> default:
> - crypto_tfm_set_flags((struct crypto_tfm *)tfm,
> - CRYPTO_TFM_RES_BAD_KEY_LEN);
> return -EINVAL;
> }
> return crypto_aead_setauthsize(aeadctx->sw_cipher, authsize);
> @@ -3291,8 +3284,7 @@ static int chcr_ccm_common_setkey(struct crypto_aead *aead,
> ck_size = CHCR_KEYCTX_CIPHER_KEY_SIZE_256;
> mk_size = CHCR_KEYCTX_MAC_KEY_SIZE_256;
> } else {
> - crypto_tfm_set_flags((struct crypto_tfm *)aead,
> - CRYPTO_TFM_RES_BAD_KEY_LEN);
> + crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
> aeadctx->enckey_len = 0;
> return -EINVAL;
> }
> @@ -3330,8 +3322,7 @@ static int chcr_aead_rfc4309_setkey(struct crypto_aead *aead, const u8 *key,
> int error;
>
> if (keylen < 3) {
> - crypto_tfm_set_flags((struct crypto_tfm *)aead,
> - CRYPTO_TFM_RES_BAD_KEY_LEN);
> + crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
> aeadctx->enckey_len = 0;
> return -EINVAL;
> }
> @@ -3381,8 +3372,7 @@ static int chcr_gcm_setkey(struct crypto_aead *aead, const u8 *key,
> } else if (keylen == AES_KEYSIZE_256) {
> ck_size = CHCR_KEYCTX_CIPHER_KEY_SIZE_256;
> } else {
> - crypto_tfm_set_flags((struct crypto_tfm *)aead,
> - CRYPTO_TFM_RES_BAD_KEY_LEN);
> + crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
> pr_err("GCM: Invalid key length %d\n", keylen);
> ret = -EINVAL;
> goto out;
> --
> 2.24.1
>
next prev parent reply other threads:[~2019-12-31 4:42 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-31 3:19 [PATCH 0/8] crypto: remove the CRYPTO_TFM_RES_* flags Eric Biggers
2019-12-31 3:19 ` [PATCH 1/8] crypto: chelsio - fix writing tfm flags to wrong place Eric Biggers
2019-12-31 4:42 ` Eric Biggers [this message]
2019-12-31 3:19 ` [PATCH 2/8] crypto: artpec6 - return correct error code for failed setkey() Eric Biggers
2019-12-31 4:43 ` Eric Biggers
2020-01-01 16:04 ` Lars Persson
2019-12-31 3:19 ` [PATCH 3/8] crypto: atmel-sha - fix error handling when setting hmac key Eric Biggers
2019-12-31 4:45 ` Eric Biggers
2020-01-08 16:06 ` Tudor.Ambarus
2019-12-31 3:19 ` [PATCH 4/8] crypto: remove unused tfm result flags Eric Biggers
2019-12-31 3:19 ` [PATCH 5/8] crypto: remove CRYPTO_TFM_RES_BAD_BLOCK_LEN Eric Biggers
2019-12-31 3:19 ` [PATCH 6/8] crypto: remove CRYPTO_TFM_RES_BAD_KEY_LEN Eric Biggers
2020-01-06 15:00 ` Horia Geanta
2019-12-31 3:19 ` [PATCH 7/8] crypto: remove CRYPTO_TFM_RES_WEAK_KEY Eric Biggers
2019-12-31 3:19 ` [PATCH 8/8] crypto: remove propagation of CRYPTO_TFM_RES_* flags Eric Biggers
2019-12-31 8:14 ` [PATCH 0/8] crypto: remove the " Ard Biesheuvel
2020-01-09 5:14 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191231044222.GA180988@zzz.localdomain \
--to=ebiggers@kernel.org \
--cc=atul.gupta@chelsio.com \
--cc=linux-crypto@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).