security/integrity/ima/ima_template.c
Source file repositories/reference/linux-study-clean/security/integrity/ima/ima_template.c
File Facts
- System
- Linux kernel
- Corpus path
security/integrity/ima/ima_template.c- Extension
.c- Size
- 14751 bytes
- Lines
- 538
- 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/rculist.hima.hima_template_lib.h
Detected Declarations
enum header_fieldsfunction ima_template_has_modsigfunction ima_template_setupfunction ima_template_fmt_setupfunction lookup_template_fieldfunction template_fmt_sizefunction template_desc_init_fieldsfunction ima_init_template_listfunction ima_init_templatefunction ima_restore_template_datafunction ima_restore_measurement_list
Annotated Snippet
if (len == 0 || len > IMA_TEMPLATE_FIELD_ID_MAX_LEN) {
pr_err("Invalid field with length %d\n", len);
return -EINVAL;
}
memcpy(tmp_field_id, template_fmt_ptr, len);
tmp_field_id[len] = '\0';
found_fields[i] = lookup_template_field(tmp_field_id);
if (!found_fields[i]) {
pr_err("field '%s' not found\n", tmp_field_id);
return -ENOENT;
}
}
if (fields && num_fields) {
*fields = kmalloc_objs(**fields, i);
if (*fields == NULL)
return -ENOMEM;
memcpy(*fields, found_fields, i * sizeof(**fields));
*num_fields = i;
}
return 0;
}
void ima_init_template_list(void)
{
int i;
if (!list_empty(&defined_templates))
return;
spin_lock(&template_list);
for (i = 0; i < ARRAY_SIZE(builtin_templates); i++) {
list_add_tail_rcu(&builtin_templates[i].list,
&defined_templates);
}
spin_unlock(&template_list);
}
struct ima_template_desc *ima_template_desc_current(void)
{
if (!ima_template) {
ima_init_template_list();
ima_template =
lookup_template_desc(CONFIG_IMA_DEFAULT_TEMPLATE);
}
return ima_template;
}
struct ima_template_desc *ima_template_desc_buf(void)
{
if (!ima_buf_template) {
ima_init_template_list();
ima_buf_template = lookup_template_desc("ima-buf");
}
return ima_buf_template;
}
int __init ima_init_template(void)
{
struct ima_template_desc *template = ima_template_desc_current();
int result;
result = template_desc_init_fields(template->fmt,
&(template->fields),
&(template->num_fields));
if (result < 0) {
pr_err("template %s init failed, result: %d\n",
(strlen(template->name) ?
template->name : template->fmt), result);
return result;
}
template = ima_template_desc_buf();
if (!template) {
pr_err("Failed to get ima-buf template\n");
return -EINVAL;
}
result = template_desc_init_fields(template->fmt,
&(template->fields),
&(template->num_fields));
if (result < 0)
pr_err("template %s init failed, result: %d\n",
(strlen(template->name) ?
template->name : template->fmt), result);
return result;
Annotation
- Immediate include surface: `linux/rculist.h`, `ima.h`, `ima_template_lib.h`.
- Detected declarations: `enum header_fields`, `function ima_template_has_modsig`, `function ima_template_setup`, `function ima_template_fmt_setup`, `function lookup_template_field`, `function template_fmt_size`, `function template_desc_init_fields`, `function ima_init_template_list`, `function ima_init_template`, `function ima_restore_template_data`.
- 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.