]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
crypto: algapi - require cra_name and cra_driver_name
authorEric Biggers <ebiggers@google.com>
Mon, 3 Jun 2019 05:40:58 +0000 (22:40 -0700)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 13 Jun 2019 06:31:40 +0000 (14:31 +0800)
Now that all algorithms explicitly set cra_driver_name, make it required
for algorithm registration and remove the code that generated a default
cra_driver_name.

Also add an explicit check that cra_name is set too, since that's
obviously required too, yet it didn't seem to be checked anywhere.

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

index 7c51f45d1cf1649c9c2894b0d6ea0d48b2516436..5278e139a161e97b9888c40c3f554f3c360a243e 100644 (file)
 
 static LIST_HEAD(crypto_template_list);
 
-static inline int crypto_set_driver_name(struct crypto_alg *alg)
-{
-       static const char suffix[] = "-generic";
-       char *driver_name = alg->cra_driver_name;
-       int len;
-
-       if (*driver_name)
-               return 0;
-
-       len = strlcpy(driver_name, alg->cra_name, CRYPTO_MAX_ALG_NAME);
-       if (len + sizeof(suffix) > CRYPTO_MAX_ALG_NAME)
-               return -ENAMETOOLONG;
-
-       memcpy(driver_name + len, suffix, sizeof(suffix));
-       return 0;
-}
-
 static inline void crypto_check_module_sig(struct module *mod)
 {
        if (fips_enabled && mod && !module_sig_ok(mod))
@@ -54,6 +37,9 @@ static int crypto_check_alg(struct crypto_alg *alg)
 {
        crypto_check_module_sig(alg->cra_module);
 
+       if (!alg->cra_name[0] || !alg->cra_driver_name[0])
+               return -EINVAL;
+
        if (alg->cra_alignmask & (alg->cra_alignmask + 1))
                return -EINVAL;
 
@@ -79,7 +65,7 @@ static int crypto_check_alg(struct crypto_alg *alg)
 
        refcount_set(&alg->cra_refcnt, 1);
 
-       return crypto_set_driver_name(alg);
+       return 0;
 }
 
 static void crypto_free_instance(struct crypto_instance *inst)