Commit 2eb27c11 authored by Eric Biggers's avatar Eric Biggers Committed by Herbert Xu

crypto: algapi - add NEED_FALLBACK to INHERITED_FLAGS

CRYPTO_ALG_NEED_FALLBACK is handled inconsistently.  When it's requested
to be clear, some templates propagate that request to child algorithms,
while others don't.

It's apparently desired for NEED_FALLBACK to be propagated, to avoid
deadlocks where a module tries to load itself while it's being
initialized, and to avoid unnecessarily complex fallback chains where we
have e.g. cbc-aes-$driver falling back to cbc(aes-$driver) where
aes-$driver itself falls back to aes-generic, instead of cbc-aes-$driver
simply falling back to cbc(aes-generic).  There have been a number of
fixes to this effect:

commit 89027579 ("crypto: xts - Propagate NEED_FALLBACK bit")
commit d2c2a85c ("crypto: ctr - Propagate NEED_FALLBACK bit")
commit e6c2e65c ("crypto: cbc - Propagate NEED_FALLBACK bit")

But it seems that other templates can have the same problems too.

To avoid this whack-a-mole, just add NEED_FALLBACK to INHERITED_FLAGS so
that it's always inherited.
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 7bcb2c99
...@@ -265,8 +265,6 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl, ...@@ -265,8 +265,6 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl,
err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SKCIPHER, &mask); err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SKCIPHER, &mask);
if (err) if (err)
return err; return err;
mask |= crypto_requires_off(crypto_get_attr_type(tb),
CRYPTO_ALG_NEED_FALLBACK);
inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
if (!inst) if (!inst)
......
...@@ -943,8 +943,6 @@ struct skcipher_instance *skcipher_alloc_instance_simple( ...@@ -943,8 +943,6 @@ struct skcipher_instance *skcipher_alloc_instance_simple(
err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SKCIPHER, &mask); err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SKCIPHER, &mask);
if (err) if (err)
return ERR_PTR(err); return ERR_PTR(err);
mask |= crypto_requires_off(crypto_get_attr_type(tb),
CRYPTO_ALG_NEED_FALLBACK);
inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
if (!inst) if (!inst)
......
...@@ -340,8 +340,6 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb) ...@@ -340,8 +340,6 @@ static int create(struct crypto_template *tmpl, struct rtattr **tb)
err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SKCIPHER, &mask); err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SKCIPHER, &mask);
if (err) if (err)
return err; return err;
mask |= crypto_requires_off(crypto_get_attr_type(tb),
CRYPTO_ALG_NEED_FALLBACK);
cipher_name = crypto_attr_alg_name(tb[1]); cipher_name = crypto_attr_alg_name(tb[1]);
if (IS_ERR(cipher_name)) if (IS_ERR(cipher_name))
......
...@@ -245,7 +245,8 @@ static inline u32 crypto_requires_off(struct crypto_attr_type *algt, u32 off) ...@@ -245,7 +245,8 @@ static inline u32 crypto_requires_off(struct crypto_attr_type *algt, u32 off)
* template), these are the flags that should always be set on the "outer" * template), these are the flags that should always be set on the "outer"
* algorithm if any "inner" algorithm has them set. * algorithm if any "inner" algorithm has them set.
*/ */
#define CRYPTO_ALG_INHERITED_FLAGS CRYPTO_ALG_ASYNC #define CRYPTO_ALG_INHERITED_FLAGS \
(CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK)
/* /*
* Given the type and mask that specify the flags restrictions on a template * Given the type and mask that specify the flags restrictions on a template
......
...@@ -60,8 +60,8 @@ ...@@ -60,8 +60,8 @@
#define CRYPTO_ALG_ASYNC 0x00000080 #define CRYPTO_ALG_ASYNC 0x00000080
/* /*
* Set this bit if and only if the algorithm requires another algorithm of * Set if the algorithm (or an algorithm which it uses) requires another
* the same type to handle corner cases. * algorithm of the same type to handle corner cases.
*/ */
#define CRYPTO_ALG_NEED_FALLBACK 0x00000100 #define CRYPTO_ALG_NEED_FALLBACK 0x00000100
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment