Skip to content

Commit 91db696

Browse files
committed
pkcs7: Allow authenticatedAttributes for ML-DSA
Allow the rejection of authenticatedAttributes in PKCS#7 (signedAttrs in CMS) to be waived in the kernel config for ML-DSA when used for module signing. This reflects the issue that openssl < 4.0 cannot do this and openssl-4 has not yet been released. This does not permit RSA, ECDSA or ECRDSA to be so waived (behaviour unchanged). Signed-off-by: David Howells <dhowells@redhat.com> cc: Lukas Wunner <lukas@wunner.de> cc: Ignat Korchagin <ignat@cloudflare.com> cc: Jarkko Sakkinen <jarkko@kernel.org> cc: Stephan Mueller <smueller@chronox.de> cc: Eric Biggers <ebiggers@kernel.org> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: keyrings@vger.kernel.org cc: linux-crypto@vger.kernel.org
1 parent 0ad9a71 commit 91db696

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

crypto/asymmetric_keys/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ config PKCS7_MESSAGE_PARSER
5353
This option provides support for parsing PKCS#7 format messages for
5454
signature data and provides the ability to verify the signature.
5555

56+
config PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA
57+
bool "Waive rejection of authenticatedAttributes for ML-DSA"
58+
depends on PKCS7_MESSAGE_PARSER
59+
depends on CRYPTO_MLDSA
60+
help
61+
Due to use of CMS_NOATTR with ML-DSA not being supported in
62+
OpenSSL < 4.0 (and thus any released version), enabling this
63+
allows authenticatedAttributes to be used with ML-DSA for
64+
module signing. Use of authenticatedAttributes in this
65+
context is normally rejected.
66+
5667
config PKCS7_TEST_KEY
5768
tristate "PKCS#7 testing key type"
5869
depends on SYSTEM_DATA_VERIFICATION

crypto/asymmetric_keys/pkcs7_parser.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,17 @@ static int pkcs7_check_authattrs(struct pkcs7_message *msg)
9292
if (!sinfo)
9393
goto inconsistent;
9494

95+
#ifdef CONFIG_PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA
96+
msg->authattrs_rej_waivable = true;
97+
#endif
98+
9599
if (sinfo->authattrs) {
96100
want = true;
97101
msg->have_authattrs = true;
102+
#ifdef CONFIG_PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA
103+
if (strncmp(sinfo->sig->pkey_algo, "mldsa", 5) != 0)
104+
msg->authattrs_rej_waivable = false;
105+
#endif
98106
} else if (sinfo->sig->algo_takes_data) {
99107
sinfo->sig->hash_algo = "none";
100108
}

crypto/asymmetric_keys/pkcs7_parser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ struct pkcs7_message {
5555
struct pkcs7_signed_info *signed_infos;
5656
u8 version; /* Version of cert (1 -> PKCS#7 or CMS; 3 -> CMS) */
5757
bool have_authattrs; /* T if have authattrs */
58+
#ifdef CONFIG_PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA
59+
bool authattrs_rej_waivable; /* T if authatts rejection can be waived */
60+
#endif
5861

5962
/* Content Data (or NULL) */
6063
enum OID data_type; /* Type of Data */

crypto/asymmetric_keys/pkcs7_verify.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,12 @@ int pkcs7_verify(struct pkcs7_message *pkcs7,
425425
return -EKEYREJECTED;
426426
}
427427
if (pkcs7->have_authattrs) {
428+
#ifdef CONFIG_PKCS7_WAIVE_AUTHATTRS_REJECTION_FOR_MLDSA
429+
if (pkcs7->authattrs_rej_waivable) {
430+
pr_warn("Waived invalid module sig (has authattrs)\n");
431+
break;
432+
}
433+
#endif
428434
pr_warn("Invalid module sig (has authattrs)\n");
429435
return -EKEYREJECTED;
430436
}

0 commit comments

Comments
 (0)