security/integrity/ima/ima_appraise.c
Source file repositories/reference/linux-study-clean/security/integrity/ima/ima_appraise.c
File Facts
- System
- Linux kernel
- Corpus path
security/integrity/ima/ima_appraise.c- Extension
.c- Size
- 22355 bytes
- Lines
- 832
- Domain
- Core OS
- Bucket
- Security And Isolation
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/init.hlinux/file.hlinux/binfmts.hlinux/fs.hlinux/xattr.hlinux/magic.hlinux/ima.hlinux/evm.hlinux/fsverity.hkeys/system_keyring.huapi/linux/fsverity.hima.h
Detected Declarations
function ima_appraise_parse_cmdlinefunction is_ima_appraise_enabledfunction ima_must_appraisefunction ima_fix_xattrfunction ima_get_cache_statusfunction ima_set_cache_statusfunction ima_cache_flagsfunction ima_get_hash_algofunction ima_read_xattrfunction xattr_verifyfunction modsig_verifyfunction ima_check_blacklistfunction evm_verifyxattrfunction ima_update_xattrfunction notify_changefunction ima_protect_xattrfunction ima_reset_appraise_flagsfunction validate_hash_algofunction ima_inode_setxattrfunction ima_inode_set_aclfunction ima_inode_removexattrfunction ima_inode_remove_aclfunction init_ima_appraise_lsm
Annotated Snippet
if (xattr_len == 21) {
unsigned int zero = 0;
if (!memcmp(&xattr_value->data[16], &zero, 4))
return HASH_ALGO_MD5;
else
return HASH_ALGO_SHA1;
} else if (xattr_len == 17)
return HASH_ALGO_MD5;
break;
}
/* return default hash algo */
return ima_hash_algo;
}
int ima_read_xattr(struct dentry *dentry,
struct evm_ima_xattr_data **xattr_value, int xattr_len)
{
int ret;
ret = vfs_getxattr_alloc(&nop_mnt_idmap, dentry, XATTR_NAME_IMA,
(char **)xattr_value, xattr_len, GFP_NOFS);
if (ret == -EOPNOTSUPP)
ret = 0;
return ret;
}
/*
* xattr_verify - verify xattr digest or signature
*
* Verify whether the hash or signature matches the file contents.
*
* Return 0 on success, error code otherwise.
*/
static int xattr_verify(enum ima_hooks func, struct ima_iint_cache *iint,
struct evm_ima_xattr_data *xattr_value, int xattr_len,
enum integrity_status *status, const char **cause)
{
struct signature_v2_hdr *sig;
int rc = -EINVAL, hash_start = 0;
int mask;
switch (xattr_value->type) {
case IMA_XATTR_DIGEST_NG:
/* first byte contains algorithm id */
hash_start = 1;
fallthrough;
case IMA_XATTR_DIGEST:
if (*status != INTEGRITY_PASS_IMMUTABLE) {
if (iint->flags & IMA_DIGSIG_REQUIRED) {
if (iint->flags & IMA_VERITY_REQUIRED)
*cause = "verity-signature-required";
else
*cause = "IMA-signature-required";
*status = INTEGRITY_FAIL;
break;
}
clear_bit(IMA_DIGSIG, &iint->atomic_flags);
} else {
set_bit(IMA_DIGSIG, &iint->atomic_flags);
}
if (xattr_len - sizeof(xattr_value->type) - hash_start >=
iint->ima_hash->length)
/*
* xattr length may be longer. md5 hash in previous
* version occupied 20 bytes in xattr, instead of 16
*/
rc = memcmp(&xattr_value->data[hash_start],
iint->ima_hash->digest,
iint->ima_hash->length);
else
rc = -EINVAL;
if (rc) {
*cause = "invalid-hash";
*status = INTEGRITY_FAIL;
break;
}
*status = INTEGRITY_PASS;
break;
case EVM_IMA_XATTR_DIGSIG:
set_bit(IMA_DIGSIG, &iint->atomic_flags);
mask = IMA_DIGSIG_REQUIRED | IMA_VERITY_REQUIRED;
if ((iint->flags & mask) == mask) {
*cause = "verity-signature-required";
*status = INTEGRITY_FAIL;
break;
}
sig = (typeof(sig))xattr_value;
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/file.h`, `linux/binfmts.h`, `linux/fs.h`, `linux/xattr.h`, `linux/magic.h`, `linux/ima.h`.
- Detected declarations: `function ima_appraise_parse_cmdline`, `function is_ima_appraise_enabled`, `function ima_must_appraise`, `function ima_fix_xattr`, `function ima_get_cache_status`, `function ima_set_cache_status`, `function ima_cache_flags`, `function ima_get_hash_algo`, `function ima_read_xattr`, `function xattr_verify`.
- Atlas domain: Core OS / Security And Isolation.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.