]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/crypto-caam-fix-hash-context-dma-unmap-size.patch
e7b2b5cc2af9ab5b7339643268ae22fc595dbd6d
[thirdparty/kernel/stable-queue.git] / queue-4.19 / crypto-caam-fix-hash-context-dma-unmap-size.patch
1 From 65055e2108847af5e577cc7ce6bde45ea136d29a Mon Sep 17 00:00:00 2001
2 From: Franck LENORMAND <franck.lenormand@nxp.com>
3 Date: Tue, 19 Feb 2019 16:56:55 +0200
4 Subject: crypto: caam - fix hash context DMA unmap size
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 From: Franck LENORMAND <franck.lenormand@nxp.com>
10
11 commit 65055e2108847af5e577cc7ce6bde45ea136d29a upstream.
12
13 When driver started using state->caam_ctxt for storing both running hash
14 and final hash, it was not updated to handle different DMA unmap
15 lengths.
16
17 Cc: <stable@vger.kernel.org> # v4.19+
18 Fixes: c19650d6ea99 ("crypto: caam - fix DMA mapping of stack memory")
19 Signed-off-by: Franck LENORMAND <franck.lenormand@nxp.com>
20 Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
21 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
22 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
23
24 ---
25 drivers/crypto/caam/caamhash.c | 8 +++++---
26 1 file changed, 5 insertions(+), 3 deletions(-)
27
28 --- a/drivers/crypto/caam/caamhash.c
29 +++ b/drivers/crypto/caam/caamhash.c
30 @@ -118,6 +118,7 @@ struct caam_hash_ctx {
31 struct caam_hash_state {
32 dma_addr_t buf_dma;
33 dma_addr_t ctx_dma;
34 + int ctx_dma_len;
35 u8 buf_0[CAAM_MAX_HASH_BLOCK_SIZE] ____cacheline_aligned;
36 int buflen_0;
37 u8 buf_1[CAAM_MAX_HASH_BLOCK_SIZE] ____cacheline_aligned;
38 @@ -170,6 +171,7 @@ static inline int map_seq_out_ptr_ctx(u3
39 struct caam_hash_state *state,
40 int ctx_len)
41 {
42 + state->ctx_dma_len = ctx_len;
43 state->ctx_dma = dma_map_single(jrdev, state->caam_ctx,
44 ctx_len, DMA_FROM_DEVICE);
45 if (dma_mapping_error(jrdev, state->ctx_dma)) {
46 @@ -223,6 +225,7 @@ static inline int ctx_map_to_sec4_sg(str
47 struct caam_hash_state *state, int ctx_len,
48 struct sec4_sg_entry *sec4_sg, u32 flag)
49 {
50 + state->ctx_dma_len = ctx_len;
51 state->ctx_dma = dma_map_single(jrdev, state->caam_ctx, ctx_len, flag);
52 if (dma_mapping_error(jrdev, state->ctx_dma)) {
53 dev_err(jrdev, "unable to map ctx\n");
54 @@ -527,12 +530,10 @@ static inline void ahash_unmap_ctx(struc
55 struct ahash_edesc *edesc,
56 struct ahash_request *req, int dst_len, u32 flag)
57 {
58 - struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
59 - struct caam_hash_ctx *ctx = crypto_ahash_ctx(ahash);
60 struct caam_hash_state *state = ahash_request_ctx(req);
61
62 if (state->ctx_dma) {
63 - dma_unmap_single(dev, state->ctx_dma, ctx->ctx_len, flag);
64 + dma_unmap_single(dev, state->ctx_dma, state->ctx_dma_len, flag);
65 state->ctx_dma = 0;
66 }
67 ahash_unmap(dev, edesc, req, dst_len);
68 @@ -1505,6 +1506,7 @@ static int ahash_init(struct ahash_reque
69 state->final = ahash_final_no_ctx;
70
71 state->ctx_dma = 0;
72 + state->ctx_dma_len = 0;
73 state->current_buf = 0;
74 state->buf_dma = 0;
75 state->buflen_0 = 0;