Skip to content

Commit 4a804b8

Browse files
robertosassumimizohar
authored andcommitted
evm: Introduce evm_hmac_disabled() to safely ignore verification errors
When a file is being created, LSMs can set the initial label with the inode_init_security hook. If no HMAC key is loaded, the new file will have LSM xattrs but not the HMAC. It is also possible that the file remains without protected xattrs after creation if no active LSM provided it, or because the filesystem does not support them. Unfortunately, EVM will deny any further metadata operation on new files, as evm_protect_xattr() will return the INTEGRITY_NOLABEL error if protected xattrs exist without security.evm, INTEGRITY_NOXATTRS if no protected xattrs exist or INTEGRITY_UNKNOWN if xattrs are not supported. This would limit the usability of EVM when only a public key is loaded, as commands such as cp or tar with the option to preserve xattrs won't work. This patch introduces the evm_hmac_disabled() function to determine whether or not it is safe to ignore verification errors, based on the ability of EVM to calculate HMACs. If the HMAC key is not loaded, and it cannot be loaded in the future due to the EVM_SETUP_COMPLETE initialization flag, allowing an operation despite the attrs/xattrs being found invalid will not make them valid. Since the post hooks can be executed even when the HMAC key is not loaded, this patch also ensures that the EVM_INIT_HMAC initialization flag is set before the post hooks call evm_update_evmxattr(). Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Suggested-by: Mimi Zohar <zohar@linux.ibm.com> (for ensuring EVM_INIT_HMAC is set) Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent e3ccfe1 commit 4a804b8

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

security/integrity/evm/evm_main.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,24 @@ static bool evm_key_loaded(void)
9090
return (bool)(evm_initialized & EVM_KEY_MASK);
9191
}
9292

93+
/*
94+
* This function determines whether or not it is safe to ignore verification
95+
* errors, based on the ability of EVM to calculate HMACs. If the HMAC key
96+
* is not loaded, and it cannot be loaded in the future due to the
97+
* EVM_SETUP_COMPLETE initialization flag, allowing an operation despite the
98+
* attrs/xattrs being found invalid will not make them valid.
99+
*/
100+
static bool evm_hmac_disabled(void)
101+
{
102+
if (evm_initialized & EVM_INIT_HMAC)
103+
return false;
104+
105+
if (!(evm_initialized & EVM_SETUP_COMPLETE))
106+
return false;
107+
108+
return true;
109+
}
110+
93111
static int evm_find_protected_xattrs(struct dentry *dentry)
94112
{
95113
struct inode *inode = d_backing_inode(dentry);
@@ -338,6 +356,10 @@ static int evm_protect_xattr(struct dentry *dentry, const char *xattr_name,
338356
if (evm_status == INTEGRITY_NOXATTRS) {
339357
struct integrity_iint_cache *iint;
340358

359+
/* Exception if the HMAC is not going to be calculated. */
360+
if (evm_hmac_disabled())
361+
return 0;
362+
341363
iint = integrity_iint_find(d_backing_inode(dentry));
342364
if (iint && (iint->flags & IMA_NEW_FILE))
343365
return 0;
@@ -354,6 +376,10 @@ static int evm_protect_xattr(struct dentry *dentry, const char *xattr_name,
354376
-EPERM, 0);
355377
}
356378
out:
379+
/* Exception if the HMAC is not going to be calculated. */
380+
if (evm_hmac_disabled() && (evm_status == INTEGRITY_NOLABEL ||
381+
evm_status == INTEGRITY_UNKNOWN))
382+
return 0;
357383
if (evm_status != INTEGRITY_PASS)
358384
integrity_audit_msg(AUDIT_INTEGRITY_METADATA, d_backing_inode(dentry),
359385
dentry->d_name.name, "appraise_metadata",
@@ -474,6 +500,9 @@ void evm_inode_post_setxattr(struct dentry *dentry, const char *xattr_name,
474500
if (!strcmp(xattr_name, XATTR_NAME_EVM))
475501
return;
476502

503+
if (!(evm_initialized & EVM_INIT_HMAC))
504+
return;
505+
477506
evm_update_evmxattr(dentry, xattr_name, xattr_value, xattr_value_len);
478507
}
479508

@@ -497,6 +526,9 @@ void evm_inode_post_removexattr(struct dentry *dentry, const char *xattr_name)
497526
if (!strcmp(xattr_name, XATTR_NAME_EVM))
498527
return;
499528

529+
if (!(evm_initialized & EVM_INIT_HMAC))
530+
return;
531+
500532
evm_update_evmxattr(dentry, xattr_name, NULL, 0);
501533
}
502534

@@ -522,7 +554,9 @@ int evm_inode_setattr(struct dentry *dentry, struct iattr *attr)
522554
return 0;
523555
evm_status = evm_verify_current_integrity(dentry);
524556
if ((evm_status == INTEGRITY_PASS) ||
525-
(evm_status == INTEGRITY_NOXATTRS))
557+
(evm_status == INTEGRITY_NOXATTRS) ||
558+
(evm_hmac_disabled() && (evm_status == INTEGRITY_NOLABEL ||
559+
evm_status == INTEGRITY_UNKNOWN)))
526560
return 0;
527561
integrity_audit_msg(AUDIT_INTEGRITY_METADATA, d_backing_inode(dentry),
528562
dentry->d_name.name, "appraise_metadata",
@@ -548,6 +582,9 @@ void evm_inode_post_setattr(struct dentry *dentry, int ia_valid)
548582

549583
evm_reset_status(dentry->d_inode);
550584

585+
if (!(evm_initialized & EVM_INIT_HMAC))
586+
return;
587+
551588
if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID))
552589
evm_update_evmxattr(dentry, NULL, NULL, 0);
553590
}

0 commit comments

Comments
 (0)