2019-05-27 08:55:01 +02:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-11-05 16:58:14 +11:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
|
2007-10-19 23:06:17 +02:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-07-06 13:54:31 -07:00
|
|
|
|
2006-09-21 11:39:29 +10:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2021-09-17 08:26:19 +08:00
|
|
|
|
2005-11-05 16:58:14 +11:00
|
|
|
|
2005-07-06 13:53:09 -07:00
|
|
|
|
2006-09-21 11:31:44 +10:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
2017-02-02 19:15:33 +01:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-05 16:58:14 +11:00
|
|
|
|
2017-10-18 08:00:38 +01:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-08-21 21:08:13 +10:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-08-21 21:08:13 +10:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-05 13:33:41 -07:00
|
|
|
|
2022-11-13 16:12:35 -08:00
|
|
|
|
|
|
|
|
|
2021-09-17 08:26:19 +08:00
|
|
|
|
2025-02-14 10:31:25 +08:00
|
|
|
|
|
|
|
|
|
2024-08-17 14:56:51 +08:00
|
|
|
|
|
|
|
|
|
2013-09-08 14:33:50 +10:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
2006-08-06 20:28:44 +10:00
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2007-05-19 14:51:00 +10:00
|
|
|
|
|
|
|
|
|
2006-08-06 20:28:44 +10:00
|
|
|
|
2007-05-19 14:51:00 +10:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2008-08-04 11:44:59 +08:00
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
|
2005-11-05 16:58:14 +11:00
|
|
|
|
|
|
|
|
|
2006-09-21 11:39:29 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-09-21 11:35:17 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-11-05 16:58:14 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-05-28 09:05:24 +10:00
|
|
|
|
2005-11-05 16:58:14 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-05-28 09:05:24 +10:00
|
|
|
|
2005-11-05 16:58:14 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-12-11 10:50:11 +08:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-08-03 21:15:23 +08:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-09-21 11:39:29 +10:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
crypto: api - Fix generic algorithm self-test races
On Fri, Aug 30, 2024 at 10:51:54AM -0700, Eric Biggers wrote:
>
> Given below in defconfig form, use 'make olddefconfig' to apply. The failures
> are nondeterministic and sometimes there are different ones, for example:
>
> [ 0.358017] alg: skcipher: failed to allocate transform for cbc(twofish-generic): -2
> [ 0.358365] alg: self-tests for cbc(twofish) using cbc(twofish-generic) failed (rc=-2)
> [ 0.358535] alg: skcipher: failed to allocate transform for cbc(camellia-generic): -2
> [ 0.358918] alg: self-tests for cbc(camellia) using cbc(camellia-generic) failed (rc=-2)
> [ 0.371533] alg: skcipher: failed to allocate transform for xts(ecb(aes-generic)): -2
> [ 0.371922] alg: self-tests for xts(aes) using xts(ecb(aes-generic)) failed (rc=-2)
>
> Modules are not enabled, maybe that matters (I haven't checked yet).
Yes I think that was the key. This triggers a massive self-test
run which executes in parallel and reveals a few race conditions
in the system. I think it boils down to the following scenario:
Base algorithm X-generic, X-optimised
Template Y
Optimised algorithm Y-X-optimised
Everything gets registered, and then the self-tests are started.
When Y-X-optimised gets tested, it requests the creation of the
generic Y(X-generic). Which then itself undergoes testing.
The race is that after Y(X-generic) gets registered, but just
before it gets tested, X-optimised finally finishes self-testing
which then causes all spawns of X-generic to be destroyed. So
by the time the self-test for Y(X-generic) comes along, it can
no longer find the algorithm. This error then bubbles up all
the way up to the self-test of Y-X-optimised which then fails.
Note that there is some complexity that I've omitted here because
when the generic self-test fails to find Y(X-generic) it actually
triggers the construction of it again which then fails for various
other reasons (these are not important because the construction
should *not* be triggered at this point).
So in a way the error is expected, and we should probably remove
the pr_err for the case where ENOENT is returned for the algorithm
that we're currently testing.
The solution is two-fold. First when an algorithm undergoes
self-testing it should not trigger its construction. Secondly
if an instance larval fails to materialise due to it being destroyed
by a more optimised algorithm coming along, it should obviously
retry the construction.
Remove the check in __crypto_alg_lookup that stops a larval from
matching new requests based on differences in the mask. It is better
to block new requests even if it is wrong and then simply retry the
lookup. If this ends up being the wrong larval it will sort iself
out during the retry.
Reduce the CRYPTO_ALG_TYPE_MASK bits in type during larval creation
as otherwise LSKCIPHER algorithms may not match SKCIPHER larvals.
Also block the instance creation during self-testing in the function
crypto_larval_lookup by checking for CRYPTO_ALG_TESTED in the mask
field.
Finally change the return value when crypto_alg_lookup fails in
crypto_larval_wait to EAGAIN to redo the lookup.
Fixes: 37da5d0ffa7b ("crypto: api - Do not wait for tests during registration")
Reported-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2024-09-01 16:05:40 +08:00
|
|
|
|
|
|
|
|
|
2006-09-21 11:35:17 +10:00
|
|
|
|
|
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-08-18 22:59:54 +02:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
|
|
|
|
|
2008-08-03 21:15:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-29 10:00:46 -06:00
|
|
|
|
2008-08-03 21:15:23 +08:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
2006-09-21 11:35:17 +10:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-09-08 14:33:50 +10:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
2013-09-08 14:33:50 +10:00
|
|
|
|
2025-02-14 10:31:25 +08:00
|
|
|
|
2013-09-08 14:33:50 +10:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-08-17 14:57:40 +08:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
2024-08-17 14:57:40 +08:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
|
|
|
|
|
2024-08-17 14:57:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
2024-08-17 14:57:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-05-19 17:51:40 +10:00
|
|
|
|
2024-08-17 14:57:40 +08:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
|
|
|
|
|
2024-08-17 14:57:40 +08:00
|
|
|
|
2021-09-17 08:26:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-08-17 14:57:40 +08:00
|
|
|
|
2021-09-17 08:26:19 +08:00
|
|
|
|
2024-08-17 14:57:40 +08:00
|
|
|
|
2021-09-17 08:26:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-08-17 14:57:40 +08:00
|
|
|
|
2021-09-17 08:26:19 +08:00
|
|
|
|
|
|
|
|
|
2025-02-14 10:31:25 +08:00
|
|
|
|
|
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
2024-08-17 14:56:51 +08:00
|
|
|
|
2024-04-30 14:14:42 +02:00
|
|
|
|
2008-08-03 21:15:23 +08:00
|
|
|
|
2024-08-17 14:56:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-11-13 16:12:35 -08:00
|
|
|
|
2021-09-17 08:26:19 +08:00
|
|
|
|
|
|
|
|
|
2024-04-30 14:14:42 +02:00
|
|
|
|
2008-08-03 21:15:23 +08:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
|
|
|
|
|
2024-04-30 14:14:42 +02:00
|
|
|
|
2008-08-03 21:15:23 +08:00
|
|
|
|
2024-08-17 14:57:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-08-03 21:15:23 +08:00
|
|
|
|
2025-05-19 18:29:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-08-17 14:56:51 +08:00
|
|
|
|
|
|
|
|
|
2025-05-19 18:29:38 +08:00
|
|
|
|
2024-08-17 14:56:51 +08:00
|
|
|
|
2019-12-11 10:50:11 +08:00
|
|
|
|
2008-08-03 21:15:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
crypto: api - allow algs only in specific constructions in FIPS mode
Currently we do not distinguish between algorithms that fail on
the self-test vs. those which are disabled in FIPS mode (not allowed).
Both are marked as having failed the self-test.
Recently the need arose to allow the usage of certain algorithms only
as arguments to specific template instantiations in FIPS mode. For
example, standalone "dh" must be blocked, but e.g. "ffdhe2048(dh)" is
allowed. Other potential use cases include "cbcmac(aes)", which must
only be used with ccm(), or "ghash", which must be used only for
gcm().
This patch allows this scenario by adding a new flag FIPS_INTERNAL to
indicate those algorithms that are not FIPS-allowed. They can then be
used as template arguments only, i.e. when looked up via
crypto_grab_spawn() to be more specific. The FIPS_INTERNAL bit gets
propagated upwards recursively into the surrounding template
instances, until the construction eventually matches an explicit
testmgr entry with ->fips_allowed being set, if any.
The behaviour to skip !->fips_allowed self-test executions in FIPS
mode will be retained. Note that this effectively means that
FIPS_INTERNAL algorithms are handled very similarly to the INTERNAL
ones in this regard. It is expected that the FIPS_INTERNAL algorithms
will receive sufficient testing when the larger constructions they're
a part of, if any, get exercised by testmgr.
Note that as a side-effect of this patch algorithms which are not
FIPS-allowed will now return ENOENT instead of ELIBBAD. Hopefully
this is not an issue as some people were relying on this already.
Link: https://lore.kernel.org/r/YeEVSaMEVJb3cQkq@gondor.apana.org.au
Originally-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Nicolai Stange <nstange@suse.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2022-02-21 13:10:58 +01:00
|
|
|
|
|
|
|
|
|
2008-08-03 21:15:23 +08:00
|
|
|
|
|
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
|
|
|
|
|
2024-08-17 14:56:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-20 08:05:39 +08:00
|
|
|
|
|
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
crypto: api - allow algs only in specific constructions in FIPS mode
Currently we do not distinguish between algorithms that fail on
the self-test vs. those which are disabled in FIPS mode (not allowed).
Both are marked as having failed the self-test.
Recently the need arose to allow the usage of certain algorithms only
as arguments to specific template instantiations in FIPS mode. For
example, standalone "dh" must be blocked, but e.g. "ffdhe2048(dh)" is
allowed. Other potential use cases include "cbcmac(aes)", which must
only be used with ccm(), or "ghash", which must be used only for
gcm().
This patch allows this scenario by adding a new flag FIPS_INTERNAL to
indicate those algorithms that are not FIPS-allowed. They can then be
used as template arguments only, i.e. when looked up via
crypto_grab_spawn() to be more specific. The FIPS_INTERNAL bit gets
propagated upwards recursively into the surrounding template
instances, until the construction eventually matches an explicit
testmgr entry with ->fips_allowed being set, if any.
The behaviour to skip !->fips_allowed self-test executions in FIPS
mode will be retained. Note that this effectively means that
FIPS_INTERNAL algorithms are handled very similarly to the INTERNAL
ones in this regard. It is expected that the FIPS_INTERNAL algorithms
will receive sufficient testing when the larger constructions they're
a part of, if any, get exercised by testmgr.
Note that as a side-effect of this patch algorithms which are not
FIPS-allowed will now return ENOENT instead of ELIBBAD. Hopefully
this is not an issue as some people were relying on this already.
Link: https://lore.kernel.org/r/YeEVSaMEVJb3cQkq@gondor.apana.org.au
Originally-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Nicolai Stange <nstange@suse.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2022-02-21 13:10:58 +01:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
2018-03-20 15:52:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
|
|
|
|
|
crypto: api - allow algs only in specific constructions in FIPS mode
Currently we do not distinguish between algorithms that fail on
the self-test vs. those which are disabled in FIPS mode (not allowed).
Both are marked as having failed the self-test.
Recently the need arose to allow the usage of certain algorithms only
as arguments to specific template instantiations in FIPS mode. For
example, standalone "dh" must be blocked, but e.g. "ffdhe2048(dh)" is
allowed. Other potential use cases include "cbcmac(aes)", which must
only be used with ccm(), or "ghash", which must be used only for
gcm().
This patch allows this scenario by adding a new flag FIPS_INTERNAL to
indicate those algorithms that are not FIPS-allowed. They can then be
used as template arguments only, i.e. when looked up via
crypto_grab_spawn() to be more specific. The FIPS_INTERNAL bit gets
propagated upwards recursively into the surrounding template
instances, until the construction eventually matches an explicit
testmgr entry with ->fips_allowed being set, if any.
The behaviour to skip !->fips_allowed self-test executions in FIPS
mode will be retained. Note that this effectively means that
FIPS_INTERNAL algorithms are handled very similarly to the INTERNAL
ones in this regard. It is expected that the FIPS_INTERNAL algorithms
will receive sufficient testing when the larger constructions they're
a part of, if any, get exercised by testmgr.
Note that as a side-effect of this patch algorithms which are not
FIPS-allowed will now return ENOENT instead of ELIBBAD. Hopefully
this is not an issue as some people were relying on this already.
Link: https://lore.kernel.org/r/YeEVSaMEVJb3cQkq@gondor.apana.org.au
Originally-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Nicolai Stange <nstange@suse.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2022-02-21 13:10:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-16 16:59:13 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-07 10:55:59 -08:00
|
|
|
|
|
|
|
|
|
2005-07-06 13:53:09 -07:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
|
|
|
|
|
2006-09-21 11:39:29 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-11-22 20:08:21 +08:00
|
|
|
|
2006-09-21 11:39:29 +10:00
|
|
|
|
2006-09-21 11:35:17 +10:00
|
|
|
|
2009-02-26 14:06:31 +08:00
|
|
|
|
2018-06-08 14:57:42 -07:00
|
|
|
|
2014-11-20 17:05:53 -08:00
|
|
|
|
2009-02-26 14:06:31 +08:00
|
|
|
|
2009-04-21 13:27:16 +08:00
|
|
|
|
2009-06-02 14:13:14 +10:00
|
|
|
|
2014-11-20 17:05:53 -08:00
|
|
|
|
2009-02-26 14:06:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-20 15:52:45 +08:00
|
|
|
|
2025-02-14 10:31:25 +08:00
|
|
|
|
crypto: api - Fix generic algorithm self-test races
On Fri, Aug 30, 2024 at 10:51:54AM -0700, Eric Biggers wrote:
>
> Given below in defconfig form, use 'make olddefconfig' to apply. The failures
> are nondeterministic and sometimes there are different ones, for example:
>
> [ 0.358017] alg: skcipher: failed to allocate transform for cbc(twofish-generic): -2
> [ 0.358365] alg: self-tests for cbc(twofish) using cbc(twofish-generic) failed (rc=-2)
> [ 0.358535] alg: skcipher: failed to allocate transform for cbc(camellia-generic): -2
> [ 0.358918] alg: self-tests for cbc(camellia) using cbc(camellia-generic) failed (rc=-2)
> [ 0.371533] alg: skcipher: failed to allocate transform for xts(ecb(aes-generic)): -2
> [ 0.371922] alg: self-tests for xts(aes) using xts(ecb(aes-generic)) failed (rc=-2)
>
> Modules are not enabled, maybe that matters (I haven't checked yet).
Yes I think that was the key. This triggers a massive self-test
run which executes in parallel and reveals a few race conditions
in the system. I think it boils down to the following scenario:
Base algorithm X-generic, X-optimised
Template Y
Optimised algorithm Y-X-optimised
Everything gets registered, and then the self-tests are started.
When Y-X-optimised gets tested, it requests the creation of the
generic Y(X-generic). Which then itself undergoes testing.
The race is that after Y(X-generic) gets registered, but just
before it gets tested, X-optimised finally finishes self-testing
which then causes all spawns of X-generic to be destroyed. So
by the time the self-test for Y(X-generic) comes along, it can
no longer find the algorithm. This error then bubbles up all
the way up to the self-test of Y-X-optimised which then fails.
Note that there is some complexity that I've omitted here because
when the generic self-test fails to find Y(X-generic) it actually
triggers the construction of it again which then fails for various
other reasons (these are not important because the construction
should *not* be triggered at this point).
So in a way the error is expected, and we should probably remove
the pr_err for the case where ENOENT is returned for the algorithm
that we're currently testing.
The solution is two-fold. First when an algorithm undergoes
self-testing it should not trigger its construction. Secondly
if an instance larval fails to materialise due to it being destroyed
by a more optimised algorithm coming along, it should obviously
retry the construction.
Remove the check in __crypto_alg_lookup that stops a larval from
matching new requests based on differences in the mask. It is better
to block new requests even if it is wrong and then simply retry the
lookup. If this ends up being the wrong larval it will sort iself
out during the retry.
Reduce the CRYPTO_ALG_TYPE_MASK bits in type during larval creation
as otherwise LSKCIPHER algorithms may not match SKCIPHER larvals.
Also block the instance creation during self-testing in the function
crypto_larval_lookup by checking for CRYPTO_ALG_TESTED in the mask
field.
Finally change the return value when crypto_alg_lookup fails in
crypto_larval_wait to EAGAIN to redo the lookup.
Fixes: 37da5d0ffa7b ("crypto: api - Do not wait for tests during registration")
Reported-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2024-09-01 16:05:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-20 15:52:45 +08:00
|
|
|
|
crypto: api - Fix generic algorithm self-test races
On Fri, Aug 30, 2024 at 10:51:54AM -0700, Eric Biggers wrote:
>
> Given below in defconfig form, use 'make olddefconfig' to apply. The failures
> are nondeterministic and sometimes there are different ones, for example:
>
> [ 0.358017] alg: skcipher: failed to allocate transform for cbc(twofish-generic): -2
> [ 0.358365] alg: self-tests for cbc(twofish) using cbc(twofish-generic) failed (rc=-2)
> [ 0.358535] alg: skcipher: failed to allocate transform for cbc(camellia-generic): -2
> [ 0.358918] alg: self-tests for cbc(camellia) using cbc(camellia-generic) failed (rc=-2)
> [ 0.371533] alg: skcipher: failed to allocate transform for xts(ecb(aes-generic)): -2
> [ 0.371922] alg: self-tests for xts(aes) using xts(ecb(aes-generic)) failed (rc=-2)
>
> Modules are not enabled, maybe that matters (I haven't checked yet).
Yes I think that was the key. This triggers a massive self-test
run which executes in parallel and reveals a few race conditions
in the system. I think it boils down to the following scenario:
Base algorithm X-generic, X-optimised
Template Y
Optimised algorithm Y-X-optimised
Everything gets registered, and then the self-tests are started.
When Y-X-optimised gets tested, it requests the creation of the
generic Y(X-generic). Which then itself undergoes testing.
The race is that after Y(X-generic) gets registered, but just
before it gets tested, X-optimised finally finishes self-testing
which then causes all spawns of X-generic to be destroyed. So
by the time the self-test for Y(X-generic) comes along, it can
no longer find the algorithm. This error then bubbles up all
the way up to the self-test of Y-X-optimised which then fails.
Note that there is some complexity that I've omitted here because
when the generic self-test fails to find Y(X-generic) it actually
triggers the construction of it again which then fails for various
other reasons (these are not important because the construction
should *not* be triggered at this point).
So in a way the error is expected, and we should probably remove
the pr_err for the case where ENOENT is returned for the algorithm
that we're currently testing.
The solution is two-fold. First when an algorithm undergoes
self-testing it should not trigger its construction. Secondly
if an instance larval fails to materialise due to it being destroyed
by a more optimised algorithm coming along, it should obviously
retry the construction.
Remove the check in __crypto_alg_lookup that stops a larval from
matching new requests based on differences in the mask. It is better
to block new requests even if it is wrong and then simply retry the
lookup. If this ends up being the wrong larval it will sort iself
out during the retry.
Reduce the CRYPTO_ALG_TYPE_MASK bits in type during larval creation
as otherwise LSKCIPHER algorithms may not match SKCIPHER larvals.
Also block the instance creation during self-testing in the function
crypto_larval_lookup by checking for CRYPTO_ALG_TESTED in the mask
field.
Finally change the return value when crypto_alg_lookup fails in
crypto_larval_wait to EAGAIN to redo the lookup.
Fixes: 37da5d0ffa7b ("crypto: api - Do not wait for tests during registration")
Reported-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2024-09-01 16:05:40 +08:00
|
|
|
|
|
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
2018-03-20 15:52:45 +08:00
|
|
|
|
2007-12-04 12:46:48 +11:00
|
|
|
|
|
|
|
|
|
2008-08-03 21:15:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-12-04 12:46:48 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-30 21:55:52 +02:00
|
|
|
|
|
|
|
|
|
2022-08-11 20:13:49 +08:00
|
|
|
|
2015-03-30 21:55:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-12-04 12:46:48 +11:00
|
|
|
|
2006-09-21 11:39:29 +10:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
|
|
|
|
|
2008-08-03 21:15:23 +08:00
|
|
|
|
2006-09-21 11:31:44 +10:00
|
|
|
|
|
|
|
|
|
2025-02-14 10:31:25 +08:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
|
|
|
|
|
2006-09-21 11:39:29 +10:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
2024-08-17 14:57:40 +08:00
|
|
|
|
2006-08-06 21:23:26 +10:00
|
|
|
|
2005-07-06 13:53:09 -07:00
|
|
|
|
2006-09-21 11:35:17 +10:00
|
|
|
|
2005-07-06 13:53:09 -07:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
|
2006-08-22 00:06:54 +10:00
|
|
|
|
|
|
|
|
|
2016-10-07 14:13:35 -07:00
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
|
2007-01-24 20:50:26 +11:00
|
|
|
|
2005-07-06 13:53:29 -07:00
|
|
|
|
2007-01-24 20:50:26 +11:00
|
|
|
|
2005-07-06 13:53:29 -07:00
|
|
|
|
|
|
|
|
|
2006-08-22 00:06:54 +10:00
|
|
|
|
2007-01-24 20:50:26 +11:00
|
|
|
|
|
|
|
|
|
2006-08-22 00:06:54 +10:00
|
|
|
|
2005-07-06 13:53:29 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-01-27 10:05:15 +11:00
|
|
|
|
2005-07-06 13:53:29 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-08-22 00:06:54 +10:00
|
|
|
|
2005-07-06 13:53:29 -07:00
|
|
|
|
|
|
|
|
|
2020-04-10 16:09:42 +10:00
|
|
|
|
2006-09-21 11:39:29 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-10 16:09:42 +10:00
|
|
|
|
2006-09-21 11:39:29 +10:00
|
|
|
|
2023-06-15 17:00:51 +08:00
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2023-09-14 02:17:27 +08:00
|
|
|
|
2005-07-06 13:53:29 -07:00
|
|
|
|
2006-09-21 11:39:29 +10:00
|
|
|
|
2005-07-06 13:53:29 -07:00
|
|
|
|
2007-01-24 20:50:26 +11:00
|
|
|
|
2023-06-15 17:00:51 +08:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-10-11 22:29:51 +10:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
|
2023-04-13 14:24:15 +08:00
|
|
|
|
2006-09-21 11:39:29 +10:00
|
|
|
|
2008-09-13 18:19:03 -07:00
|
|
|
|
2006-05-24 13:02:26 +10:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-05-24 13:02:26 +10:00
|
|
|
|
|
|
|
|
|
2008-09-13 18:19:03 -07:00
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-10-11 22:29:51 +10:00
|
|
|
|
2006-09-21 11:39:29 +10:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-15 17:00:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-09-21 11:39:29 +10:00
|
|
|
|
|
|
|
|
|
2006-07-30 11:53:01 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
2013-06-28 15:56:20 +03:00
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
2006-07-30 11:53:01 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
crypto: skcipher - remove the "blkcipher" algorithm type
Now that all "blkcipher" algorithms have been converted to "skcipher",
remove the blkcipher algorithm type.
The skcipher (symmetric key cipher) algorithm type was introduced a few
years ago to replace both blkcipher and ablkcipher (synchronous and
asynchronous block cipher). The advantages of skcipher include:
- A much less confusing name, since none of these algorithm types have
ever actually been for raw block ciphers, but rather for all
length-preserving encryption modes including block cipher modes of
operation, stream ciphers, and other length-preserving modes.
- It unified blkcipher and ablkcipher into a single algorithm type
which supports both synchronous and asynchronous implementations.
Note, blkcipher already operated only on scatterlists, so the fact
that skcipher does too isn't a regression in functionality.
- Better type safety by using struct skcipher_alg, struct
crypto_skcipher, etc. instead of crypto_alg, crypto_tfm, etc.
- It sometimes simplifies the implementations of algorithms.
Also, the blkcipher API was no longer being tested.
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2019-10-25 12:41:12 -07:00
|
|
|
|
2006-07-30 11:53:01 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-10-11 22:29:51 +10:00
|
|
|
|
|
|
|
|
|
2006-07-30 11:53:01 +10:00
|
|
|
|
2006-10-11 22:29:51 +10:00
|
|
|
|
2006-07-30 11:53:01 +10:00
|
|
|
|
2007-01-24 20:50:26 +11:00
|
|
|
|
2006-07-30 11:53:01 +10:00
|
|
|
|
2006-10-11 22:29:51 +10:00
|
|
|
|
2006-07-30 11:53:01 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-19 18:23:57 +08:00
|
|
|
|
2006-07-30 11:53:01 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-10-11 22:29:51 +10:00
|
|
|
|
2006-07-30 11:53:01 +10:00
|
|
|
|
2006-10-11 22:29:51 +10:00
|
|
|
|
2006-07-30 11:53:01 +10:00
|
|
|
|
|
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
2023-04-13 14:24:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
2023-04-13 14:24:17 +08:00
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
|
|
|
|
|
2023-04-13 14:24:17 +08:00
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
|
|
|
|
|
2009-07-13 20:46:25 +08:00
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
2023-04-13 14:24:17 +08:00
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
2023-04-13 14:24:17 +08:00
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-05 21:18:58 +12:00
|
|
|
|
2023-04-13 14:24:15 +08:00
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
2023-04-13 14:24:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-23 17:22:28 +08:00
|
|
|
|
2023-04-13 14:24:17 +08:00
|
|
|
|
2009-07-13 20:46:25 +08:00
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-02-18 16:56:59 +08:00
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
2009-02-18 16:56:59 +08:00
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
2020-07-05 21:18:58 +12:00
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
2023-04-13 14:24:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-23 17:22:31 +08:00
|
|
|
|
2023-04-13 14:24:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-08 17:53:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-20 07:41:00 +08:00
|
|
|
|
2009-07-08 17:53:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
2020-07-05 21:18:58 +12:00
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-05 21:18:58 +12:00
|
|
|
|
|
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-11-29 10:16:48 -08:00
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-05 21:18:58 +12:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
2009-02-18 16:56:59 +08:00
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-08 17:53:16 +08:00
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-05 21:18:58 +12:00
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-19 18:23:57 +08:00
|
|
|
|
2008-09-21 06:52:53 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-05 21:18:58 +12:00
|
|
|
|
2009-02-05 16:48:24 +11:00
|
|
|
|
2006-07-30 11:53:01 +10:00
|
|
|
|
2009-02-05 16:48:24 +11:00
|
|
|
|
|
|
|
|
|
2006-07-30 11:53:01 +10:00
|
|
|
|
|
|
|
|
|
2009-02-05 16:48:24 +11:00
|
|
|
|
2006-07-30 11:53:01 +10:00
|
|
|
|
|
|
|
|
|
2009-02-05 16:48:24 +11:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-07-06 13:54:31 -07:00
|
|
|
|
|
|
|
|
|
2021-03-02 21:33:03 +01:00
|
|
|
|
2005-07-06 13:54:31 -07:00
|
|
|
|
|
|
|
|
|
2023-04-13 14:24:15 +08:00
|
|
|
|
|
|
|
|
|
2005-07-06 13:54:31 -07:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2008-09-13 18:19:03 -07:00
|
|
|
|
2006-05-24 13:02:26 +10:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-05-28 09:05:24 +10:00
|
|
|
|
2020-08-06 23:18:13 -07:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2009-02-05 16:48:24 +11:00
|
|
|
|
2006-08-26 17:35:45 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-02-16 20:26:46 +08:00
|
|
|
|
2006-08-26 17:35:45 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-02-16 20:26:46 +08:00
|
|
|
|
2006-08-26 17:35:45 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-03-30 16:36:09 +08:00
|
|
|
|
2023-02-08 13:58:44 +08:00
|
|
|
|
2017-10-18 08:00:38 +01:00
|
|
|
|
2023-02-08 13:58:44 +08:00
|
|
|
|
2017-10-18 08:00:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-12 13:16:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-23 17:22:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-03-30 16:36:09 +08:00
|
|
|
|
|
|
|
|
|