]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
crypto: api - Check spawn->alg under lock in crypto_drop_spawn
authorHerbert Xu <herbert@gondor.apana.org.au>
Fri, 6 Dec 2019 05:55:17 +0000 (13:55 +0800)
committerKhalid Elmously <khalid.elmously@canonical.com>
Fri, 13 Mar 2020 04:31:00 +0000 (00:31 -0400)
BugLink: https://bugs.launchpad.net/bugs/1866678
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: <stable@vger.kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
crypto/algapi.c

index 9a636f961572b99af844b1d8a28bebfd9463c9e2..f4d8deff5fcdd63f02fa04ee0286dea9314b2f4f 100644 (file)
@@ -652,11 +652,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);