Skip to content

Commit cd708c9

Browse files
committed
evm: add support to disable EVM on unsupported filesystems
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>
1 parent 40ca4ee commit cd708c9

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

include/linux/fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,7 @@ extern int send_sigurg(struct fown_struct *fown);
11641164
#define SB_I_USERNS_VISIBLE 0x00000010 /* fstype already mounted */
11651165
#define SB_I_IMA_UNVERIFIABLE_SIGNATURE 0x00000020
11661166
#define SB_I_UNTRUSTED_MOUNTER 0x00000040
1167+
#define SB_I_EVM_UNSUPPORTED 0x00000080
11671168

11681169
#define SB_I_SKIP_SYNC 0x00000100 /* Skip superblock at global sync */
11691170
#define SB_I_PERSB_BDI 0x00000200 /* has a per-sb bdi */

security/integrity/evm/evm_main.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ static int evm_find_protected_xattrs(struct dentry *dentry)
151151
return count;
152152
}
153153

154+
static int is_unsupported_fs(struct dentry *dentry)
155+
{
156+
struct inode *inode = d_backing_inode(dentry);
157+
158+
if (inode->i_sb->s_iflags & SB_I_EVM_UNSUPPORTED) {
159+
pr_info_once("%s not supported\n", inode->i_sb->s_type->name);
160+
return 1;
161+
}
162+
return 0;
163+
}
164+
154165
/*
155166
* evm_verify_hmac - calculate and compare the HMAC with the EVM xattr
156167
*
@@ -181,6 +192,9 @@ static enum integrity_status evm_verify_hmac(struct dentry *dentry,
181192
iint->evm_status == INTEGRITY_PASS_IMMUTABLE))
182193
return iint->evm_status;
183194

195+
if (is_unsupported_fs(dentry))
196+
return INTEGRITY_UNKNOWN;
197+
184198
/* if status is not PASS, try to check again - against -ENOMEM */
185199

186200
/* first need to know the sig type */
@@ -408,6 +422,9 @@ enum integrity_status evm_verifyxattr(struct dentry *dentry,
408422
if (!evm_key_loaded() || !evm_protected_xattr(xattr_name))
409423
return INTEGRITY_UNKNOWN;
410424

425+
if (is_unsupported_fs(dentry))
426+
return INTEGRITY_UNKNOWN;
427+
411428
if (!iint) {
412429
iint = integrity_iint_find(d_backing_inode(dentry));
413430
if (!iint)
@@ -491,15 +508,21 @@ static int evm_protect_xattr(struct mnt_idmap *idmap,
491508
if (strcmp(xattr_name, XATTR_NAME_EVM) == 0) {
492509
if (!capable(CAP_SYS_ADMIN))
493510
return -EPERM;
511+
if (is_unsupported_fs(dentry))
512+
return -EPERM;
494513
} else if (!evm_protected_xattr(xattr_name)) {
495514
if (!posix_xattr_acl(xattr_name))
496515
return 0;
516+
if (is_unsupported_fs(dentry))
517+
return 0;
518+
497519
evm_status = evm_verify_current_integrity(dentry);
498520
if ((evm_status == INTEGRITY_PASS) ||
499521
(evm_status == INTEGRITY_NOXATTRS))
500522
return 0;
501523
goto out;
502-
}
524+
} else if (is_unsupported_fs(dentry))
525+
return 0;
503526

504527
evm_status = evm_verify_current_integrity(dentry);
505528
if (evm_status == INTEGRITY_NOXATTRS) {
@@ -750,6 +773,9 @@ void evm_inode_post_setxattr(struct dentry *dentry, const char *xattr_name,
750773
if (!(evm_initialized & EVM_INIT_HMAC))
751774
return;
752775

776+
if (is_unsupported_fs(dentry))
777+
return;
778+
753779
evm_update_evmxattr(dentry, xattr_name, xattr_value, xattr_value_len);
754780
}
755781

@@ -814,8 +840,12 @@ int evm_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
814840
if (evm_initialized & EVM_ALLOW_METADATA_WRITES)
815841
return 0;
816842

843+
if (is_unsupported_fs(dentry))
844+
return 0;
845+
817846
if (!(ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID)))
818847
return 0;
848+
819849
evm_status = evm_verify_current_integrity(dentry);
820850
/*
821851
* 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)
859889
if (!(evm_initialized & EVM_INIT_HMAC))
860890
return;
861891

892+
if (is_unsupported_fs(dentry))
893+
return;
894+
862895
if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID))
863896
evm_update_evmxattr(dentry, NULL, NULL, 0);
864897
}

0 commit comments

Comments
 (0)