]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.19.31/crypto-cfb-remove-bogus-memcpy-with-src-dest.patch
Linux 4.19.31
[thirdparty/kernel/stable-queue.git] / releases / 4.19.31 / crypto-cfb-remove-bogus-memcpy-with-src-dest.patch
1 From 6c2e322b3621dc8be72e5c86d4fdb587434ba625 Mon Sep 17 00:00:00 2001
2 From: Eric Biggers <ebiggers@google.com>
3 Date: Thu, 3 Jan 2019 20:16:11 -0800
4 Subject: crypto: cfb - remove bogus memcpy() with src == dest
5
6 From: Eric Biggers <ebiggers@google.com>
7
8 commit 6c2e322b3621dc8be72e5c86d4fdb587434ba625 upstream.
9
10 The memcpy() in crypto_cfb_decrypt_inplace() uses walk->iv as both the
11 source and destination, which has undefined behavior. It is unneeded
12 because walk->iv is already used to hold the previous ciphertext block;
13 thus, walk->iv is already updated to its final value. So, remove it.
14
15 Also, note that in-place decryption is the only case where the previous
16 ciphertext block is not directly available. Therefore, as a related
17 cleanup I also updated crypto_cfb_encrypt_segment() to directly use the
18 previous ciphertext block rather than save it into walk->iv. This makes
19 it consistent with in-place encryption and out-of-place decryption; now
20 only in-place decryption is different, because it has to be.
21
22 Fixes: a7d85e06ed80 ("crypto: cfb - add support for Cipher FeedBack mode")
23 Cc: <stable@vger.kernel.org> # v4.17+
24 Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
25 Signed-off-by: Eric Biggers <ebiggers@google.com>
26 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
27 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28
29 ---
30 crypto/cfb.c | 8 ++++----
31 1 file changed, 4 insertions(+), 4 deletions(-)
32
33 --- a/crypto/cfb.c
34 +++ b/crypto/cfb.c
35 @@ -77,12 +77,14 @@ static int crypto_cfb_encrypt_segment(st
36 do {
37 crypto_cfb_encrypt_one(tfm, iv, dst);
38 crypto_xor(dst, src, bsize);
39 - memcpy(iv, dst, bsize);
40 + iv = dst;
41
42 src += bsize;
43 dst += bsize;
44 } while ((nbytes -= bsize) >= bsize);
45
46 + memcpy(walk->iv, iv, bsize);
47 +
48 return nbytes;
49 }
50
51 @@ -162,7 +164,7 @@ static int crypto_cfb_decrypt_inplace(st
52 const unsigned int bsize = crypto_cfb_bsize(tfm);
53 unsigned int nbytes = walk->nbytes;
54 u8 *src = walk->src.virt.addr;
55 - u8 *iv = walk->iv;
56 + u8 * const iv = walk->iv;
57 u8 tmp[MAX_CIPHER_BLOCKSIZE];
58
59 do {
60 @@ -172,8 +174,6 @@ static int crypto_cfb_decrypt_inplace(st
61 src += bsize;
62 } while ((nbytes -= bsize) >= bsize);
63
64 - memcpy(walk->iv, iv, bsize);
65 -
66 return nbytes;
67 }
68