Skip to contentSkip to conversation

ima: measure modules with multiple appended signatures

RFC PATCH New Bruno Meneguele 1 participant 9 messages Nov 27

Subsystems (9)
lore
Share & tools
lore
#0 lore raw

cover ima: measure modules with multiple appended signatures

Hi,

This RFC presents the support for modules with multiple signatures, *and mixed algorithms*, appended. A scenario that requires it today is the PQC transition period where modules are signed with both, eg., ML-DSA and ECDSA.

Appraisal already handles that: pkcs7_verify() accepts the file if a trusted signer verifies and no other signer fails (unknown keys is not considered failure). But measurement doesn't: 'd-modsig' and the binary blacklist check take the content digest from pkcs7_get_digest(), which fails with more than one signer, so the file loads unmeasured.

Patches #1 and #2 (for stable) fix two PKCS#7 bugs found on the way: a failed digest left in sig->m, and pkcs7_get_digest() returning the signed attributes instead of the content digest. Patch #3 adds support for multiple signers on PKCS#7 code, but IMA 'd-modsig' can't describe it, so patches #4-#7 add a template (patch #5 standardizes how ima-modsig records ML-DSA in the same way proposed here for its v2):

ima-modsigv2 = d-ngv2 | n-ng | sig | d-modsig-list | modsig

'd-modsig-list' is <u32 count> x (<u32 entry_len><entry>), one 'd-modsig' entry per signer in 'modsig' order, or "<sig algo>:" for direct data (eg. ML-DSA) signatures:

  d-ngv2:        ima:sha256:a4fa30a9...48d3a449
  n-ng:          /test/t10-ecdsa512-mldsa65-noattr.ko
  sig:           030304...feff

d-modsig-list: sha512:0e750939...f8c18dcb,mldsa65:
modsig: 30820e1706092a864886f70d010702a0...

Another example with ECDSA-SHA512+RSA-SHA256 and ML-DSA-65+ML-DSA-87:

d-modsig-list: sha512:0e750939...f8c18dcb,sha256:0ae76371...e37306f2
d-modsig-list: mldsa65:,mldsa87:

A signer with no usable digest gets an empty entry; with none, the measurement list entry is dropped, as with 'd-modsig'. Patch #8 blocks a file if any signer's digest is blacklisted.

Open questions: (1) should a dropped measurement be reported more explicitly than by its audit record? (2) a pure ML-DSA signer has no content digest to match a 'bin:' entry; how should that fit with the 'skid:' proposal [1]?

I tested module loading in a QEMU/KVM x86_64 and kernel image kexec in a PPC64LE LPAR with RSA, ECDSA and ML-DSA-65/87, one or two signers, mixed hash algorithms and rejected cases (bad messageDigest, two ML-DSA signers with one bad).

Claude Opus helped read the code, review the patches and write the tests (and this cover-letter). I reviewed and reworked every diff and I'm responsible for all of it.

Thanks,
Bruno

[1] https://lore.kernel.org/all/[email protected]/

Bruno Meneguele (8):
pkcs7: don't cache a failed digest in pkcs7_digest()
pkcs7: return the content digest from pkcs7_get_digest()
pkcs7: support multiple signers in pkcs7_get_digest()
ima: get the modsig content digest of each signer
ima: record data-signing algorithms by name in 'd-modsig'
ima: add the 'd-modsig-list' template field
ima: define the ima-modsigv2 template
ima: check the digest of every modsig signer against the blacklist

 Documentation/security/IMA-templates.rst  |   8 +-
 crypto/asymmetric_keys/pkcs7_verify.c     |  83 +++++++--
 include/crypto/pkcs7.h                    |   7 +-
 security/integrity/ima/ima.h              |  15 +-
 security/integrity/ima/ima_appraise.c     |  15 +-
 security/integrity/ima/ima_modsig.c       |  48 +++--
 security/integrity/ima/ima_policy.c       |   3 +-
 security/integrity/ima/ima_template.c     |   8 +-
 security/integrity/ima/ima_template_lib.c | 208 ++++++++++++++++++----
 security/integrity/ima/ima_template_lib.h |   4 +
 10 files changed, 314 insertions(+), 85 deletions(-)

