evm: add support to disable EVM on unsupported filesystems
authorMimi Zohar <zohar@linux.ibm.com>
Mon, 18 Dec 2023 13:06:40 +0000 (08:06 -0500)
committerMimi Zohar <zohar@linux.ibm.com>
Wed, 20 Dec 2023 12:40:07 +0000 (07:40 -0500)
Identify EVM unsupported filesystems by defining a new flag
SB_I_EVM_UNSUPPORTED.

Don't verify, write, remove or update 'security.evm' on unsupported
filesystems.

Acked-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
include/linux/fs.h
security/integrity/evm/evm_main.c

index 98b7a7a8c42e36cc140d14797cf8eb00f7c36f76..1474f36e9b38bafc6f97bb4478d6054bd91fbaaa 100644 (file)
@@ -1164,6 +1164,7 @@ extern int send_sigurg(struct fown_struct *fown);
 #define SB_I_USERNS_VISIBLE            0x00000010 /* fstype already mounted */
 #define SB_I_IMA_UNVERIFIABLE_SIGNATURE        0x00000020
 #define SB_I_UNTRUSTED_MOUNTER         0x00000040
+#define SB_I_EVM_UNSUPPORTED           0x00000080
 
 #define SB_I_SKIP_SYNC 0x00000100      /* Skip superblock at global sync */
 #define SB_I_PERSB_BDI 0x00000200      /* has a per-sb bdi */
index 02adba635b02cbfe083fe9f193bb6890cc023f66..cc7956d7878b3d79d0cbd48c1175a329869bd1a7 100644 (file)
@@ -151,6 +151,17 @@ static int evm_find_protected_xattrs(struct dentry *dentry)
        return count;
 }
 
+static int is_unsupported_fs(struct dentry *dentry)
+{
+       struct inode *inode = d_backing_inode(dentry);
+
+       if (inode->i_sb->s_iflags & SB_I_EVM_UNSUPPORTED) {
+               pr_info_once("%s not supported\n", inode->i_sb->s_type->name);
+               return 1;
+       }
+       return 0;
+}
+
 /*
  * evm_verify_hmac - calculate and compare the HMAC with the EVM xattr
  *
@@ -181,6 +192,9 @@ static enum integrity_status evm_verify_hmac(struct dentry *dentry,
                     iint->evm_status == INTEGRITY_PASS_IMMUTABLE))
                return iint->evm_status;
 
+       if (is_unsupported_fs(dentry))
+               return INTEGRITY_UNKNOWN;
+
        /* if status is not PASS, try to check again - against -ENOMEM */
 
        /* first need to know the sig type */
@@ -408,6 +422,9 @@ enum integrity_status evm_verifyxattr(struct dentry *dentry,
        if (!evm_key_loaded() || !evm_protected_xattr(xattr_name))
                return INTEGRITY_UNKNOWN;
 
+       if (is_unsupported_fs(dentry))
+               return INTEGRITY_UNKNOWN;
+
        if (!iint) {
                iint = integrity_iint_find(d_backing_inode(dentry));
                if (!iint)
@@ -491,15 +508,21 @@ static int evm_protect_xattr(struct mnt_idmap *idmap,
        if (strcmp(xattr_name, XATTR_NAME_EVM) == 0) {
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
+               if (is_unsupported_fs(dentry))
+                       return -EPERM;
        } else if (!evm_protected_xattr(xattr_name)) {
                if (!posix_xattr_acl(xattr_name))
                        return 0;
+               if (is_unsupported_fs(dentry))
+                       return 0;
+
                evm_status = evm_verify_current_integrity(dentry);
                if ((evm_status == INTEGRITY_PASS) ||
                    (evm_status == INTEGRITY_NOXATTRS))
                        return 0;
                goto out;
-       }
+       } else if (is_unsupported_fs(dentry))
+               return 0;
 
        evm_status = evm_verify_current_integrity(dentry);
        if (evm_status == INTEGRITY_NOXATTRS) {
@@ -750,6 +773,9 @@ void evm_inode_post_setxattr(struct dentry *dentry, const char *xattr_name,
        if (!(evm_initialized & EVM_INIT_HMAC))
                return;
 
+       if (is_unsupported_fs(dentry))
+               return;
+
        evm_update_evmxattr(dentry, xattr_name, xattr_value, xattr_value_len);
 }
 
@@ -814,8 +840,12 @@ int evm_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
        if (evm_initialized & EVM_ALLOW_METADATA_WRITES)
                return 0;
 
+       if (is_unsupported_fs(dentry))
+               return 0;
+
        if (!(ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID)))
                return 0;
+
        evm_status = evm_verify_current_integrity(dentry);
        /*
         * Writing attrs is safe for portable signatures, as portable signatures
@@ -859,6 +889,9 @@ void evm_inode_post_setattr(struct dentry *dentry, int ia_valid)
        if (!(evm_initialized & EVM_INIT_HMAC))
                return;
 
+       if (is_unsupported_fs(dentry))
+               return;
+
        if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID))
                evm_update_evmxattr(dentry, NULL, NULL, 0);
 }