mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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>
Subject: [RFC PATCH 6/8] ima: add the 'd-modsig-list' template field
Date: Thu, 26 Nov 2026 23:59:09 -0300	[thread overview]
Message-ID: <20261127025912.1383750-7-bmeneg@redhat.com> (raw)
In-Reply-To: <20261127025912.1383750-1-bmeneg@redhat.com>

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.

Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
---
 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(-)

diff --git a/Documentation/security/IMA-templates.rst b/Documentation/security/IMA-templates.rst
index 4ec0440b27f1..161aed3da8b7 100644
--- a/Documentation/security/IMA-templates.rst
+++ b/Documentation/security/IMA-templates.rst
@@ -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.
diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
index 2dc1d93aa768..bb68f78fdb0e 100644
--- a/security/integrity/ima/ima_policy.c
+++ b/security/integrity/ima/ima_policy.c
@@ -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;
 	}
 
diff --git a/security/integrity/ima/ima_template.c b/security/integrity/ima/ima_template.c
index 16154078fd70..584f970e553e 100644
--- a/security/integrity/ima/ima_template.c
+++ b/security/integrity/ima/ima_template.c
@@ -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;
diff --git a/security/integrity/ima/ima_template_lib.c b/security/integrity/ima/ima_template_lib.c
index a2aeaae83065..eeb636155798 100644
--- a/security/integrity/ima/ima_template_lib.c
+++ b/security/integrity/ima/ima_template_lib.c
@@ -200,6 +200,40 @@ void ima_show_template_digest_ngv2(struct seq_file *m, enum ima_show_type show,
 				     field_data);
 }
 
+void ima_show_template_modsig_list(struct seq_file *m, enum ima_show_type show,
+				   struct ima_field_data *field_data)
+{
+	struct ima_field_data entry;
+	u32 count, i;
+	int parsed;
+	void *p = field_data->data;
+	void *end = p + field_data->len;
+
+	if (show != IMA_SHOW_ASCII || field_data->len < sizeof(count)) {
+		ima_show_template_field_data(m, show, DATA_FMT_HEX, field_data);
+		return;
+	}
+
+	memcpy(&count, p, sizeof(count));
+	if (ima_canonical_fmt)
+		count = le32_to_cpu((__force __le32)count);
+	p += sizeof(count);
+
+	for (i = 0; i < count; i++) {
+		ima_parse_buf(p, end, &p, 1, &entry, &parsed, NULL, 0,
+			      "d-modsig-list");
+		if (parsed != 1)
+			break;
+
+		if (i)
+			seq_putc(m, ',');
+		if (entry.len)
+			ima_show_template_data_ascii(m, show,
+						     DATA_FMT_DIGEST_WITH_ALGO,
+						     &entry);
+	}
+}
+
 void ima_show_template_string(struct seq_file *m, enum ima_show_type show,
 			      struct ima_field_data *field_data)
 {
@@ -524,6 +558,75 @@ int ima_eventdigest_modsig_init(struct ima_event_data *event_data,
 					     field_data);
 }
 
+/*
+ *  ima_eventdigest_modsig_list_init - add the content digest of each modsig
+ *  signer to the template data.
+ *
+ *  Unlike 'd-modsig', this field describes an appended signature with any
+ *  number of signers, which may use different algorithms. It is a table as
+ *  follows:
+ *
+ *      <u32 count> x (<u32 entry_len><entry>)
+ *
+ *  with one entry per signer, in the order of the 'modsig' field, so entry i
+ *  describes signer i, and with the pair <entry_len><entry> repeating <count>
+ *  times.
+ *
+ *  An entry has the 'd-modsig' format, see ima_modsig_digest_entry().
+ */
+int ima_eventdigest_modsig_list_init(struct ima_event_data *event_data,
+				     struct ima_field_data *field_data)
+{
+	unsigned int count, i, err_count = 0;
+	int len, rc;
+	size_t buf_len;
+	u8 *buf, *p;
+	u32 val;
+
+	if (!event_data->modsig)
+		return 0;
+
+	count = ima_get_modsig_signer_count(event_data->modsig);
+	if (!count)
+		return 0;
+
+	buf_len = size_add(sizeof(u32),
+			   size_mul(count, sizeof(u32) +
+				    IMA_MAX_DIGEST_ENTRY_SIZE - DIGEST_TYPE_NAME_LEN_MAX));
+	buf = kmalloc(buf_len, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	p = buf;
+	val = ima_canonical_fmt ? (__force u32)cpu_to_le32(count) : count;
+	memcpy(p, &val, sizeof(val));
+	p += sizeof(u32);
+
+	for (i = 0; i < count; i++) {
+		len = ima_modsig_digest_entry(event_data->modsig, i,
+					      p + sizeof(u32));
+		if (len < 0) {
+			/* Keep walking signers' list, even on failure, to
+			 * maintain allignament with modsig.
+			 */
+			rc = len;
+			len = 0;
+			err_count++;
+		}
+
+		val = ima_canonical_fmt ? (__force u32)cpu_to_le32(len) : len;
+		memcpy(p, &val, sizeof(val));
+		p += sizeof(u32) + len;
+	}
+
+	/* Like 'd-modsig', don't measure if the list has only bad digests */
+	if (err_count < count)
+		rc = ima_write_template_field_data(buf, p - buf, DATA_FMT_HEX,
+						   field_data);
+	kfree(buf);
+	return rc;
+}
+
 static int ima_eventname_init_common(struct ima_event_data *event_data,
 				     struct ima_field_data *field_data,
 				     bool size_limit)
diff --git a/security/integrity/ima/ima_template_lib.h b/security/integrity/ima/ima_template_lib.h
index 9f7c335f304f..cf3d453d4c37 100644
--- a/security/integrity/ima/ima_template_lib.h
+++ b/security/integrity/ima/ima_template_lib.h
@@ -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,
-- 
2.55.0


  parent reply	other threads:[~2026-11-27  3:00 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 ` [RFC PATCH 2/8] pkcs7: return the content digest from pkcs7_get_digest() Bruno Meneguele
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 ` Bruno Meneguele [this message]
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-7-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=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®