]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/crypto-crct10dif-generic-fix-use-via-crypto_shash_digest.patch
Linux 4.14.121
[thirdparty/kernel/stable-queue.git] / queue-4.19 / crypto-crct10dif-generic-fix-use-via-crypto_shash_digest.patch
1 From 307508d1072979f4435416f87936f87eaeb82054 Mon Sep 17 00:00:00 2001
2 From: Eric Biggers <ebiggers@google.com>
3 Date: Sun, 31 Mar 2019 13:04:12 -0700
4 Subject: crypto: crct10dif-generic - fix use via crypto_shash_digest()
5
6 From: Eric Biggers <ebiggers@google.com>
7
8 commit 307508d1072979f4435416f87936f87eaeb82054 upstream.
9
10 The ->digest() method of crct10dif-generic reads the current CRC value
11 from the shash_desc context. But this value is uninitialized, causing
12 crypto_shash_digest() to compute the wrong result. Fix it.
13
14 Probably this wasn't noticed before because lib/crc-t10dif.c only uses
15 crypto_shash_update(), not crypto_shash_digest(). Likewise,
16 crypto_shash_digest() is not yet tested by the crypto self-tests because
17 those only test the ahash API which only uses shash init/update/final.
18
19 This bug was detected by my patches that improve testmgr to fuzz
20 algorithms against their generic implementation.
21
22 Fixes: 2d31e518a428 ("crypto: crct10dif - Wrap crc_t10dif function all to use crypto transform framework")
23 Cc: <stable@vger.kernel.org> # v3.11+
24 Cc: Tim Chen <tim.c.chen@linux.intel.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/crct10dif_generic.c | 11 ++++-------
31 1 file changed, 4 insertions(+), 7 deletions(-)
32
33 --- a/crypto/crct10dif_generic.c
34 +++ b/crypto/crct10dif_generic.c
35 @@ -65,10 +65,9 @@ static int chksum_final(struct shash_des
36 return 0;
37 }
38
39 -static int __chksum_finup(__u16 *crcp, const u8 *data, unsigned int len,
40 - u8 *out)
41 +static int __chksum_finup(__u16 crc, const u8 *data, unsigned int len, u8 *out)
42 {
43 - *(__u16 *)out = crc_t10dif_generic(*crcp, data, len);
44 + *(__u16 *)out = crc_t10dif_generic(crc, data, len);
45 return 0;
46 }
47
48 @@ -77,15 +76,13 @@ static int chksum_finup(struct shash_des
49 {
50 struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
51
52 - return __chksum_finup(&ctx->crc, data, len, out);
53 + return __chksum_finup(ctx->crc, data, len, out);
54 }
55
56 static int chksum_digest(struct shash_desc *desc, const u8 *data,
57 unsigned int length, u8 *out)
58 {
59 - struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
60 -
61 - return __chksum_finup(&ctx->crc, data, length, out);
62 + return __chksum_finup(0, data, length, out);
63 }
64
65 static struct shash_alg alg = {