Skip to content

Commit 0fa5248

Browse files
committed
Merge tag 'v6.16-p5' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto fixes from Herbert Xu: "This fixes a regression in ahash (broken fallback finup) and reinstates a Kconfig option to control the extra self-tests" * tag 'v6.16-p5' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: crypto: ahash - Fix infinite recursion in ahash_def_finup crypto: testmgr - reinstate kconfig control over full self-tests
2 parents 41687a5 + df29f60 commit 0fa5248

File tree

5 files changed

+41
-11
lines changed

5 files changed

+41
-11
lines changed

crypto/Kconfig

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,33 @@ config CRYPTO_USER
176176

177177
config CRYPTO_SELFTESTS
178178
bool "Enable cryptographic self-tests"
179-
depends on DEBUG_KERNEL
179+
depends on EXPERT
180180
help
181181
Enable the cryptographic self-tests.
182182

183183
The cryptographic self-tests run at boot time, or at algorithm
184184
registration time if algorithms are dynamically loaded later.
185185

186-
This is primarily intended for developer use. It should not be
187-
enabled in production kernels, unless you are trying to use these
188-
tests to fulfill a FIPS testing requirement.
186+
There are two main use cases for these tests:
187+
188+
- Development and pre-release testing. In this case, also enable
189+
CRYPTO_SELFTESTS_FULL to get the full set of tests. All crypto code
190+
in the kernel is expected to pass the full set of tests.
191+
192+
- Production kernels, to help prevent buggy drivers from being used
193+
and/or meet FIPS 140-3 pre-operational testing requirements. In
194+
this case, enable CRYPTO_SELFTESTS but not CRYPTO_SELFTESTS_FULL.
195+
196+
config CRYPTO_SELFTESTS_FULL
197+
bool "Enable the full set of cryptographic self-tests"
198+
depends on CRYPTO_SELFTESTS
199+
help
200+
Enable the full set of cryptographic self-tests for each algorithm.
201+
202+
The full set of tests should be enabled for development and
203+
pre-release testing, but not in production kernels.
204+
205+
All crypto code in the kernel is expected to pass the full tests.
189206

190207
config CRYPTO_NULL
191208
tristate "Null algorithms"

crypto/ahash.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,12 +600,14 @@ static void ahash_def_finup_done2(void *data, int err)
600600

601601
static int ahash_def_finup_finish1(struct ahash_request *req, int err)
602602
{
603+
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
604+
603605
if (err)
604606
goto out;
605607

606608
req->base.complete = ahash_def_finup_done2;
607609

608-
err = crypto_ahash_final(req);
610+
err = crypto_ahash_alg(tfm)->final(req);
609611
if (err == -EINPROGRESS || err == -EBUSY)
610612
return err;
611613

crypto/testmgr.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,18 @@ static bool notests;
4545
module_param(notests, bool, 0644);
4646
MODULE_PARM_DESC(notests, "disable all crypto self-tests");
4747

48+
#ifdef CONFIG_CRYPTO_SELFTESTS_FULL
4849
static bool noslowtests;
4950
module_param(noslowtests, bool, 0644);
5051
MODULE_PARM_DESC(noslowtests, "disable slow crypto self-tests");
5152

5253
static unsigned int fuzz_iterations = 100;
5354
module_param(fuzz_iterations, uint, 0644);
5455
MODULE_PARM_DESC(fuzz_iterations, "number of fuzz test iterations");
56+
#else
57+
#define noslowtests 1
58+
#define fuzz_iterations 0
59+
#endif
5560

5661
#ifndef CONFIG_CRYPTO_SELFTESTS
5762

@@ -319,9 +324,9 @@ struct testvec_config {
319324

320325
/*
321326
* The following are the lists of testvec_configs to test for each algorithm
322-
* type when the fast crypto self-tests are enabled. They aim to provide good
323-
* test coverage, while keeping the test time much shorter than the full tests
324-
* so that the fast tests can be used to fulfill FIPS 140 testing requirements.
327+
* type when the "fast" crypto self-tests are enabled. They aim to provide good
328+
* test coverage, while keeping the test time much shorter than the "full" tests
329+
* so that the "fast" tests can be enabled in a wider range of circumstances.
325330
*/
326331

327332
/* Configs for skciphers and aeads */
@@ -1183,14 +1188,18 @@ static void generate_random_testvec_config(struct rnd_state *rng,
11831188

11841189
static void crypto_disable_simd_for_test(void)
11851190
{
1191+
#ifdef CONFIG_CRYPTO_SELFTESTS_FULL
11861192
migrate_disable();
11871193
__this_cpu_write(crypto_simd_disabled_for_test, true);
1194+
#endif
11881195
}
11891196

11901197
static void crypto_reenable_simd_for_test(void)
11911198
{
1199+
#ifdef CONFIG_CRYPTO_SELFTESTS_FULL
11921200
__this_cpu_write(crypto_simd_disabled_for_test, false);
11931201
migrate_enable();
1202+
#endif
11941203
}
11951204

11961205
/*

include/crypto/internal/simd.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ void simd_unregister_aeads(struct aead_alg *algs, int count,
4444
*
4545
* This delegates to may_use_simd(), except that this also returns false if SIMD
4646
* in crypto code has been temporarily disabled on this CPU by the crypto
47-
* self-tests, in order to test the no-SIMD fallback code.
47+
* self-tests, in order to test the no-SIMD fallback code. This override is
48+
* currently limited to configurations where the "full" self-tests are enabled,
49+
* because it might be a bit too invasive to be part of the "fast" self-tests.
4850
*/
49-
#ifdef CONFIG_CRYPTO_SELFTESTS
51+
#ifdef CONFIG_CRYPTO_SELFTESTS_FULL
5052
DECLARE_PER_CPU(bool, crypto_simd_disabled_for_test);
5153
#define crypto_simd_usable() \
5254
(may_use_simd() && !this_cpu_read(crypto_simd_disabled_for_test))

lib/crypto/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ libsha256-generic-y := sha256-generic.o
6666

6767
obj-$(CONFIG_MPILIB) += mpi/
6868

69-
obj-$(CONFIG_CRYPTO_SELFTESTS) += simd.o
69+
obj-$(CONFIG_CRYPTO_SELFTESTS_FULL) += simd.o
7070

7171
obj-$(CONFIG_CRYPTO_LIB_SM3) += libsm3.o
7272
libsm3-y := sm3.o

0 commit comments

Comments
 (0)