kernel: bump 5.4 to 5.4.66
[openwrt/openwrt.git] / target / linux / ipq40xx / patches-5.4 / 043-crypto-qce-save-a-sg-table-slot-for-result-buf.patch
1 From 3ee50c896d712dc2fc8f34c2cd1918d035e74045 Mon Sep 17 00:00:00 2001
2 From: Eneas U de Queiroz <cotequeiroz@gmail.com>
3 Date: Fri, 20 Dec 2019 16:02:15 -0300
4 Subject: [PATCH 04/11] crypto: qce - save a sg table slot for result buf
5
6 When ctr-aes-qce is used for gcm-mode, an extra sg entry for the
7 authentication tag is present, causing trouble when the qce driver
8 prepares the dst-results sg table for dma.
9
10 It computes the number of entries needed with sg_nents_for_len, leaving
11 out the tag entry. Then it creates a sg table with that number plus
12 one, used to store a result buffer.
13
14 When copying the sg table, there's no limit to the number of entries
15 copied, so the extra slot is filled with the authentication tag sg.
16 When the driver tries to add the result sg, the list is full, and it
17 returns EINVAL.
18
19 By limiting the number of sg entries copied to the dest table, the slot
20 for the result buffer is guaranteed to be unused.
21
22 Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
23 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
24 ---
25 drivers/crypto/qce/dma.c | 6 ++++--
26 drivers/crypto/qce/dma.h | 3 ++-
27 drivers/crypto/qce/skcipher.c | 4 ++--
28 3 files changed, 8 insertions(+), 5 deletions(-)
29
30 --- a/drivers/crypto/qce/dma.c
31 +++ b/drivers/crypto/qce/dma.c
32 @@ -47,7 +47,8 @@ void qce_dma_release(struct qce_dma_data
33 }
34
35 struct scatterlist *
36 -qce_sgtable_add(struct sg_table *sgt, struct scatterlist *new_sgl)
37 +qce_sgtable_add(struct sg_table *sgt, struct scatterlist *new_sgl,
38 + int max_ents)
39 {
40 struct scatterlist *sg = sgt->sgl, *sg_last = NULL;
41
42 @@ -60,12 +61,13 @@ qce_sgtable_add(struct sg_table *sgt, st
43 if (!sg)
44 return ERR_PTR(-EINVAL);
45
46 - while (new_sgl && sg) {
47 + while (new_sgl && sg && max_ents) {
48 sg_set_page(sg, sg_page(new_sgl), new_sgl->length,
49 new_sgl->offset);
50 sg_last = sg;
51 sg = sg_next(sg);
52 new_sgl = sg_next(new_sgl);
53 + max_ents--;
54 }
55
56 return sg_last;
57 --- a/drivers/crypto/qce/dma.h
58 +++ b/drivers/crypto/qce/dma.h
59 @@ -42,6 +42,7 @@ int qce_dma_prep_sgs(struct qce_dma_data
60 void qce_dma_issue_pending(struct qce_dma_data *dma);
61 int qce_dma_terminate_all(struct qce_dma_data *dma);
62 struct scatterlist *
63 -qce_sgtable_add(struct sg_table *sgt, struct scatterlist *sg_add);
64 +qce_sgtable_add(struct sg_table *sgt, struct scatterlist *sg_add,
65 + int max_ents);
66
67 #endif /* _DMA_H_ */
68 --- a/drivers/crypto/qce/skcipher.c
69 +++ b/drivers/crypto/qce/skcipher.c
70 @@ -95,13 +95,13 @@ qce_skcipher_async_req_handle(struct cry
71
72 sg_init_one(&rctx->result_sg, qce->dma.result_buf, QCE_RESULT_BUF_SZ);
73
74 - sg = qce_sgtable_add(&rctx->dst_tbl, req->dst);
75 + sg = qce_sgtable_add(&rctx->dst_tbl, req->dst, rctx->dst_nents - 1);
76 if (IS_ERR(sg)) {
77 ret = PTR_ERR(sg);
78 goto error_free;
79 }
80
81 - sg = qce_sgtable_add(&rctx->dst_tbl, &rctx->result_sg);
82 + sg = qce_sgtable_add(&rctx->dst_tbl, &rctx->result_sg, 1);
83 if (IS_ERR(sg)) {
84 ret = PTR_ERR(sg);
85 goto error_free;