--
2.55.0

#1 lore raw

RFC PATCH 1/8 pkcs7: don't cache a failed digest in pkcs7_digest()

The pkcs7_digest() function error path leaves sig->m allocated when messageDigest attribute doesn't match the content or the digest calculation fails. Considering it can be called more than once for the same signer, a second call after the first failed would have sig->m incorrectly set and would skip any further check as a successful calculation.

One example of user is IMA, which hits it when measuring first and then appraising a file module signature. With that, free and clear sig->m on failure, so every call repeats the checks.

Fixes e201af16d1ec ("PKCS#7: Introduce pkcs7_get_digest()")
---
 crypto/asymmetric_keys/pkcs7_verify.c | 5 +++++
 1 file changed, 5 insertions(+)
crypto/asymmetric_keys/pkcs7_verify.c +5 -0
index 474e2c1ae21b..356570b6d6aa 100644
@@ -131,6 +131,11 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7,
 	kfree(desc);
 error_no_desc:
 	crypto_free_shash(tfm);
+	if (ret && sig->m_free) {
+		kfree(sig->m);
+		sig->m = NULL;
+		sig->m_free = false;
+	}
 	kleave(" = %d", ret);
 	return ret;
 }
Signature · 1 line
2.55.0
#2 lore raw

RFC PATCH 2/8 pkcs7: return the content digest from pkcs7_get_digest()

In reply to Bruno Meneguele

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")
---
 crypto/asymmetric_keys/pkcs7_verify.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
crypto/asymmetric_keys/pkcs7_verify.c +11 -4
index 356570b6d6aa..db3f6d080ccf 100644
@@ -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)
Signature · 1 line
2.55.0
#3 lore raw

RFC PATCH 3/8 pkcs7: support multiple signers in pkcs7_get_digest()

In reply to Bruno Meneguele

Current pkcs7_get_digest() code fails with any message that has more than one SignerInfo, so the content digest of a multi-signed message can't be obtained, and it also doesn't support signers whose algorithm signs the data directly (eg. ML-DSA) without authenticated attributes, which has no content digest to report.

Give it a signer zero-index and add pkcs7_get_signer_count(), so callers can get the content digest of each signer of a message. Report a signer with no content digest as a zero-length digest rather than an error, and return the name of the signature algorithm when it signs the data directly.

This commit prepares the ground for ima-modsigv2 template, maintaining current field templates behavior.

---
 crypto/asymmetric_keys/pkcs7_verify.c | 63 ++++++++++++++++++++++-----
 include/crypto/pkcs7.h                |  7 ++-
 security/integrity/ima/ima_modsig.c   | 10 ++++-
 3 files changed, 66 insertions(+), 14 deletions(-)
crypto/asymmetric_keys/pkcs7_verify.c +53 -10
index db3f6d080ccf..bd55f86b9464 100644
@@ -140,17 +140,61 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7,
 	return ret;
 }
 
