Re: [PATCH] crypto: pkcs7: Return no-digest for data-taking algorithms
From: Ignat Korchagin
Date: Fri Nov 06 2026 - 13:13:06 EST
On Thu, Oct 15, 2026 at 12:08 PM Muhammad Mahdi Amirpour
<ampr.mhd@xxxxxxxxx> 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.
>
> Signed-off-by: Muhammad Mahdi Amirpour <ampr.mhd@xxxxxxxxx>
Would be nice to include "Fixes: " and "Cc: stable.."
> ---
> 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",
We should actually include what the algorithm is here probably for
easier debugging
> + __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
>
>
Ignat