]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
crypto: x86/cast5-avx - fix ECB encryption when long sg follows short one
authorEric Biggers <ebiggers@google.com>
Tue, 20 Feb 2018 07:48:12 +0000 (23:48 -0800)
committerSasha Levin <alexander.levin@microsoft.com>
Wed, 23 May 2018 01:33:57 +0000 (21:33 -0400)
[ Upstream commit 8f461b1e02ed546fbd0f11611138da67fd85a30f ]

With ecb-cast5-avx, if a 128+ byte scatterlist element followed a
shorter one, then the algorithm accidentally encrypted/decrypted only 8
bytes instead of the expected 128 bytes.  Fix it by setting the
encryption/decryption 'fn' correctly.

Fixes: c12ab20b162c ("crypto: cast5/avx - avoid using temporary stack buffers")
Cc: <stable@vger.kernel.org> # v3.8+
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
arch/x86/crypto/cast5_avx_glue.c

index 236c80974457b97575a585911aabbdf72b23c4f8..75385fcf1074591c35aa6057b69076818a8f8996 100644 (file)
@@ -67,8 +67,6 @@ static int ecb_crypt(struct blkcipher_desc *desc, struct blkcipher_walk *walk,
        void (*fn)(struct cast5_ctx *ctx, u8 *dst, const u8 *src);
        int err;
 
-       fn = (enc) ? cast5_ecb_enc_16way : cast5_ecb_dec_16way;
-
        err = blkcipher_walk_virt(desc, walk);
        desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
 
@@ -80,6 +78,7 @@ static int ecb_crypt(struct blkcipher_desc *desc, struct blkcipher_walk *walk,
 
                /* Process multi-block batch */
                if (nbytes >= bsize * CAST5_PARALLEL_BLOCKS) {
+                       fn = (enc) ? cast5_ecb_enc_16way : cast5_ecb_dec_16way;
                        do {
                                fn(ctx, wdst, wsrc);