From: Mimi Zohar <zohar@linux.ibm.com>
To: Coiby Xu <coxu@redhat.com>
Cc: linux-integrity@vger.kernel.org,
Roberto Sassu <roberto.sassu@huawei.com>,
Dmitry Kasatkin <dmitry.kasatkin@gmail.com>,
Eric Snowberg <eric.snowberg@oracle.com>,
Paul Moore <paul@paul-moore.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>,
"open list:SECURITY SUBSYSTEM"
<linux-security-module@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ima: setting security.ima to fix security.evm for a file with IMA signature
Date: Wed, 24 Sep 2025 23:27:03 -0400 [thread overview]
Message-ID: <e74e81465e168a7f43583d5783850cc5fe7ca1c5.camel@linux.ibm.com> (raw)
In-Reply-To: <4l7l4duxfximhzixruim3lnij5mhnlqs5srzycc6j6c2bu5zda@ogoj3ade37fd>
On Wed, 2025-09-24 at 16:03 +0800, Coiby Xu wrote:
> On Mon, Sep 15, 2025 at 05:05:42PM -0400, Mimi Zohar wrote:
> > On Wed, 2025-09-10 at 09:20 +0800, Coiby Xu wrote:
> > > On Tue, Sep 09, 2025 at 11:31:20AM -0400, Mimi Zohar wrote:
> > > > On Tue, 2025-09-09 at 12:19 +0800, Coiby Xu wrote:
> > > > > When both IMA and EVM fix modes are enabled, accessing a file with IMA
> > > > > signature won't cause security.evm to be fixed. But this doesn't happen
> > > > > to a file with correct IMA hash already set because accessing it will
> > > > > cause setting security.ima again which triggers fixing security.evm
> > > > > thanks to security_inode_post_setxattr->evm_update_evmxattr.
> > > > >
> > > > > Let's use the same mechanism to fix security.evm for a file with IMA
> > > > > signature.
> > > > >
> [...]
> > > > > ---
> > > > > security/integrity/ima/ima_appraise.c | 27 +++++++++++++++++++++------
> > > > > 1 file changed, 21 insertions(+), 6 deletions(-)
> > > > >
> > > > > diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c
> > > > > index f435eff4667f..18c3907c5e44 100644
> > > > > --- a/security/integrity/ima/ima_appraise.c
> > > > > +++ b/security/integrity/ima/ima_appraise.c
> > > > > @@ -595,12 +595,27 @@ int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *iint,
> > > > > integrity_audit_msg(audit_msgno, inode, filename,
> > > > > op, cause, rc, 0);
> > > > > } else if (status != INTEGRITY_PASS) {
> > > > > - /* Fix mode, but don't replace file signatures. */
> > > > > - if ((ima_appraise & IMA_APPRAISE_FIX) && !try_modsig &&
> > > > > - (!xattr_value ||
> > > > > - xattr_value->type != EVM_IMA_XATTR_DIGSIG)) {
> > > > > - if (!ima_fix_xattr(dentry, iint))
> > > > > - status = INTEGRITY_PASS;
> > > > > + /*
> > > > > + * Fix mode, but don't replace file signatures.
> > > > > + *
> > > > > + * When EVM fix mode is also enabled, security.evm will be
> > > > > + * fixed automatically when security.ima is set because of
> > > > > + * security_inode_post_setxattr->evm_update_evmxattr.
> > > > > + */
> > > > > + if ((ima_appraise & IMA_APPRAISE_FIX) && !try_modsig) {
> > > > > + if (!xattr_value ||
> > > > > + xattr_value->type != EVM_IMA_XATTR_DIGSIG) {
> > > > > + if (ima_fix_xattr(dentry, iint))
> > > > > + status = INTEGRITY_PASS;
> > > > > + } else if (xattr_value->type == EVM_IMA_XATTR_DIGSIG &&
> > > > > + evm_revalidate_status(XATTR_NAME_IMA)) {
> > > > > + if (!__vfs_setxattr_noperm(&nop_mnt_idmap,
> > > > > + dentry,
> > > > > + XATTR_NAME_IMA,
> > > > > + xattr_value,
> > > > > + xattr_len, 0))
> > > > > + status = INTEGRITY_PASS;
> > > > > + }
> > > > > }
> >
> > Instead of re-writing the IMA signature without a clear explanation, define a
> > new EVM function named evm_fix_hmac() and add a call here in IMA. Only in EVM
> > fix mode would evm_fix_hmac() update the EVM hmac.
> >
> > } else if (status != INTEGRITY_PASS) {
> > /*
> > * IMA fix mode updates the IMA file hash, which triggers EVM
> > * to update security.evm. ....
> > *
> > * Similarly, trigger fixing EVM HMAC for IMA file signatures.
> > */
> > if ((ima_appraise & IMA_APPRAISE_FIX) && !try_modsig) {
> > if (!xattr_value ||
> > xattr_value->type != EVM_IMA_XATTR_DIGSIG) {
> > if (ima_fix_xattr(dentry, iint))
> > status = INTEGRITY_PASS;
> > } else if (status == INTEGRITY_NOLABEL) {
> > evm_fix_hmac(dentry, XATTR_NAME_IMA, ....);
> > }
> > }
>
> Thanks for the advice! I wonder if we should use existing
> evm_update_evmxattr instead of defining a new EVM function.
>
> /*
> * Calculate the hmac and update security.evm xattr
> *
> * Expects to be called with i_mutex locked.
> */
> int evm_update_evmxattr(struct dentry *dentry, const char *xattr_name,
> const char *xattr_value, size_t xattr_value_len)
> {
> }
>
>
> I already tried evm_update_evmxattr and can confirm it works. But later
> I switched to __vfs_setxattr_noperm because I thought it's consistent
> with current logic of adding security.evm when there is already correct
> security.ima and it's a slightly smaller change.
Calling evm_inode_updatexattr() is limited to EVM. Only after verifying the
existing EVM value is evm_inode_updatexattr() called. For example, in
evm_inode_setxattr() the existing EVM value is verified and then updated in
evm_inode_post_setxattr(), by calling evm_inode_updatexattr().
In this case, the new function evm_fix_hmac() would call evm_update_evmxattr()
only after verifying the EVM mode is set to fix.
next prev parent reply other threads:[~2025-09-25 3:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-09 4:19 [PATCH] ima: setting security.ima to fix security.evm for a file with IMA signature Coiby Xu
2025-09-09 15:31 ` Mimi Zohar
2025-09-10 1:20 ` Coiby Xu
2025-09-10 11:15 ` Mimi Zohar
2025-09-30 2:31 ` Coiby Xu
2025-09-15 21:05 ` Mimi Zohar
2025-09-24 8:03 ` Coiby Xu
2025-09-25 3:27 ` Mimi Zohar [this message]
2025-09-30 2:28 ` Coiby Xu
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=e74e81465e168a7f43583d5783850cc5fe7ca1c5.camel@linux.ibm.com \
--to=zohar@linux.ibm.com \
--cc=coxu@redhat.com \
--cc=dmitry.kasatkin@gmail.com \
--cc=eric.snowberg@oracle.com \
--cc=jmorris@namei.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=roberto.sassu@huawei.com \
--cc=serge@hallyn.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;
as well as URLs for NNTP newsgroup(s).