Linux Integrity Measurement development
 help / color / mirror / Atom feed
From: Mimi Zohar <zohar@linux.ibm.com>
To: Enrico Bravi <enrico.bravi@polito.it>,
	"roberto.sassu@huawei.com" <roberto.sassu@huawei.com>,
	"linux-integrity@vger.kernel.org"
	<linux-integrity@vger.kernel.org>,
	"dmitry.kasatkin@gmail.com" <dmitry.kasatkin@gmail.com>
Cc: "eric.snowberg@oracle.com" <eric.snowberg@oracle.com>
Subject: Re: [RFC][PATCH v3 1/2] ima: measure loaded policy after write on securityfs policy file
Date: Thu, 11 Jun 2026 10:30:39 -0400	[thread overview]
Message-ID: <5703152fed864a39eb54cfccb571e9781a493760.camel@linux.ibm.com> (raw)
In-Reply-To: <7149d8e873fe59fedffd23a06c9c647d42660328.camel@polito.it>

On Thu, 2026-06-11 at 12:51 +0000, Enrico  Bravi wrote:
> 
> > > diff --git a/security/integrity/ima/ima_efi.c
> > > b/security/integrity/ima/ima_efi.c
> > > index 138029bfcce1..8e9f85ec9a86 100644
> > > --- a/security/integrity/ima/ima_efi.c
> > > +++ b/security/integrity/ima/ima_efi.c
> > > @@ -60,6 +60,8 @@ static const char * const sb_arch_rules[] = {
> > >  #endif
> > >  #if IS_ENABLED(CONFIG_INTEGRITY_MACHINE_KEYRING) &&
> > > IS_ENABLED(CONFIG_IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY)
> > >  	"appraise func=POLICY_CHECK appraise_type=imasig",
> > > +#else
> > > +	"measure func=CRITICAL_DATA label=ima_policy",
> > >  #endif
> > 
> >  None of the other arch "measure" policy rules are conditional.  Should the
> > new
> > "measure" rule be limited?
> 
> This condition aims to avoid measuring the policy loaded even if a signed policy
> is required. In that case, it would not be possible to directly write the policy
> in the securityfs file.

Good point. Since it is different than the other rules, could you add a comment
here or in the patch description.

> 
> > >  	"measure func=MODULE_CHECK",
> > >  	NULL
> > > diff --git a/security/integrity/ima/ima_fs.c
> > > b/security/integrity/ima/ima_fs.c
> > > index 012a58959ff0..75cb308cf01f 100644
> > > --- a/security/integrity/ima/ima_fs.c
> > > +++ b/security/integrity/ima/ima_fs.c
> > > 
> > > @@ -2381,3 +2380,55 @@ bool ima_appraise_signature(enum kernel_read_file_id
> > > id)
> > >  	return found;
> > >  }
> > >  #endif /* CONFIG_IMA_APPRAISE && CONFIG_INTEGRITY_TRUSTED_KEYRING */
> > > +
> > 
> > Please add kernel-doc here, something like:
> > 
> > /**
> >  * 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.
> >  */
> 
> Sure, thank you. If it is ok for you I can directly add what you suggested.

This was suggested by Claude, so it should be acceptable to use.

> 
> > > +void ima_measure_loaded_policy(void)
> > > +{
> > > +	const char *event_name = "ima_policy_loaded";
> > > +	const char *op = "measure_loaded_ima_policy";
> > > +	const char *audit_cause = "ENOMEM";
> > > +	struct ima_rule_entry *rule_entry;
> > > +	struct list_head *ima_rules_tmp;
> > > +	struct seq_file file;
> > > +	int result = -ENOMEM;
> > > +	size_t file_len;
> > > +	char rule[255];
> > 
> > The 255-byte buffer may be insufficient for custom policy rules that include
> > additional fields such as LSM labels and other file metadata, unlike the
> > simpler
> > built-in and architecture-specific rules. Please increase the buffer size to
> > accommodate the worst-case serialized rule length.
> 
> Yes, I wrongly took as reference the arch policy rules case. I don't know if the
> worst-case can be precisely estimated. I could increase the buffer size and
> check in any case if seq_has_overflowed(). Could it be an idea?

Sounds good.

> 
> > > +
> > > +	/* calculate IMA policy rules memory size */
> > > +	file.buf = rule;
> > > +	file.read_pos = 0;
> > > +	file.size = 255;
> > > +	file.count = 0;
> > > +
> > 
> > Please add "lockdep_assert_held(&ima_write_mutex);"  here.
> 
> Yes, and this would actually fail because I'm not acquiring ima_write_mutex in
> ima_release_policy().

Thanks.

Mimi
> > 

  reply	other threads:[~2026-06-11 14:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-26 13:51 [RFC][PATCH v3 0/2] ima: measure write on securityfs policy file Enrico Bravi
2026-05-26 13:51 ` [RFC][PATCH v3 1/2] ima: measure loaded policy after " Enrico Bravi
2026-06-10 14:32   ` Mimi Zohar
2026-06-11 12:51     ` Enrico  Bravi
2026-06-11 14:30       ` Mimi Zohar [this message]
2026-06-12  9:19         ` Enrico  Bravi
2026-05-26 13:51 ` [RFC][PATCH v3 2/2] ima: measure buffer sent to " Enrico Bravi
2026-06-10 18:59   ` Mimi Zohar
2026-06-11 13:41     ` Roberto Sassu

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=5703152fed864a39eb54cfccb571e9781a493760.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