security/integrity/ima/ima_template_lib.c
Source file repositories/reference/linux-study-clean/security/integrity/ima/ima_template_lib.c
File Facts
- System
- Linux kernel
- Corpus path
security/integrity/ima/ima_template_lib.c- Extension
.c- Size
- 20174 bytes
- Lines
- 765
- 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.
- 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
ima_template_lib.hlinux/xattr.hlinux/evm.h
Detected Declarations
enum data_formatsenum digest_typefunction Copyrightfunction ima_write_template_field_datafunction fieldsfunction ima_show_template_data_asciifunction ima_show_template_data_binaryfunction ima_show_template_field_datafunction ima_show_template_digestfunction ima_show_template_digest_ngfunction ima_show_template_digest_ngv2function ima_show_template_stringfunction ima_show_template_sigfunction ima_show_template_buffunction ima_show_template_uintfunction ima_parse_buffunction ima_eventdigest_init_commonfunction eventfunction eventfunction eventfunction ima_eventdigest_modsig_initfunction ima_eventname_init_commonfunction eventfunction eventfunction ima_eventsig_initfunction ima_eventbuf_initfunction ima_eventmodsig_initfunction ima_eventevmsig_initfunction ima_eventinodedac_init_commonfunction ima_eventinodeuid_initfunction ima_eventinodegid_initfunction ima_eventinodemode_initfunction ima_eventinodexattrs_init_commonfunction ima_eventinodexattrnames_initfunction ima_eventinodexattrlengths_initfunction ima_eventinodexattrvalues_init
Annotated Snippet
switch (field_data->len) {
case sizeof(u8):
seq_printf(m, "%u", *(u8 *)buf_ptr);
break;
case sizeof(u16):
if (ima_canonical_fmt)
seq_printf(m, "%u",
le16_to_cpu(*(__le16 *)buf_ptr));
else
seq_printf(m, "%u", *(u16 *)buf_ptr);
break;
case sizeof(u32):
if (ima_canonical_fmt)
seq_printf(m, "%u",
le32_to_cpu(*(__le32 *)buf_ptr));
else
seq_printf(m, "%u", *(u32 *)buf_ptr);
break;
case sizeof(u64):
if (ima_canonical_fmt)
seq_printf(m, "%llu",
le64_to_cpu(*(__le64 *)buf_ptr));
else
seq_printf(m, "%llu", *(u64 *)buf_ptr);
break;
default:
break;
}
break;
default:
break;
}
}
static void ima_show_template_data_binary(struct seq_file *m,
enum ima_show_type show,
enum data_formats datafmt,
struct ima_field_data *field_data)
{
u32 len = (show == IMA_SHOW_BINARY_OLD_STRING_FMT) ?
strlen(field_data->data) : field_data->len;
if (show != IMA_SHOW_BINARY_NO_FIELD_LEN) {
u32 field_len = !ima_canonical_fmt ?
len : (__force u32)cpu_to_le32(len);
ima_putc(m, &field_len, sizeof(field_len));
}
if (!len)
return;
ima_putc(m, field_data->data, len);
}
static void ima_show_template_field_data(struct seq_file *m,
enum ima_show_type show,
enum data_formats datafmt,
struct ima_field_data *field_data)
{
switch (show) {
case IMA_SHOW_ASCII:
ima_show_template_data_ascii(m, show, datafmt, field_data);
break;
case IMA_SHOW_BINARY:
case IMA_SHOW_BINARY_NO_FIELD_LEN:
case IMA_SHOW_BINARY_OLD_STRING_FMT:
ima_show_template_data_binary(m, show, datafmt, field_data);
break;
default:
break;
}
}
void ima_show_template_digest(struct seq_file *m, enum ima_show_type show,
struct ima_field_data *field_data)
{
ima_show_template_field_data(m, show, DATA_FMT_DIGEST, field_data);
}
void ima_show_template_digest_ng(struct seq_file *m, enum ima_show_type show,
struct ima_field_data *field_data)
{
ima_show_template_field_data(m, show, DATA_FMT_DIGEST_WITH_ALGO,
field_data);
}
void ima_show_template_digest_ngv2(struct seq_file *m, enum ima_show_type show,
struct ima_field_data *field_data)
{
Annotation
- Immediate include surface: `ima_template_lib.h`, `linux/xattr.h`, `linux/evm.h`.
- Detected declarations: `enum data_formats`, `enum digest_type`, `function Copyright`, `function ima_write_template_field_data`, `function fields`, `function ima_show_template_data_ascii`, `function ima_show_template_data_binary`, `function ima_show_template_field_data`, `function ima_show_template_digest`, `function ima_show_template_digest_ng`.
- Atlas domain: Core OS / Security And Isolation.
- Implementation status: source implementation candidate.
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.