b83cacc98feb9be59ac886b747a91b3c1c2c435b
[oweals/openwrt.git] /
1 From 658c9d2b9f374c835d0348d852a3f002196628d0 Mon Sep 17 00:00:00 2001
2 From: Christian Lamparter <chunkeey@gmail.com>
3 Date: Thu, 19 Apr 2018 18:41:57 +0200
4 Subject: [PATCH 8/8] crypto: crypto4xx - put temporary dst sg into request ctx
5
6 This patch fixes a crash that happens when testing rfc4543(gcm(aes))
7
8 Unable to handle kernel paging request for data at address 0xf59b3420
9 Faulting instruction address: 0xc0012994
10 Oops: Kernel access of bad area, sig: 11 [#1]
11 BE PowerPC 44x Platform
12 Modules linked in: tcrypt(+) crypto4xx [...]
13 CPU: 0 PID: 0 Comm: swapper Tainted: G           O      4.17.0-rc1+ #23
14 NIP:  c0012994 LR: d3077934 CTR: 06026d49
15 REGS: cfff7e30 TRAP: 0300   Tainted: G           O       (4.17.0-rc1+)
16 MSR:  00029000 <CE,EE,ME>  CR: 44744822  XER: 00000000
17 DEAR: f59b3420 ESR: 00000000
18 NIP [c0012994] __dma_sync+0x58/0x10c
19 LR [d3077934] crypto4xx_bh_tasklet_cb+0x188/0x3c8 [crypto4xx]
20
21 __dma_sync was fed the temporary _dst that crypto4xx_build_pd()
22 had in it's function stack. This clearly never worked.
23 This patch therefore overhauls the code from the original driver
24 and puts the temporary dst sg list into aead's request context.
25
26 Fixes: a0aae821ba3d3 ("crypto: crypto4xx - prepare for AEAD support")
27 Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
28 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
29 ---
30  drivers/crypto/amcc/crypto4xx_alg.c  | 15 ++++++++-------
31  drivers/crypto/amcc/crypto4xx_core.c | 10 +++++-----
32  drivers/crypto/amcc/crypto4xx_core.h |  7 ++++++-
33  3 files changed, 19 insertions(+), 13 deletions(-)
34
35 --- a/drivers/crypto/amcc/crypto4xx_alg.c
36 +++ b/drivers/crypto/amcc/crypto4xx_alg.c
37 @@ -87,7 +87,7 @@ static inline int crypto4xx_crypt(struct
38  
39         return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
40                 req->cryptlen, iv, ivlen, decrypt ? ctx->sa_in : ctx->sa_out,
41 -               ctx->sa_len, 0);
42 +               ctx->sa_len, 0, NULL);
43  }
44  
45  int crypto4xx_encrypt_noiv(struct skcipher_request *req)
46 @@ -223,7 +223,7 @@ int crypto4xx_rfc3686_encrypt(struct skc
47  
48         return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
49                                   req->cryptlen, iv, AES_IV_SIZE,
50 -                                 ctx->sa_out, ctx->sa_len, 0);
51 +                                 ctx->sa_out, ctx->sa_len, 0, NULL);
52  }
53  
54  int crypto4xx_rfc3686_decrypt(struct skcipher_request *req)
55 @@ -238,7 +238,7 @@ int crypto4xx_rfc3686_decrypt(struct skc
56  
57         return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
58                                   req->cryptlen, iv, AES_IV_SIZE,
59 -                                 ctx->sa_out, ctx->sa_len, 0);
60 +                                 ctx->sa_out, ctx->sa_len, 0, NULL);
61  }
62  
63  static int
64 @@ -449,6 +449,7 @@ int crypto4xx_setkey_aes_ccm(struct cryp
65  static int crypto4xx_crypt_aes_ccm(struct aead_request *req, bool decrypt)
66  {
67         struct crypto4xx_ctx *ctx  = crypto_tfm_ctx(req->base.tfm);
68 +       struct crypto4xx_aead_reqctx *rctx = aead_request_ctx(req);
69         struct crypto_aead *aead = crypto_aead_reqtfm(req);
70         __le32 iv[16];
71         u32 tmp_sa[SA_AES128_CCM_LEN + 4];
72 @@ -474,7 +475,7 @@ static int crypto4xx_crypt_aes_ccm(struc
73  
74         return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
75                                   len, iv, sizeof(iv),
76 -                                 sa, ctx->sa_len, req->assoclen);
77 +                                 sa, ctx->sa_len, req->assoclen, rctx->dst);
78  }
79  
80  int crypto4xx_encrypt_aes_ccm(struct aead_request *req)
81 @@ -622,7 +623,7 @@ static inline int crypto4xx_crypt_aes_gc
82         return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
83                                   len, iv, sizeof(iv),
84                                   decrypt ? ctx->sa_in : ctx->sa_out,
85 -                                 ctx->sa_len, req->assoclen);
86 +                                 ctx->sa_len, req->assoclen, rctx->dst);
87  }
88  
89  int crypto4xx_encrypt_aes_gcm(struct aead_request *req)
90 @@ -707,7 +708,7 @@ int crypto4xx_hash_update(struct ahash_r
91  
92         return crypto4xx_build_pd(&req->base, ctx, req->src, &dst,
93                                   req->nbytes, NULL, 0, ctx->sa_in,
94 -                                 ctx->sa_len, 0);
95 +                                 ctx->sa_len, 0, NULL);
96  }
97  
98  int crypto4xx_hash_final(struct ahash_request *req)
99 @@ -726,7 +727,7 @@ int crypto4xx_hash_digest(struct ahash_r
100  
101         return crypto4xx_build_pd(&req->base, ctx, req->src, &dst,
102                                   req->nbytes, NULL, 0, ctx->sa_in,
103 -                                 ctx->sa_len, 0);
104 +                                 ctx->sa_len, 0, NULL);
105  }
106  
107  /**
108 --- a/drivers/crypto/amcc/crypto4xx_core.c
109 +++ b/drivers/crypto/amcc/crypto4xx_core.c
110 @@ -695,9 +695,9 @@ int crypto4xx_build_pd(struct crypto_asy
111                        const __le32 *iv, const u32 iv_len,
112                        const struct dynamic_sa_ctl *req_sa,
113                        const unsigned int sa_len,
114 -                      const unsigned int assoclen)
115 +                      const unsigned int assoclen,
116 +                      struct scatterlist *_dst)
117  {
118 -       struct scatterlist _dst[2];
119         struct crypto4xx_device *dev = ctx->dev;
120         struct dynamic_sa_ctl *sa;
121         struct ce_gd *gd;
122 @@ -996,9 +996,9 @@ static int crypto4xx_aead_init(struct cr
123  
124         amcc_alg = container_of(alg, struct crypto4xx_alg, alg.u.aead);
125         crypto4xx_ctx_init(amcc_alg, ctx);
126 -       crypto_aead_set_reqsize(tfm, sizeof(struct aead_request) +
127 -                               max(sizeof(struct crypto4xx_ctx), 32 +
128 -                               crypto_aead_reqsize(ctx->sw_cipher.aead)));
129 +       crypto_aead_set_reqsize(tfm, max(sizeof(struct aead_request) + 32 +
130 +                               crypto_aead_reqsize(ctx->sw_cipher.aead),
131 +                               sizeof(struct crypto4xx_aead_reqctx)));
132         return 0;
133  }
134  
135 --- a/drivers/crypto/amcc/crypto4xx_core.h
136 +++ b/drivers/crypto/amcc/crypto4xx_core.h
137 @@ -133,6 +133,10 @@ struct crypto4xx_ctx {
138         } sw_cipher;
139  };
140  
141 +struct crypto4xx_aead_reqctx {
142 +       struct scatterlist dst[2];
143 +};
144 +
145  struct crypto4xx_alg_common {
146         u32 type;
147         union {
148 @@ -159,7 +163,8 @@ int crypto4xx_build_pd(struct crypto_asy
149                        const __le32 *iv, const u32 iv_len,
150                        const struct dynamic_sa_ctl *sa,
151                        const unsigned int sa_len,
152 -                      const unsigned int assoclen);
153 +                      const unsigned int assoclen,
154 +                      struct scatterlist *dst_tmp);
155  int crypto4xx_setkey_aes_cbc(struct crypto_skcipher *cipher,
156                              const u8 *key, unsigned int keylen);
157  int crypto4xx_setkey_aes_cfb(struct crypto_skcipher *cipher,