summaryrefslogtreecommitdiffstats
path: root/crypto/cfb.c
diff options
context:
space:
mode:
authorPan Bian <bianpan2016@163.com>2018-11-22 05:00:16 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2018-11-29 01:53:59 -0500
commite5bde04ccce64d808f8b00a489a1fe5825d285cb (patch)
treeff071a695559c7343c9ca04744794332368e0ecd /crypto/cfb.c
parent9f4debe38415583086ce814798eeb864aeb39551 (diff)
crypto: do not free algorithm before using
In multiple functions, the algorithm fields are read after its reference is dropped through crypto_mod_put. In this case, the algorithm memory may be freed, resulting in use-after-free bugs. This patch delays the put operation until the algorithm is never used. Fixes: 79c65d179a40 ("crypto: cbc - Convert to skcipher") Fixes: a7d85e06ed80 ("crypto: cfb - add support for Cipher FeedBack mode") Fixes: 043a44001b9e ("crypto: pcbc - Convert to skcipher") Cc: <stable@vger.kernel.org> Signed-off-by: Pan Bian <bianpan2016@163.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/cfb.c')
-rw-r--r--crypto/cfb.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/crypto/cfb.c b/crypto/cfb.c
index a0d68c09e1b9..20987d0e09d8 100644
--- a/crypto/cfb.c
+++ b/crypto/cfb.c
@@ -286,9 +286,8 @@ static int crypto_cfb_create(struct crypto_template *tmpl, struct rtattr **tb)
286 spawn = skcipher_instance_ctx(inst); 286 spawn = skcipher_instance_ctx(inst);
287 err = crypto_init_spawn(spawn, alg, skcipher_crypto_instance(inst), 287 err = crypto_init_spawn(spawn, alg, skcipher_crypto_instance(inst),
288 CRYPTO_ALG_TYPE_MASK); 288 CRYPTO_ALG_TYPE_MASK);
289 crypto_mod_put(alg);
290 if (err) 289 if (err)
291 goto err_free_inst; 290 goto err_put_alg;
292 291
293 err = crypto_inst_setname(skcipher_crypto_instance(inst), "cfb", alg); 292 err = crypto_inst_setname(skcipher_crypto_instance(inst), "cfb", alg);
294 if (err) 293 if (err)
@@ -317,12 +316,15 @@ static int crypto_cfb_create(struct crypto_template *tmpl, struct rtattr **tb)
317 err = skcipher_register_instance(tmpl, inst); 316 err = skcipher_register_instance(tmpl, inst);
318 if (err) 317 if (err)
319 goto err_drop_spawn; 318 goto err_drop_spawn;
319 crypto_mod_put(alg);
320 320
321out: 321out:
322 return err; 322 return err;
323 323
324err_drop_spawn: 324err_drop_spawn:
325 crypto_drop_spawn(spawn); 325 crypto_drop_spawn(spawn);
326err_put_alg:
327 crypto_mod_put(alg);
326err_free_inst: 328err_free_inst:
327 kfree(inst); 329 kfree(inst);
328 goto out; 330 goto out;