crypto: algapi - reject NULL crypto_spawn::inst
authorEric Biggers <ebiggers@google.com>
Sun, 6 Jan 2019 20:46:06 +0000 (12:46 -0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 11 Jan 2019 06:16:58 +0000 (14:16 +0800)
It took me a while to notice the bug where the adiantum template left
crypto_spawn::inst == NULL, because this only caused problems in certain
cases where algorithms are dynamically loaded/unloaded.

More improvements are needed, but for now make crypto_init_spawn()
reject this case and WARN(), so this type of bug will be noticed
immediately in the future.

Note: I checked all callers and the adiantum template was the only place
that had this wrong.  So this WARN shouldn't trigger anymore.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/algapi.c

index f3d766312bd96a88bd84bf27b2529f7761b6df65..713baabeb64386e1cbf5165d5d3d2b4b001de853 100644 (file)
@@ -608,6 +608,9 @@ int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg,
 {
        int err = -EAGAIN;
 
+       if (WARN_ON_ONCE(inst == NULL))
+               return -EINVAL;
+
        spawn->inst = inst;
        spawn->mask = mask;