security/integrity/ima/ima_policy.c
Source file repositories/reference/linux-study-clean/security/integrity/ima/ima_policy.c
File Facts
- System
- Linux kernel
- Corpus path
security/integrity/ima/ima_policy.c- Extension
.c- Size
- 64849 bytes
- Lines
- 2383
- 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/init.hlinux/list.hlinux/kernel_read_file.hlinux/fs.hlinux/security.hlinux/magic.hlinux/parser.hlinux/slab.hlinux/rculist.hlinux/seq_file.hlinux/ima.hima.h
Detected Declarations
struct ima_rule_opt_liststruct ima_rule_entryenum lsm_rule_typesenum policy_typesenum policy_rule_listenum policy_optfunction vfsuid_gt_kuidfunction vfsgid_gt_kgidfunction vfsuid_lt_kuidfunction vfsgid_lt_kgidfunction default_measure_policy_setupfunction policy_setupfunction default_appraise_policy_setupfunction ima_free_rule_opt_listfunction ima_lsm_free_rulefunction ima_free_rulefunction ima_lsm_update_rulefunction ima_rule_contains_lsm_condfunction ima_lsm_update_rulesfunction list_for_each_entry_safefunction ima_lsm_policy_changefunction ima_match_rule_datafunction ima_match_rulesfunction get_subactionfunction ima_match_policyfunction ima_update_policy_flagsfunction setxattrfunction ima_appraise_flagfunction add_rulesfunction ima_init_arch_policyfunction ima_init_policyfunction ima_check_policyfunction ima_update_policyfunction ima_lsm_rule_initfunction ima_log_string_opfunction ima_log_stringfunction signaturefunction check_template_fieldfunction ima_validate_rulefunction ima_parse_appraise_algosfunction ima_parse_rulefunction strcmpfunction ima_write_policyfunction ima_delete_rulesfunction ima_policy_stopfunction ima_show_rule_opt_listfunction ima_policy_show_appraise_algosfunction ima_policy_show
Annotated Snippet
struct ima_rule_opt_list {
size_t count;
char *items[] __counted_by(count);
};
/*
* These comparators are needed nowhere outside of ima so just define them here.
* This pattern should hopefully never be needed outside of ima.
*/
static inline bool vfsuid_gt_kuid(vfsuid_t vfsuid, kuid_t kuid)
{
return __vfsuid_val(vfsuid) > __kuid_val(kuid);
}
static inline bool vfsgid_gt_kgid(vfsgid_t vfsgid, kgid_t kgid)
{
return __vfsgid_val(vfsgid) > __kgid_val(kgid);
}
static inline bool vfsuid_lt_kuid(vfsuid_t vfsuid, kuid_t kuid)
{
return __vfsuid_val(vfsuid) < __kuid_val(kuid);
}
static inline bool vfsgid_lt_kgid(vfsgid_t vfsgid, kgid_t kgid)
{
return __vfsgid_val(vfsgid) < __kgid_val(kgid);
}
struct ima_rule_entry {
struct list_head list;
int action;
unsigned int flags;
enum ima_hooks func;
int mask;
unsigned long fsmagic;
uuid_t fsuuid;
kuid_t uid;
kgid_t gid;
kuid_t fowner;
kgid_t fgroup;
bool (*uid_op)(kuid_t cred_uid, kuid_t rule_uid); /* Handlers for operators */
bool (*gid_op)(kgid_t cred_gid, kgid_t rule_gid);
bool (*fowner_op)(vfsuid_t vfsuid, kuid_t rule_uid); /* vfsuid_eq_kuid(), vfsuid_gt_kuid(), vfsuid_lt_kuid() */
bool (*fgroup_op)(vfsgid_t vfsgid, kgid_t rule_gid); /* vfsgid_eq_kgid(), vfsgid_gt_kgid(), vfsgid_lt_kgid() */
int pcr;
unsigned int allowed_algos; /* bitfield of allowed hash algorithms */
struct {
void *rule; /* LSM file metadata specific */
char *args_p; /* audit value */
int type; /* audit type */
} lsm[MAX_LSM_RULES];
char *fsname;
char *fs_subtype;
struct ima_rule_opt_list *keyrings; /* Measure keys added to these keyrings */
struct ima_rule_opt_list *label; /* Measure data grouped under this label */
struct ima_template_desc *template;
};
/*
* sanity check in case the kernels gains more hash algorithms that can
* fit in an unsigned int
*/
static_assert(
8 * sizeof(unsigned int) >= HASH_ALGO__LAST,
"The bitfield allowed_algos in ima_rule_entry is too small to contain all the supported hash algorithms, consider using a bigger type");
/*
* Without LSM specific knowledge, the default policy can only be
* written in terms of .action, .func, .mask, .fsmagic, .uid, .gid,
* .fowner, and .fgroup
*/
/*
* The minimum rule set to allow for full TCB coverage. Measures all files
* opened or mmap for exec and everything read by root. Dangerous because
* normal users can easily run the machine out of memory simply building
* and running executables.
*/
static struct ima_rule_entry dont_measure_rules[] __ro_after_init = {
{.action = DONT_MEASURE, .fsmagic = PROC_SUPER_MAGIC, .flags = IMA_FSMAGIC},
{.action = DONT_MEASURE, .fsmagic = SYSFS_MAGIC, .flags = IMA_FSMAGIC},
{.action = DONT_MEASURE, .fsmagic = DEBUGFS_MAGIC, .flags = IMA_FSMAGIC},
{.action = DONT_MEASURE, .fsmagic = TMPFS_MAGIC, .func = FILE_CHECK,
.flags = IMA_FSMAGIC | IMA_FUNC},
{.action = DONT_MEASURE, .fsmagic = DEVPTS_SUPER_MAGIC, .flags = IMA_FSMAGIC},
{.action = DONT_MEASURE, .fsmagic = BINFMTFS_MAGIC, .flags = IMA_FSMAGIC},
{.action = DONT_MEASURE, .fsmagic = SECURITYFS_MAGIC, .flags = IMA_FSMAGIC},
{.action = DONT_MEASURE, .fsmagic = SELINUX_MAGIC, .flags = IMA_FSMAGIC},
{.action = DONT_MEASURE, .fsmagic = SMACK_MAGIC, .flags = IMA_FSMAGIC},
Annotation
- Immediate include surface: `linux/init.h`, `linux/list.h`, `linux/kernel_read_file.h`, `linux/fs.h`, `linux/security.h`, `linux/magic.h`, `linux/parser.h`, `linux/slab.h`.
- Detected declarations: `struct ima_rule_opt_list`, `struct ima_rule_entry`, `enum lsm_rule_types`, `enum policy_types`, `enum policy_rule_list`, `enum policy_opt`, `function vfsuid_gt_kuid`, `function vfsgid_gt_kgid`, `function vfsuid_lt_kuid`, `function vfsgid_lt_kgid`.
- 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.