]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.4.181/crypto-crct10dif-generic-fix-use-via-crypto_shash_digest.patch
Linux 4.4.181
[thirdparty/kernel/stable-queue.git] / releases / 4.4.181 / crypto-crct10dif-generic-fix-use-via-crypto_shash_digest.patch
CommitLineData
09dfd60e
GKH
1From 307508d1072979f4435416f87936f87eaeb82054 Mon Sep 17 00:00:00 2001
2From: Eric Biggers <ebiggers@google.com>
3Date: Sun, 31 Mar 2019 13:04:12 -0700
4Subject: crypto: crct10dif-generic - fix use via crypto_shash_digest()
5
6From: Eric Biggers <ebiggers@google.com>
7
8commit 307508d1072979f4435416f87936f87eaeb82054 upstream.
9
10The ->digest() method of crct10dif-generic reads the current CRC value
11from the shash_desc context. But this value is uninitialized, causing
12crypto_shash_digest() to compute the wrong result. Fix it.
13
14Probably this wasn't noticed before because lib/crc-t10dif.c only uses
15crypto_shash_update(), not crypto_shash_digest(). Likewise,
16crypto_shash_digest() is not yet tested by the crypto self-tests because
17those only test the ahash API which only uses shash init/update/final.
18
19This bug was detected by my patches that improve testmgr to fuzz
20algorithms against their generic implementation.
21
22Fixes: 2d31e518a428 ("crypto: crct10dif - Wrap crc_t10dif function all to use crypto transform framework")
23Cc: <stable@vger.kernel.org> # v3.11+
24Cc: Tim Chen <tim.c.chen@linux.intel.com>
25Signed-off-by: Eric Biggers <ebiggers@google.com>
26Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
27Signed-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 = {