Skip to content

Commit 7aa5783

Browse files
robertosassumimizohar
authored andcommitted
ima: Allow imasig requirement to be satisfied by EVM portable signatures
System administrators can require that all accessed files have a signature by specifying appraise_type=imasig in a policy rule. Currently, IMA signatures satisfy this requirement. Appended signatures may also satisfy this requirement, but are not applicable as IMA signatures. IMA/appended signatures ensure data source authentication for file content and prevent any change. EVM signatures instead ensure data source authentication for file metadata. Given that the digest or signature of the file content must be included in the metadata, EVM signatures provide the same file data guarantees of IMA signatures, as well as providing file metadata guarantees. This patch lets systems protected with EVM signatures pass appraisal verification if the appraise_type=imasig requirement is specified in the policy. This facilitates deployment in the scenarios where only EVM signatures are available. The patch makes the following changes: file xattr types: security.ima: IMA_XATTR_DIGEST/IMA_XATTR_DIGEST_NG security.evm: EVM_XATTR_PORTABLE_DIGSIG execve(), mmap(), open() behavior (with appraise_type=imasig): before: denied (file without IMA signature, imasig requirement not met) after: allowed (file with EVM portable signature, imasig requirement met) open(O_WRONLY) behavior (without appraise_type=imasig): before: allowed (file without IMA signature, not immutable) after: denied (file with EVM portable signature, immutable) In addition, similarly to IMA signatures, this patch temporarily allows new files without or with incomplete metadata to be opened so that content can be written. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent 1434c6a commit 7aa5783

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

security/integrity/ima/ima_appraise.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,16 @@ static int xattr_verify(enum ima_hooks func, struct integrity_iint_cache *iint,
242242
hash_start = 1;
243243
fallthrough;
244244
case IMA_XATTR_DIGEST:
245-
if (iint->flags & IMA_DIGSIG_REQUIRED) {
246-
*cause = "IMA-signature-required";
247-
*status = INTEGRITY_FAIL;
248-
break;
245+
if (*status != INTEGRITY_PASS_IMMUTABLE) {
246+
if (iint->flags & IMA_DIGSIG_REQUIRED) {
247+
*cause = "IMA-signature-required";
248+
*status = INTEGRITY_FAIL;
249+
break;
250+
}
251+
clear_bit(IMA_DIGSIG, &iint->atomic_flags);
252+
} else {
253+
set_bit(IMA_DIGSIG, &iint->atomic_flags);
249254
}
250-
clear_bit(IMA_DIGSIG, &iint->atomic_flags);
251255
if (xattr_len - sizeof(xattr_value->type) - hash_start >=
252256
iint->ima_hash->length)
253257
/*
@@ -417,6 +421,7 @@ int ima_appraise_measurement(enum ima_hooks func,
417421
cause = "missing-HMAC";
418422
goto out;
419423
case INTEGRITY_FAIL_IMMUTABLE:
424+
set_bit(IMA_DIGSIG, &iint->atomic_flags);
420425
fallthrough;
421426
case INTEGRITY_FAIL: /* Invalid HMAC/signature. */
422427
cause = "invalid-HMAC";
@@ -461,9 +466,12 @@ int ima_appraise_measurement(enum ima_hooks func,
461466
status = INTEGRITY_PASS;
462467
}
463468

464-
/* Permit new files with file signatures, but without data. */
469+
/*
470+
* Permit new files with file/EVM portable signatures, but
471+
* without data.
472+
*/
465473
if (inode->i_size == 0 && iint->flags & IMA_NEW_FILE &&
466-
xattr_value && xattr_value->type == EVM_IMA_XATTR_DIGSIG) {
474+
test_bit(IMA_DIGSIG, &iint->atomic_flags)) {
467475
status = INTEGRITY_PASS;
468476
}
469477

@@ -581,6 +589,8 @@ int ima_inode_setxattr(struct dentry *dentry, const char *xattr_name,
581589
if (!xattr_value_len || (xvalue->type >= IMA_XATTR_LAST))
582590
return -EINVAL;
583591
digsig = (xvalue->type == EVM_IMA_XATTR_DIGSIG);
592+
} else if (!strcmp(xattr_name, XATTR_NAME_EVM) && xattr_value_len > 0) {
593+
digsig = (xvalue->type == EVM_XATTR_PORTABLE_DIGSIG);
584594
}
585595
if (result == 1 || evm_revalidate_status(xattr_name)) {
586596
ima_reset_appraise_flags(d_backing_inode(dentry), digsig);

0 commit comments

Comments
 (0)