From: Herbert Xu Date: Fri, 6 Dec 2019 05:55:17 +0000 (+0800) Subject: crypto: api - Check spawn->alg under lock in crypto_drop_spawn X-Git-Tag: v4.19.103~123 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=12fa296ad27e784d8a9201c953a3e3b2542a75b1;p=thirdparty%2Fkernel%2Fstable.git crypto: api - Check spawn->alg under lock in crypto_drop_spawn commit 7db3b61b6bba4310f454588c2ca6faf2958ad79f upstream. We need to check whether spawn->alg is NULL under lock as otherwise the algorithm could be removed from under us after we have checked it and found it to be non-NULL. This could cause us to remove the spawn from a non-existent list. Fixes: 7ede5a5ba55a ("crypto: api - Fix crypto_drop_spawn crash...") Cc: Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- diff --git a/crypto/algapi.c b/crypto/algapi.c index c0755cf4f53f8..6d578b7e59a42 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -649,11 +649,9 @@ EXPORT_SYMBOL_GPL(crypto_grab_spawn); void crypto_drop_spawn(struct crypto_spawn *spawn) { - if (!spawn->alg) - return; - down_write(&crypto_alg_sem); - list_del(&spawn->list); + if (spawn->alg) + list_del(&spawn->list); up_write(&crypto_alg_sem); } EXPORT_SYMBOL_GPL(crypto_drop_spawn);