]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
evm: fix security.evm for a file with IMA signature
authorCoiby Xu <coxu@redhat.com>
Tue, 30 Sep 2025 02:26:56 +0000 (10:26 +0800)
committerMimi Zohar <zohar@linux.ibm.com>
Thu, 5 Mar 2026 16:39:39 +0000 (11:39 -0500)
When both IMA and EVM fix modes are enabled, accessing a file with IMA
signature but missing EVM HMAC won't cause security.evm to be fixed.

Add a function evm_fix_hmac which will be explicitly called to fix EVM
HMAC for this case.

Suggested-by: Mimi Zohar <zohar@linux.ibm.com>
Signed-off-by: Coiby Xu <coxu@redhat.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
include/linux/evm.h
security/integrity/evm/evm_main.c
security/integrity/ima/ima_appraise.c

index ddece4a6b25d1c6eaafdaeb7adb24c4e9c44c040..913f4573b2038e6a54ac53c27f5c751bf522854e 100644 (file)
@@ -18,6 +18,8 @@ extern enum integrity_status evm_verifyxattr(struct dentry *dentry,
                                             const char *xattr_name,
                                             void *xattr_value,
                                             size_t xattr_value_len);
+int evm_fix_hmac(struct dentry *dentry, const char *xattr_name,
+                const char *xattr_value, size_t xattr_value_len);
 int evm_inode_init_security(struct inode *inode, struct inode *dir,
                            const struct qstr *qstr, struct xattr *xattrs,
                            int *xattr_count);
@@ -51,6 +53,12 @@ static inline enum integrity_status evm_verifyxattr(struct dentry *dentry,
 {
        return INTEGRITY_UNKNOWN;
 }
+
+static inline int evm_fix_hmac(struct dentry *dentry, const char *xattr_name,
+                              const char *xattr_value, size_t xattr_value_len)
+{
+       return -EOPNOTSUPP;
+}
 #endif
 
 static inline int evm_inode_init_security(struct inode *inode, struct inode *dir,
index cfc3531cf53fd879843347f08a627842b651a215..1b0089b4b79611f63c9f77ed4e6b4a63b3d841ca 100644 (file)
@@ -795,6 +795,34 @@ bool evm_revalidate_status(const char *xattr_name)
        return true;
 }
 
+/**
+ * evm_fix_hmac - Calculate the HMAC and add it to security.evm for fix mode
+ * @dentry: pointer to the affected dentry which doesn't yet have security.evm
+ *          xattr
+ * @xattr_name: pointer to the affected extended attribute name
+ * @xattr_value: pointer to the new extended attribute value
+ * @xattr_value_len: pointer to the new extended attribute value length
+ *
+ * Expects to be called with i_mutex locked.
+ *
+ * Return: 0 on success, -EPERM/-ENOMEM/-EOPNOTSUPP on failure
+ */
+int evm_fix_hmac(struct dentry *dentry, const char *xattr_name,
+                const char *xattr_value, size_t xattr_value_len)
+
+{
+       if (!evm_fixmode || !evm_revalidate_status((xattr_name)))
+               return -EPERM;
+
+       if (!(evm_initialized & EVM_INIT_HMAC))
+               return -EPERM;
+
+       if (is_unsupported_hmac_fs(dentry))
+               return -EOPNOTSUPP;
+
+       return evm_update_evmxattr(dentry, xattr_name, xattr_value, xattr_value_len);
+}
+
 /**
  * evm_inode_post_setxattr - update 'security.evm' to reflect the changes
  * @dentry: pointer to the affected dentry
index ee2e0891febcc0146c53742d7719bb3bc4170c03..0d41d102626ace8e200f39f2382258829e066fa8 100644 (file)
@@ -591,6 +591,11 @@ out:
                     xattr_value->type != EVM_IMA_XATTR_DIGSIG)) {
                        if (!ima_fix_xattr(dentry, iint))
                                status = INTEGRITY_PASS;
+               } else if (status == INTEGRITY_NOLABEL) {
+                       if (!evm_fix_hmac(dentry, XATTR_NAME_IMA,
+                                         (const char *)xattr_value,
+                                         xattr_len))
+                               status = INTEGRITY_PASS;
                }
 
                /*