* [PATCH v2] pkcs7: Return -EOPNOTSUPP for data-taking algorithms in pkcs7_get_digest()
@ 2026-11-06 20:03 Muhammad Mahdi Amirpour
2026-11-07 8:02 ` Muhammad Mahdi Amirpour
0 siblings, 1 reply; 2+ messages in thread
From: Muhammad Mahdi Amirpour @ 2026-11-06 20:03 UTC (permalink / raw)
To: ampr.mhd
Cc: dhowells, lukas, ignat, herbert, keyrings, linux-crypto,
linux-kernel, stable
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.
Fixes: f3eccecd782d ("pkcs7: Allow the signing algo to do whatever digestion it wants itself")
Cc: stable@vger.kernel.org # v7.0+
Signed-off-by: Muhammad Mahdi Amirpour <ampr.mhd@gmail.com>
---
v2:
- Add algorithm name to the pr_notice_once() message (Ignat)
- Add Fixes: and Cc: stable tags (Ignat)
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 474e2c1ae21b..c2e0eda502e2 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 (%s)\n",
+ __func__, sinfo->sig->pkey_algo);
+ 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] 2+ messages in thread* Re: [PATCH v2] pkcs7: Return -EOPNOTSUPP for data-taking algorithms in pkcs7_get_digest()
2026-11-06 20:03 [PATCH v2] pkcs7: Return -EOPNOTSUPP for data-taking algorithms in pkcs7_get_digest() Muhammad Mahdi Amirpour
@ 2026-11-07 8:02 ` Muhammad Mahdi Amirpour
0 siblings, 0 replies; 2+ messages in thread
From: Muhammad Mahdi Amirpour @ 2026-11-07 8:02 UTC (permalink / raw)
To: David Howells, Herbert Xu
Cc: Lukas Wunner, Ignat Korchagin, David S . Miller, keyrings,
linux-crypto, linux-kernel
Note: ignat@cloudflare.com bounced; the correct address per
MAINTAINERS is ignat@linux.win. The patch is otherwise unchanged
and available at:
https://lore.kernel.org/all/20261106200423.37769-1-ampr.mhd@gmail.com/
Thanks,
Mahdi
On Fri, Nov 6, 2026 at 11:34 PM Muhammad Mahdi Amirpour
<ampr.mhd@gmail.com> wrote:
>
> 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.
>
> Fixes: f3eccecd782d ("pkcs7: Allow the signing algo to do whatever digestion it wants itself")
> Cc: stable@vger.kernel.org # v7.0+
> Signed-off-by: Muhammad Mahdi Amirpour <ampr.mhd@gmail.com>
> ---
> v2:
> - Add algorithm name to the pr_notice_once() message (Ignat)
> - Add Fixes: and Cc: stable tags (Ignat)
>
> 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 474e2c1ae21b..c2e0eda502e2 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 (%s)\n",
> + __func__, sinfo->sig->pkey_algo);
> + 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] 2+ messages in thread
end of thread, other threads:[~2026-11-07 8:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-06 20:03 [PATCH v2] pkcs7: Return -EOPNOTSUPP for data-taking algorithms in pkcs7_get_digest() Muhammad Mahdi Amirpour
2026-11-07 8:02 ` 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®