-int pkcs7_get_digest(struct pkcs7_message *pkcs7, const u8 **buf, u32 *len,
-		     enum hash_algo *hash_algo)
+/**
+ * pkcs7_get_signer_count - Count the signers of a PKCS#7 message
+ * @pkcs7: The preparsed PKCS#7 message to access
+ *
+ * Return: the number of SignerInfos in the message.
+ */
+unsigned int pkcs7_get_signer_count(const struct pkcs7_message *pkcs7)
+{
+	const struct pkcs7_signed_info *sinfo;
+	unsigned int count = 0;
+
+	for (sinfo = pkcs7->signed_infos; sinfo; sinfo = sinfo->next)
+		count++;
+
+	return count;
+}
+
+/**
+ * pkcs7_get_digest - Get the content digest of one signer of a PKCS#7 message
+ * @pkcs7: The PKCS#7 message
+ * @index: Zero-based index of the signer, in the message's (DER) order
+ * @buf: The content digest (NULL when there is none)
+ * @len: The content digest length (0 when there is none)
+ * @hash_algo: The digest algorithm (HASH_ALGO__LAST when there is none)
+ * @pkey_algo: The signature algorithm name if the data was signed directly
+ *
+ * The content digest is the digest of the signed content under the signer's
+ * digest algorithm. A signer whose algorithm signs the data directly has no
+ * digest when authenticated/signed attributes is absent, we return 0 in
+ * this case.
+ *
+ * Return: 0 on success, -EINVAL if there is no signer at 'index',
+ * -EKEYREJECTED if the messageDigest attribute doesn't match the content, or
+ * another negative error code.
+ */
+int pkcs7_get_digest(struct pkcs7_message *pkcs7, unsigned int index,
+		     const u8 **buf, u32 *len, enum hash_algo *hash_algo,
+		     const char **pkey_algo)
 {
 	struct pkcs7_signed_info *sinfo = pkcs7->signed_infos;
+	unsigned int n;
 	int i, ret;
 
-	/*
-	 * This function doesn't support messages with more than one signature.
-	 */
-	if (sinfo == NULL || sinfo->next != NULL)
-		return -EBADMSG;
+	*buf = NULL;
+	*len = 0;
+	*hash_algo = HASH_ALGO__LAST;
+	*pkey_algo = NULL;
+
+	for (n = 0; sinfo && n < index; n++)
+		sinfo = sinfo->next;
+	if (!sinfo)
+		return -EINVAL;
+
+	if (sinfo->sig->algo_takes_data)
+		*pkey_algo = sinfo->sig->pkey_algo;
 
 	ret = pkcs7_digest(pkcs7, sinfo);
 	if (ret)
@@ -166,9 +210,8 @@ int pkcs7_get_digest(struct pkcs7_message *pkcs7, const u8 **buf, u32 *len,
 		*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. */
+		/* No intermediate digest and no hash_algo to match. */
+		return 0;
 	}
 
 	i = match_string(hash_algo_name, HASH_ALGO__LAST,
include/crypto/pkcs7.h +5 -2
index 38ec7f5f9041..b237fe01b2f4 100644
@@ -41,7 +41,10 @@ extern int pkcs7_verify(struct pkcs7_message *pkcs7,
 extern int pkcs7_supply_detached_data(struct pkcs7_message *pkcs7,
 				      const void *data, size_t datalen);
 
-extern int pkcs7_get_digest(struct pkcs7_message *pkcs7, const u8 **buf,
-			    u32 *len, enum hash_algo *hash_algo);
+extern unsigned int pkcs7_get_signer_count(const struct pkcs7_message *pkcs7);
+
+extern int pkcs7_get_digest(struct pkcs7_message *pkcs7, unsigned int index,
+			    const u8 **buf, u32 *len, enum hash_algo *hash_algo,
+			    const char **pkey_algo);
 
 #endif /* _CRYPTO_PKCS7_H */
security/integrity/ima/ima_modsig.c +8 -2
index 632c746fd81e..15e499f7dba1 100644
@@ -99,6 +99,7 @@ int ima_read_modsig(enum ima_hooks func, const void *buf, loff_t buf_len,
  */
 void ima_collect_modsig(struct modsig *modsig, const void *buf, loff_t size)
 {
+	const char *pkey_algo;
 	int rc;
 
 	/*
@@ -111,9 +112,14 @@ void ima_collect_modsig(struct modsig *modsig, const void *buf, loff_t size)
 	if (rc)
 		return;
 
+	/* There's room for the digest of a single signer only. */
+	if (pkcs7_get_signer_count(modsig->pkcs7_msg) != 1)
+		return;
+
 	/* Ask the PKCS7 code to calculate the file hash. */
-	rc = pkcs7_get_digest(modsig->pkcs7_msg, &modsig->digest,
-			      &modsig->digest_size, &modsig->hash_algo);
+	rc = pkcs7_get_digest(modsig->pkcs7_msg, 0, &modsig->digest,
+			      &modsig->digest_size, &modsig->hash_algo,
+			      &pkey_algo);
 }
 
 int ima_modsig_verify(struct key *keyring, const struct modsig *modsig)
Signature · 1 line
2.55.0
#4 lore raw

RFC PATCH 4/8 ima: get the modsig content digest of each signer

In reply to Bruno Meneguele

The current code supports only one signer through ima_collect_modsig(), which is used for the 'd-modsig' field (from 'ima-modsig' template) and the is_binary_blacklisted() check. This single signer digest is taken from the PKCS#7/CMS message and kept in the modsig structure. However, in case of multiple signatures, PKCS#7 code already keeps the digest of each signer, thus we can use pkcs7_get_digest() to collect the digest of any of them without storing the data anywhere.

Stop keeping a copy of content digest in struct modsig and have ima_get_modsig_digest() get the digest lazily based on signer's index in the DER blob. To keep backwards compatibility, 'd-modsig' and the blacklist check still ask the digest of a single signed (index 0) modsig, so the behavior doesn't change.

---
 security/integrity/ima/ima.h              | 15 +++++--
 security/integrity/ima/ima_appraise.c     |  8 ++--
 security/integrity/ima/ima_modsig.c       | 54 ++++++++++-------------
 security/integrity/ima/ima_template_lib.c | 10 ++++-
 4 files changed, 48 insertions(+), 39 deletions(-)
security/integrity/ima/ima.h +12 -3
index b502854f28ee..055a2a696071 100644
@@ -560,8 +560,10 @@ static inline void __init init_ima_appraise_lsm(const struct lsm_id *lsmid)
 int ima_read_modsig(enum ima_hooks func, const void *buf, loff_t buf_len,
 		    struct modsig **modsig);
 void ima_collect_modsig(struct modsig *modsig, const void *buf, loff_t size);
-int ima_get_modsig_digest(const struct modsig *modsig, enum hash_algo *algo,
-			  const u8 **digest, u32 *digest_size);
+unsigned int ima_get_modsig_signer_count(const struct modsig *modsig);
+int ima_get_modsig_digest(const struct modsig *modsig, unsigned int index,
+			  enum hash_algo *algo, const u8 **digest,
+			  u32 *digest_size, const char **sig_algo);
 int ima_get_raw_modsig(const struct modsig *modsig, const void **data,
 		       u32 *data_len);
 void ima_free_modsig(struct modsig *modsig);
@@ -577,9 +579,16 @@ static inline void ima_collect_modsig(struct modsig *modsig, const void *buf,
 {
 }
 
+static inline unsigned int
+ima_get_modsig_signer_count(const struct modsig *modsig)
+{
+	return 0;
+}
+
 static inline int ima_get_modsig_digest(const struct modsig *modsig,
+					unsigned int index,
 					enum hash_algo *algo, const u8 **digest,
-					u32 *digest_size)
+					u32 *digest_size, const char **sig_algo)
 {
 	return -EOPNOTSUPP;
 }
security/integrity/ima/ima_appraise.c +5 -3
index 134174d2e3f0..8aeec2778984 100644
@@ -429,6 +429,7 @@ int ima_check_blacklist(struct ima_iint_cache *iint,
 			const struct modsig *modsig, int pcr)
 {
 	enum hash_algo hash_algo;
+	const char *sig_algo;
 	const u8 *digest = NULL;
 	u32 digestsize = 0;
 	int rc = 0;
@@ -437,9 +438,10 @@ int ima_check_blacklist(struct ima_iint_cache *iint,
 		return 0;
 
 	if (iint->flags & IMA_MODSIG_ALLOWED && modsig) {
-		ima_get_modsig_digest(modsig, &hash_algo, &digest, &digestsize);
-
-		rc = is_binary_blacklisted(digest, digestsize);
+		if (ima_get_modsig_signer_count(modsig) == 1 &&
+		    !ima_get_modsig_digest(modsig, 0, &hash_algo, &digest,
+					   &digestsize, &sig_algo))
+			rc = is_binary_blacklisted(digest, digestsize);
 	} else if (iint->flags & IMA_DIGSIG_REQUIRED && iint->ima_hash)
 		rc = is_binary_blacklisted(iint->ima_hash->digest, iint->ima_hash->length);
 
security/integrity/ima/ima_modsig.c +23 -31

95 lines not on this page · raw message

security/integrity/ima/ima_template_lib.c +8 -2
index 9bd80ca1159a..0609a8f7a127 100644
@@ -471,10 +471,16 @@ int ima_eventdigest_modsig_init(struct ima_event_data *event_data,
 		cur_digest = NULL;
 		cur_digestsize = 0;
 	} else {
+		const char *sig_algo;
 		int rc;
 
-		rc = ima_get_modsig_digest(event_data->modsig, &hash_algo,
-					   &cur_digest, &cur_digestsize);
+		/* 'd-modsig' supports the digest of a single signer only. */
+		if (ima_get_modsig_signer_count(event_data->modsig) != 1)
+			return -EINVAL;
+
+		rc = ima_get_modsig_digest(event_data->modsig, 0, &hash_algo,
+					   &cur_digest, &cur_digestsize,
+					   &sig_algo);
 		if (rc)
 			return rc;
 		else if (hash_algo == HASH_ALGO__LAST || cur_digestsize == 0)
Signature · 1 line
2.55.0
#5 lore raw

RFC PATCH 5/8 ima: record data-signing algorithms by name in 'd-modsig'

In reply to Bruno Meneguele

A signer whose algorithm signs the data directly (eg. ML-DSA) has no content digest unless it carries authenticated attributes. With authenticated attributes, which sign-file uses for ML-DSA when built against OpenSSL 3.x, 'd-modsig' holds the messageDigest attribute, while the signature covers the attributes and not that digest.

Record such a signer by the name of its signature algorithm instead of a hash algorithm, with an empty digest (e.g. "mldsa65:" '\0'), with or without authenticated attributes. A verifier needs to traverse the 'modsig' field to find out authattr's presence. Signers that sign a digest are recorded as before.

---
 Documentation/security/IMA-templates.rst  |   4 +-
 security/integrity/ima/ima_template_lib.c | 113 ++++++++++++++--------
 2 files changed, 75 insertions(+), 42 deletions(-)
Documentation/security/IMA-templates.rst +3 -1
index 15b4add314fc..4ec0440b27f1 100644
@@ -69,7 +69,9 @@ descriptors by adding their identifier to the format string
    algorithm (field format: <hash algo>:digest);
  - 'd-ngv2': same as d-ng, but prefixed with the "ima" or "verity" digest type
    (field format: <digest type>:<hash algo>:digest);
- - 'd-modsig': the digest of the event without the appended modsig;
+ - 'd-modsig': the digest of the event without the appended modsig or a signature
+   algorithm name followed by an empty digest (<signing algo>: \0) when direct data
+   algorithms are used, e.g. ML-DSA;
  - 'n-ng': the name of the event, without size limitations;
  - 'sig': the file signature, based on either the file's/fsverity's digest[1],
    or the EVM portable signature, if 'security.ima' contains a file hash.
security/integrity/ima/ima_template_lib.c +72 -41

141 lines not on this page · raw message

Signature · 1 line
2.55.0
#6 lore raw

RFC PATCH 6/8 ima: add the 'd-modsig-list' template field

In reply to Bruno Meneguele

The 'd-modsig' field holds a single content digest, so it can't describe an appended signature with more than one signer, let alone signers using different algorithms. With that, add a 'd-modsig-list' field that records an entry per signer as the following length-value table:

    <u32 count> x (<u32 entry_len><entry>)

with the entries in the order of the signers in the 'modsig' field, so entry i describes signer i, and following the already known d-modsig format:

<hash algo>: <digest>

for a signer that signs an usual digest, and:

    <signature algo>: '\0'

for a signer that signs data directly (eg. ML-DSA). The idea of adding an empty entry is to keep entries aligned with their signers in 'modsig' field, easing verifiers work.

---
 Documentation/security/IMA-templates.rst  |   3 +
 security/integrity/ima/ima_policy.c       |   3 +-
 security/integrity/ima/ima_template.c     |   6 +-
 security/integrity/ima/ima_template_lib.c | 103 ++++++++++++++++++++++
 security/integrity/ima/ima_template_lib.h |   4 +
 5 files changed, 117 insertions(+), 2 deletions(-)
Documentation/security/IMA-templates.rst +3 -0
index 4ec0440b27f1..161aed3da8b7 100644
@@ -72,6 +72,9 @@ descriptors by adding their identifier to the format string
  - 'd-modsig': the digest of the event without the appended modsig or a signature
    algorithm name followed by an empty digest (<signing algo>: \0) when direct data
    algorithms are used, e.g. ML-DSA;
+ - 'd-modsig-list': a list of 'd-modsig' of each signer when multiple signatures are
+   present and which may use different algorithms
+   (field format: <entry count>[pairs of <entry length><d-modsig entry>]);
  - 'n-ng': the name of the event, without size limitations;
  - 'sig': the file signature, based on either the file's/fsverity's digest[1],
    or the EVM portable signature, if 'security.ima' contains a file hash.
security/integrity/ima/ima_policy.c +2 -1
index 2dc1d93aa768..bb68f78fdb0e 100644
@@ -1242,7 +1242,8 @@ static void check_template_modsig(const struct ima_template_desc *template)
 	for (i = 0; i < template->num_fields; i++) {
 		if (!strcmp(template->fields[i]->field_id, "modsig"))
 			has_modsig = true;
-		else if (!strcmp(template->fields[i]->field_id, "d-modsig"))
+		else if (!strcmp(template->fields[i]->field_id, "d-modsig") ||
+			 !strcmp(template->fields[i]->field_id, "d-modsig-list"))
 			has_dmodsig = true;
 	}
 
security/integrity/ima/ima_template.c +5 -1
index 16154078fd70..584f970e553e 100644
@@ -50,6 +50,9 @@ static const struct ima_template_field supported_fields[] = {
 	 .field_show = ima_show_template_buf},
 	{.field_id = "d-modsig", .field_init = ima_eventdigest_modsig_init,
 	 .field_show = ima_show_template_digest_ng},
+	{.field_id = "d-modsig-list",
+	 .field_init = ima_eventdigest_modsig_list_init,
+	 .field_show = ima_show_template_modsig_list},
 	{.field_id = "modsig", .field_init = ima_eventmodsig_init,
 	 .field_show = ima_show_template_sig},
 	{.field_id = "evmsig", .field_init = ima_eventevmsig_init,
@@ -95,7 +98,8 @@ bool ima_template_has_modsig(const struct ima_template_desc *ima_template)
 
 	for (i = 0; i < ima_template->num_fields; i++)
 		if (!strcmp(ima_template->fields[i]->field_id, "modsig") ||
-		    !strcmp(ima_template->fields[i]->field_id, "d-modsig"))
+		    !strcmp(ima_template->fields[i]->field_id, "d-modsig") ||
+		    !strcmp(ima_template->fields[i]->field_id, "d-modsig-list"))
 			return true;
 
 	return false;
security/integrity/ima/ima_template_lib.c +103 -0

115 lines not on this page · raw message

security/integrity/ima/ima_template_lib.h +4 -0
index 9f7c335f304f..cf3d453d4c37 100644
@@ -23,6 +23,8 @@ void ima_show_template_digest_ng(struct seq_file *m, enum ima_show_type show,
 				 struct ima_field_data *field_data);
 void ima_show_template_digest_ngv2(struct seq_file *m, enum ima_show_type show,
 				   struct ima_field_data *field_data);
+void ima_show_template_modsig_list(struct seq_file *m, enum ima_show_type show,
+				   struct ima_field_data *field_data);
 void ima_show_template_string(struct seq_file *m, enum ima_show_type show,
 			      struct ima_field_data *field_data);
 void ima_show_template_sig(struct seq_file *m, enum ima_show_type show,
@@ -44,6 +46,8 @@ int ima_eventdigest_ngv2_init(struct ima_event_data *event_data,
 			      struct ima_field_data *field_data);
 int ima_eventdigest_modsig_init(struct ima_event_data *event_data,
 				struct ima_field_data *field_data);
+int ima_eventdigest_modsig_list_init(struct ima_event_data *event_data,
+				     struct ima_field_data *field_data);
 int ima_eventname_ng_init(struct ima_event_data *event_data,
 			  struct ima_field_data *field_data);
 int ima_eventsig_init(struct ima_event_data *event_data,
Signature · 1 line
2.55.0
#7 lore raw

RFC PATCH 7/8 ima: define the ima-modsigv2 template

In reply to Bruno Meneguele

Add the "ima-modsigv2" template with the following format:

d-ngv2|n-ng|sig|d-modsig-list|modsig

the counterpart of ima-modsig with support for multiple appended signatures that records the content digest for every signer instead of just one. The existing ima-modsig template and its 'd-modsig' field are left unchanged.

---
 Documentation/security/IMA-templates.rst | 1 +
 security/integrity/ima/ima_template.c    | 2 ++
 2 files changed, 3 insertions(+)
Documentation/security/IMA-templates.rst +1 -0
index 161aed3da8b7..38d6d27344e2 100644
@@ -99,6 +99,7 @@ Below, there is the list of defined template descriptors:
  - "ima-sigv2": its format is ``d-ngv2|n-ng|sig``;
  - "ima-buf": its format is ``d-ng|n-ng|buf``;
  - "ima-modsig": its format is ``d-ng|n-ng|sig|d-modsig|modsig``;
+ - "ima-modsigv2": its format is ``d-ngv2|n-ng|sig|d-modsig-list|modsig``;
  - "evm-sig": its format is ``d-ng|n-ng|evmsig|xattrnames|xattrlengths|xattrvalues|iuid|igid|imode``;
 
 
security/integrity/ima/ima_template.c +2 -0
index 584f970e553e..721af4b1828b 100644
@@ -24,6 +24,8 @@ static struct ima_template_desc builtin_templates[] = {
 	{.name = "ima-sigv2", .fmt = "d-ngv2|n-ng|sig"},
 	{.name = "ima-buf", .fmt = "d-ng|n-ng|buf"},
 	{.name = "ima-modsig", .fmt = "d-ng|n-ng|sig|d-modsig|modsig"},
+	{.name = "ima-modsigv2",
+	 .fmt = "d-ngv2|n-ng|sig|d-modsig-list|modsig"},
 	{.name = "evm-sig",
 	 .fmt = "d-ng|n-ng|evmsig|xattrnames|xattrlengths|xattrvalues|iuid|igid|imode"},
 	{.name = "", .fmt = ""},	/* placeholder for a custom format */
Signature · 1 line
2.55.0
#8 lore raw

RFC PATCH 8/8 ima: check the digest of every modsig signer against the blacklist

In reply to Bruno Meneguele

When checking the binary blacklist, traverse every signer content digest appended to the file. If one digest fails (-EPERM), the content is deemed blocked.

---
 security/integrity/ima/ima_appraise.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
security/integrity/ima/ima_appraise.c +10 -5
index 8aeec2778984..a62dc1aa93b4 100644
@@ -432,18 +432,23 @@ int ima_check_blacklist(struct ima_iint_cache *iint,
 	const char *sig_algo;
 	const u8 *digest = NULL;
 	u32 digestsize = 0;
+	unsigned int i, count;
 	int rc = 0;
 
 	if (!(iint->flags & IMA_CHECK_BLACKLIST))
 		return 0;
 
 	if (iint->flags & IMA_MODSIG_ALLOWED && modsig) {
-		if (ima_get_modsig_signer_count(modsig) == 1 &&
-		    !ima_get_modsig_digest(modsig, 0, &hash_algo, &digest,
-					   &digestsize, &sig_algo))
-			rc = is_binary_blacklisted(digest, digestsize);
-	} else if (iint->flags & IMA_DIGSIG_REQUIRED && iint->ima_hash)
+		count = ima_get_modsig_signer_count(modsig);
+		for (i = 0; i < count && rc != -EPERM; i++) {
+			if (!ima_get_modsig_digest(modsig, i, &hash_algo,
+						   &digest, &digestsize,
+						   &sig_algo) && digestsize)
+				rc = is_binary_blacklisted(digest, digestsize);
+		}
+	} else if (iint->flags & IMA_DIGSIG_REQUIRED && iint->ima_hash) {
 		rc = is_binary_blacklisted(iint->ima_hash->digest, iint->ima_hash->length);
+	}
 
 	if ((rc == -EPERM) && (iint->flags & IMA_MEASURE))
 		process_buffer_measurement(&nop_mnt_idmap, NULL, digest, digestsize,
Signature · 1 line
2.55.0