aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2019-06-17 09:25:17 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2019-06-27 02:28:01 -0400
commit8d3bcb9900ca5a193088c1f2d20c92865482368b (patch)
treeeeba8c1cb0e3e3251dbf4253fcb259fb8c54776a
parent303f99ac9470a92c06fec1dfb5f263fbc26eb8f4 (diff)
crypto: sun4i-ss - reduce stack usage
After the latest addition, the stack usage of sun4i_ss_cipher_poll grew beyond the warning limit when KASAN is enabled: drivers/crypto/sunxi-ss/sun4i-ss-cipher.c:118:12: error: stack frame size of 1152 bytes in function 'sun4i_ss_cipher_poll' [-Werror,-Wframe-larger-than=] static int sun4i_ss_cipher_poll(struct skcipher_request *areq) Reduce it in three ways: - split out the new code into a separate function so its stack usage can overlap that of the sun4i_ss_opti_poll() code path - mark both special cases as noinline_for_stack, which should ideally result in a tail call that frees the rest of the stack - move the buf and obuf variables into the code blocks in which they are used. The three separate functions now use 144, 640 and 304 bytes of kernel stack, respectively. Fixes: 0ae1f46c55f8 ("crypto: sun4i-ss - fallback when length is not multiple of blocksize") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Tested-by: Corentin LABBE <clabbe.montjoie@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--drivers/crypto/sunxi-ss/sun4i-ss-cipher.c47
1 files changed, 30 insertions, 17 deletions
diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
index b060a0810934..e87717e1e00a 100644
--- a/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
+++ b/drivers/crypto/sunxi-ss/sun4i-ss-cipher.c
@@ -16,7 +16,7 @@
16 */ 16 */
17#include "sun4i-ss.h" 17#include "sun4i-ss.h"
18 18
19static int sun4i_ss_opti_poll(struct skcipher_request *areq) 19static int noinline_for_stack sun4i_ss_opti_poll(struct skcipher_request *areq)
20{ 20{
21 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); 21 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq);
22 struct sun4i_tfm_ctx *op = crypto_skcipher_ctx(tfm); 22 struct sun4i_tfm_ctx *op = crypto_skcipher_ctx(tfm);
@@ -118,6 +118,29 @@ release_ss:
118 return err; 118 return err;
119} 119}
120 120
121
122static int noinline_for_stack sun4i_ss_cipher_poll_fallback(struct skcipher_request *areq)
123{
124 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq);
125 struct sun4i_tfm_ctx *op = crypto_skcipher_ctx(tfm);
126 struct sun4i_cipher_req_ctx *ctx = skcipher_request_ctx(areq);
127 SYNC_SKCIPHER_REQUEST_ON_STACK(subreq, op->fallback_tfm);
128 int err;
129
130 skcipher_request_set_sync_tfm(subreq, op->fallback_tfm);
131 skcipher_request_set_callback(subreq, areq->base.flags, NULL,
132 NULL);
133 skcipher_request_set_crypt(subreq, areq->src, areq->dst,
134 areq->cryptlen, areq->iv);
135 if (ctx->mode & SS_DECRYPTION)
136 err = crypto_skcipher_decrypt(subreq);
137 else
138 err = crypto_skcipher_encrypt(subreq);
139 skcipher_request_zero(subreq);
140
141 return err;
142}
143
121/* Generic function that support SG with size not multiple of 4 */ 144/* Generic function that support SG with size not multiple of 4 */
122static int sun4i_ss_cipher_poll(struct skcipher_request *areq) 145static int sun4i_ss_cipher_poll(struct skcipher_request *areq)
123{ 146{
@@ -144,8 +167,6 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq)
144 unsigned int todo; 167 unsigned int todo;
145 struct sg_mapping_iter mi, mo; 168 struct sg_mapping_iter mi, mo;
146 unsigned int oi, oo; /* offset for in and out */ 169 unsigned int oi, oo; /* offset for in and out */
147 char buf[4 * SS_RX_MAX];/* buffer for linearize SG src */
148 char bufo[4 * SS_TX_MAX]; /* buffer for linearize SG dst */
149 unsigned int ob = 0; /* offset in buf */ 170 unsigned int ob = 0; /* offset in buf */
150 unsigned int obo = 0; /* offset in bufo*/ 171 unsigned int obo = 0; /* offset in bufo*/
151 unsigned int obl = 0; /* length of data in bufo */ 172 unsigned int obl = 0; /* length of data in bufo */
@@ -182,20 +203,8 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq)
182 if (no_chunk == 1 && !need_fallback) 203 if (no_chunk == 1 && !need_fallback)
183 return sun4i_ss_opti_poll(areq); 204 return sun4i_ss_opti_poll(areq);
184 205
185 if (need_fallback) { 206 if (need_fallback)
186 SYNC_SKCIPHER_REQUEST_ON_STACK(subreq, op->fallback_tfm); 207 return sun4i_ss_cipher_poll_fallback(areq);
187 skcipher_request_set_sync_tfm(subreq, op->fallback_tfm);
188 skcipher_request_set_callback(subreq, areq->base.flags, NULL,
189 NULL);
190 skcipher_request_set_crypt(subreq, areq->src, areq->dst,
191 areq->cryptlen, areq->iv);
192 if (ctx->mode & SS_DECRYPTION)
193 err = crypto_skcipher_decrypt(subreq);
194 else
195 err = crypto_skcipher_encrypt(subreq);
196 skcipher_request_zero(subreq);
197 return err;
198 }
199 208
200 spin_lock_irqsave(&ss->slock, flags); 209 spin_lock_irqsave(&ss->slock, flags);
201 210
@@ -228,6 +237,8 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq)
228 237
229 while (oleft) { 238 while (oleft) {
230 if (ileft) { 239 if (ileft) {
240 char buf[4 * SS_RX_MAX];/* buffer for linearize SG src */
241
231 /* 242 /*
232 * todo is the number of consecutive 4byte word that we 243 * todo is the number of consecutive 4byte word that we
233 * can read from current SG 244 * can read from current SG
@@ -285,6 +296,8 @@ static int sun4i_ss_cipher_poll(struct skcipher_request *areq)
285 oo = 0; 296 oo = 0;
286 } 297 }
287 } else { 298 } else {
299 char bufo[4 * SS_TX_MAX]; /* buffer for linearize SG dst */
300
288 /* 301 /*
289 * read obl bytes in bufo, we read at maximum for 302 * read obl bytes in bufo, we read at maximum for
290 * emptying the device 303 * emptying the device