From: Bruno Meneguele <bmeneg@redhat.com>
To: linux-integrity@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, keyrings@vger.kernel.org,
zohar@linux.ibm.com, roberto.sassu@huawei.com,
dhowells@redhat.com, bauerman@linux.ibm.com,
Bruno Meneguele <bmeneg@redhat.com>,
stable@vger.kernel.org
Subject: [RFC PATCH 2/8] pkcs7: return the content digest from pkcs7_get_digest()
Date: Thu, 26 Nov 2026 23:59:05 -0300 [thread overview]
Message-ID: <20261127025912.1383750-3-bmeneg@redhat.com> (raw)
In-Reply-To: <20261127025912.1383750-1-bmeneg@redhat.com>
When generating an appended module signature with authenticated attributes,
allowed only for ML-DSA with OpenSSL v3.x, pkcs7_digest() stores the file
content digest in sig->m and then check it against the messageDigest
attribute, later on it overwrites sig->m with a copy of the whole
attributes set, setting sig->m_size to its length and returning it to the
caller.
As consequence, a caller like IMA always fails on its binary blacklist
check because it's, possibly, comparing a file digest (blacklisted digest)
against the authenticated attributes data (computed and stored at sig->m).
On such case, return the messageDigest attribute instead.
Fixes: f3eccecd782d ("pkcs7: Allow the signing algo to do whatever digestion it wants itself")
Cc: stable@vger.kernel.org
Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
---
crypto/asymmetric_keys/pkcs7_verify.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/crypto/asymmetric_keys/pkcs7_verify.c b/crypto/asymmetric_keys/pkcs7_verify.c
index 356570b6d6aa..db3f6d080ccf 100644
--- a/crypto/asymmetric_keys/pkcs7_verify.c
+++ b/crypto/asymmetric_keys/pkcs7_verify.c
@@ -155,15 +155,22 @@ int pkcs7_get_digest(struct pkcs7_message *pkcs7, const u8 **buf, u32 *len,
ret = pkcs7_digest(pkcs7, sinfo);
if (ret)
return ret;
- if (!sinfo->sig->m_free) {
+
+ /* 'm' holds the digest or a copy of authattr, if the algorithm signs
+ * the data directly.
+ */
+ if (sinfo->authattrs) {
+ *buf = sinfo->msgdigest;
+ *len = sinfo->msgdigest_len;
+ } else if (sinfo->sig->m_free) {
+ *buf = sinfo->sig->m;
+ *len = sinfo->sig->m_size;
+ } else {
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;
-
i = match_string(hash_algo_name, HASH_ALGO__LAST,
sinfo->sig->hash_algo);
if (i >= 0)
--
2.55.0
next prev parent reply other threads:[~2026-11-27 2:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 2:59 [RFC PATCH 0/8] ima: measure modules with multiple appended signatures Bruno Meneguele
2026-11-27 2:59 ` [RFC PATCH 1/8] pkcs7: don't cache a failed digest in pkcs7_digest() Bruno Meneguele
2026-11-27 2:59 ` Bruno Meneguele [this message]
2026-11-27 2:59 ` [RFC PATCH 3/8] pkcs7: support multiple signers in pkcs7_get_digest() Bruno Meneguele
2026-11-27 2:59 ` [RFC PATCH 4/8] ima: get the modsig content digest of each signer Bruno Meneguele
2026-11-27 2:59 ` [RFC PATCH 5/8] ima: record data-signing algorithms by name in 'd-modsig' Bruno Meneguele
2026-11-27 2:59 ` [RFC PATCH 6/8] ima: add the 'd-modsig-list' template field Bruno Meneguele
2026-11-27 2:59 ` [RFC PATCH 7/8] ima: define the ima-modsigv2 template Bruno Meneguele
2026-11-27 2:59 ` [RFC PATCH 8/8] ima: check the digest of every modsig signer against the blacklist Bruno Meneguele
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261127025912.1383750-3-bmeneg@redhat.com \
--to=bmeneg@redhat.com \
--cc=bauerman@linux.ibm.com \
--cc=dhowells@redhat.com \
--cc=keyrings@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=roberto.sassu@huawei.com \
--cc=stable@vger.kernel.org \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®