From: Mimi Zohar <zohar@linux.ibm.com>
To: Enrico Bravi <enrico.bravi@polito.it>,
linux-integrity@vger.kernel.org, dmitry.kasatkin@gmail.com,
roberto.sassu@huawei.com
Cc: eric.snowberg@oracle.com
Subject: Re: [PATCH v5 1/2] ima: add critical data measurement for loaded policy
Date: Mon, 06 Jul 2026 23:04:12 -0400 [thread overview]
Message-ID: <23b77eb601a40063738e0d9c4253fff51e304a11.camel@linux.ibm.com> (raw)
In-Reply-To: <20260702190403.5844-2-enrico.bravi@polito.it>
On Thu, 2026-07-02 at 21:04 +0200, Enrico Bravi wrote:
> diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
> index f7f940a76922..a65b7e4b64d6 100644
> --- a/security/integrity/ima/ima_policy.c
> +++ b/security/integrity/ima/ima_policy.c
> @@ -2379,3 +2385,82 @@ bool ima_appraise_signature(enum kernel_read_file_id id)
> return found;
> }
> #endif /* CONFIG_IMA_APPRAISE && CONFIG_INTEGRITY_TRUSTED_KEYRING */
> +
> +/**
> + * ima_measure_loaded_policy - measure the active IMA policy ruleset
> + *
> + * Must be called with ima_write_mutex held, as it performs two
> + * separate RCU read passes over ima_rules and relies on the mutex
> + * to prevent concurrent policy updates between them.
> + */
> +void ima_measure_loaded_policy(void)
> +{
> + const char *event_name = "ima_policy_loaded";
> + const char *op = "measure_loaded_ima_policy";
> + size_t rule_len = max_rule_len + 2;
> + struct ima_rule_entry *rule_entry;
> + struct list_head *ima_rules_tmp;
> + struct seq_file file;
Hi Enrico,
FYI, there's a merge conflict with commit 51bedcd803e0 ("ima: Mediate
open/release method of the measurements list".
As long as 2/2 needs to be update, there are two nits: initialize seq_file like
"file = { 0 };".
> + int result = -ENOMEM;
> + size_t file_len = 0;
> + char *rule;
> +
> + lockdep_assert_held(&ima_write_mutex);
> +
> + rule = vmalloc(rule_len);
> + if (!rule) {
> + integrity_audit_msg(AUDIT_INTEGRITY_PCR, NULL, event_name,
> + op, "ENOMEM", result, 0);
> + return;
> + }
> +
> + /* calculate IMA policy rules memory size */
> + file.buf = rule;
> + file.read_pos = 0;
> + file.size = rule_len;
> + file.count = 0;
> +
> + rcu_read_lock();
> + ima_rules_tmp = rcu_dereference(ima_rules);
> + list_for_each_entry_rcu(rule_entry, ima_rules_tmp, list) {
> + ima_policy_show(&file, rule_entry);
> +
> + if (seq_has_overflowed(&file)) {
> + result = -E2BIG;
> + integrity_audit_msg(AUDIT_INTEGRITY_PCR, NULL, event_name,
> + op, "rule_length", result, 0);
and limit the integrity_audit_msg to 80 chars.
Otherwise the patch looks good.
Mimi
> + rcu_read_unlock();
> + goto free_rule;
> + }
> +
> + file_len += file.count;
> + file.count = 0;
> + }
> + rcu_read_unlock();
> +
> + /* copy IMA policy rules to a buffer for measuring */
> + file.buf = vmalloc(file_len);
> + if (!file.buf) {
> + integrity_audit_msg(AUDIT_INTEGRITY_PCR, NULL, event_name,
> + op, "ENOMEM", result, 0);
> + goto free_rule;
> + }
> +
> + file.read_pos = 0;
> + file.size = file_len;
> + file.count = 0;
> +
> + rcu_read_lock();
> + ima_rules_tmp = rcu_dereference(ima_rules);
> + list_for_each_entry_rcu(rule_entry, ima_rules_tmp, list) {
> + ima_policy_show(&file, rule_entry);
> + }
> + rcu_read_unlock();
> +
> + ima_measure_critical_data("ima_policy", event_name, file.buf,
> + file.count, false, NULL, 0);
> +
> + vfree(file.buf);
> +free_rule:
> + vfree(rule);
> +}
next prev parent reply other threads:[~2026-07-07 3:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 19:04 [PATCH v5 0/2] ima: measure write on securityfs policy file Enrico Bravi
2026-07-02 19:04 ` [PATCH v5 1/2] ima: add critical data measurement for loaded policy Enrico Bravi
2026-07-07 3:04 ` Mimi Zohar [this message]
2026-07-07 11:25 ` Enrico Bravi
2026-07-07 23:53 ` Mimi Zohar
2026-07-02 19:04 ` [PATCH v5 2/2] ima: measure userspace policy writes before parsing Enrico Bravi
2026-07-07 3:03 ` Mimi Zohar
2026-07-07 15:25 ` Enrico Bravi
2026-07-07 20:06 ` Mimi Zohar
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=23b77eb601a40063738e0d9c4253fff51e304a11.camel@linux.ibm.com \
--to=zohar@linux.ibm.com \
--cc=dmitry.kasatkin@gmail.com \
--cc=enrico.bravi@polito.it \
--cc=eric.snowberg@oracle.com \
--cc=linux-integrity@vger.kernel.org \
--cc=roberto.sassu@huawei.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