* [PATCH] crypto: pkcs7: Return no-digest for data-taking algorithms
@ 2026-10-15 11:08 Muhammad Mahdi Amirpour
0 siblings, 0 replies; only message in thread
From: Muhammad Mahdi Amirpour @ 2026-10-15 11:08 UTC (permalink / raw)
To: David Howells, Lukas Wunner, Ignat Korchagin, Herbert Xu,
David S . Miller
Cc: keyrings, linux-crypto, linux-kernel, Muhammad Mahdi Amirpour
pkcs7_get_digest() is documented to return a digest for IMA to use
when verifying a modsig. For signature algorithms where the public
key algorithm consumes the raw data rather than a precomputed hash
(algo_takes_data, currently ML-DSA), pkcs7_digest() does not produce
an intermediate digest.
When such a signature has no authenticated attributes, sig->m points
at the raw data and m_free is false, so the existing check rejects it.
But when the signature does have authenticated attributes, sig->m is
an allocated buffer containing a modified copy of the AuthAttrs and
m_free is true. The existing check therefore returns that buffer to
the caller as if it were a digest.
Test for algo_takes_data directly and report that no digest is
available, before attempting to call pkcs7_digest(). This covers
both ML-DSA cases consistently and removes the now-dead m_free check.
The only in-tree caller, ima_collect_modsig(), does not check the
return value of pkcs7_get_digest(); for a data-taking algorithm it
will now leave the digest fields unset and fall through with no
digest, which is the correct outcome for an algorithm that does not
produce an intermediate digest. Callers that do care can detect the
new -EOPNOTSUPP return.
Signed-off-by: Muhammad Mahdi Amirpour <ampr.mhd@gmail.com>
---
crypto/asymmetric_keys/pkcs7_verify.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/crypto/asymmetric_keys/pkcs7_verify.c b/crypto/asymmetric_keys/pkcs7_verify.c
index 474e2c1ae21..7939b08b603 100644
--- a/crypto/asymmetric_keys/pkcs7_verify.c
+++ b/crypto/asymmetric_keys/pkcs7_verify.c
@@ -147,14 +147,15 @@ int pkcs7_get_digest(struct pkcs7_message *pkcs7, const u8 **buf, u32 *len,
if (sinfo == NULL || sinfo->next != NULL)
return -EBADMSG;
+ if (sinfo->sig->algo_takes_data) {
+ pr_notice_once("%s: No digest for data-taking algorithm\n",
+ __func__);
+ return -EOPNOTSUPP;
+ }
+
ret = pkcs7_digest(pkcs7, sinfo);
if (ret)
return ret;
- if (!sinfo->sig->m_free) {
- pr_notice_once("%s: No digest available\n", __func__);
- return -EINVAL; /* TODO: MLDSA doesn't necessarily calculate an
- * intermediate digest. */
- }
*buf = sinfo->sig->m;
*len = sinfo->sig->m_size;
--
2.55.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-15 11:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-15 11:08 [PATCH] crypto: pkcs7: Return no-digest for data-taking algorithms Muhammad Mahdi Amirpour
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®