Skip to content

Commit 4112f1b

Browse files
author
Herbert Xu
committed
certs: Break circular dependency when selftest is modular
JIRA: https://issues.redhat.com/browse/RHEL-81929 commit 04a9320 Author: Herbert Xu <herbert@gondor.apana.org.au> Date: Mon Oct 16 13:21:44 2023 +0800 certs: Break circular dependency when selftest is modular The modular build fails because the self-test code depends on pkcs7 which in turn depends on x509 which contains the self-test. Split the self-test out into its own module to break the cycle. Fixes: 3cde317 ("certs: Add FIPS selftests") Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Herbert Xu <herbert.xu@redhat.com>
1 parent b477cf5 commit 4112f1b

File tree

5 files changed

+15
-21
lines changed

5 files changed

+15
-21
lines changed

crypto/asymmetric_keys/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,14 @@ config SIGNED_PE_FILE_VERIFICATION
9797
signed PE binary.
9898

9999
config FIPS_SIGNATURE_SELFTEST
100-
bool "Run FIPS selftests on the X.509+PKCS7 signature verification"
100+
tristate "Run FIPS selftests on the X.509+PKCS7 signature verification"
101101
help
102102
This option causes some selftests to be run on the signature
103103
verification code, using some built in data. This is required
104104
for FIPS.
105105
depends on KEYS
106106
depends on ASYMMETRIC_KEY_TYPE
107107
depends on PKCS7_MESSAGE_PARSER=X509_CERTIFICATE_PARSER
108+
depends on X509_CERTIFICATE_PARSER
108109

109110
endif # ASYMMETRIC_KEY_TYPE

crypto/asymmetric_keys/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ x509_key_parser-y := \
2323
x509_cert_parser.o \
2424
x509_loader.o \
2525
x509_public_key.o
26-
x509_key_parser-$(CONFIG_FIPS_SIGNATURE_SELFTEST) += selftest.o
26+
obj-$(CONFIG_FIPS_SIGNATURE_SELFTEST) += x509_selftest.o
27+
x509_selftest-y += selftest.o
2728

2829
$(obj)/x509_cert_parser.o: \
2930
$(obj)/x509.asn1.h \

crypto/asymmetric_keys/selftest.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
* Written by David Howells (dhowells@redhat.com)
55
*/
66

7-
#include <linux/kernel.h>
7+
#include <crypto/pkcs7.h>
88
#include <linux/cred.h>
9+
#include <linux/kernel.h>
910
#include <linux/key.h>
10-
#include <crypto/pkcs7.h>
11+
#include <linux/module.h>
1112
#include "x509_parser.h"
1213

1314
struct certs_test {
@@ -175,7 +176,7 @@ static const struct certs_test certs_tests[] __initconst = {
175176
TEST(certs_selftest_1_data, certs_selftest_1_pkcs7),
176177
};
177178

178-
int __init fips_signature_selftest(void)
179+
static int __init fips_signature_selftest(void)
179180
{
180181
struct key *keyring;
181182
int ret, i;
@@ -222,3 +223,9 @@ int __init fips_signature_selftest(void)
222223
key_put(keyring);
223224
return 0;
224225
}
226+
227+
late_initcall(fips_signature_selftest);
228+
229+
MODULE_DESCRIPTION("X.509 self tests");
230+
MODULE_AUTHOR("Red Hat, Inc.");
231+
MODULE_LICENSE("GPL");

crypto/asymmetric_keys/x509_parser.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,6 @@ struct x509_certificate {
4141
bool blacklisted;
4242
};
4343

44-
/*
45-
* selftest.c
46-
*/
47-
#ifdef CONFIG_FIPS_SIGNATURE_SELFTEST
48-
extern int __init fips_signature_selftest(void);
49-
#else
50-
static inline int fips_signature_selftest(void) { return 0; }
51-
#endif
52-
5344
/*
5445
* x509_cert_parser.c
5546
*/

crypto/asymmetric_keys/x509_public_key.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,9 @@ static struct asymmetric_key_parser x509_key_parser = {
257257
/*
258258
* Module stuff
259259
*/
260-
extern int __init certs_selftest(void);
261260
static int __init x509_key_init(void)
262261
{
263-
int ret;
264-
265-
ret = register_asymmetric_key_parser(&x509_key_parser);
266-
if (ret < 0)
267-
return ret;
268-
return fips_signature_selftest();
262+
return register_asymmetric_key_parser(&x509_key_parser);
269263
}
270264

271265
static void __exit x509_key_exit(void)

0 commit comments

Comments
 (0)