security/apparmor/lib.c
Source file repositories/reference/linux-study-clean/security/apparmor/lib.c
File Facts
- System
- Linux kernel
- Corpus path
security/apparmor/lib.c- Extension
.c- Size
- 11610 bytes
- Lines
- 516
- 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
linux/ctype.hlinux/mm.hlinux/slab.hlinux/string.hlinux/vmalloc.hinclude/audit.hinclude/apparmor.hinclude/lib.hinclude/perms.hinclude/policy.h
Detected Declarations
struct val_table_entfunction aa_parse_debug_paramsfunction val_mask_to_strfunction aa_print_debug_paramsfunction aa_resize_str_tablefunction aa_destroy_str_tablefunction aa_info_messagefunction aa_str_kreffunction aa_perm_mask_to_strfunction aa_audit_perm_namesfunction aa_audit_perm_maskfunction aa_apply_modes_to_permsfunction aa_profile_match_labelfunction aa_check_permsfunction aa_policy_initfunction aa_policy_destroy
Annotated Snippet
struct val_table_ent {
const char *str;
int value;
};
static struct val_table_ent debug_values_table[] = {
{ "N", DEBUG_NONE },
{ "none", DEBUG_NONE },
{ "n", DEBUG_NONE },
{ "0", DEBUG_NONE },
{ "all", DEBUG_ALL },
{ "Y", DEBUG_ALL },
{ "y", DEBUG_ALL },
{ "1", DEBUG_ALL },
{ "abs_root", DEBUG_LABEL_ABS_ROOT },
{ "label", DEBUG_LABEL },
{ "domain", DEBUG_DOMAIN },
{ "policy", DEBUG_POLICY },
{ "interface", DEBUG_INTERFACE },
{ "unpack", DEBUG_UNPACK },
{ "tags", DEBUG_TAGS },
{ NULL, 0 }
};
static struct val_table_ent *val_table_find_ent(struct val_table_ent *table,
const char *name, size_t len)
{
struct val_table_ent *entry;
for (entry = table; entry->str != NULL; entry++) {
if (strncmp(entry->str, name, len) == 0 &&
strlen(entry->str) == len)
return entry;
}
return NULL;
}
int aa_parse_debug_params(const char *str)
{
struct val_table_ent *ent;
const char *next;
int val = 0;
do {
size_t n = strcspn(str, "\r\n,");
next = str + n;
ent = val_table_find_ent(debug_values_table, str, next - str);
if (ent)
val |= ent->value;
else
AA_DEBUG(DEBUG_INTERFACE, "unknown debug type '%.*s'",
(int)(next - str), str);
str = next + 1;
} while (*next != 0);
return val;
}
/**
* val_mask_to_str - convert a perm mask to its short string
* @str: character buffer to store string in (at least 10 characters)
* @size: size of the @str buffer
* @table: NUL-terminated character buffer of permission characters (NOT NULL)
* @mask: permission mask to convert
*/
static int val_mask_to_str(char *str, size_t size,
const struct val_table_ent *table, u32 mask)
{
const struct val_table_ent *ent;
int total = 0;
for (ent = table; ent->str; ent++) {
if (ent->value && (ent->value & mask) == ent->value) {
int len = scnprintf(str, size, "%s%s", total ? "," : "",
ent->str);
size -= len;
str += len;
total += len;
mask &= ~ent->value;
}
}
return total;
}
int aa_print_debug_params(char *buffer)
{
if (!aa_g_debug)
return sprintf(buffer, "N");
return val_mask_to_str(buffer, PAGE_SIZE, debug_values_table,
Annotation
- Immediate include surface: `linux/ctype.h`, `linux/mm.h`, `linux/slab.h`, `linux/string.h`, `linux/vmalloc.h`, `include/audit.h`, `include/apparmor.h`, `include/lib.h`.
- Detected declarations: `struct val_table_ent`, `function aa_parse_debug_params`, `function val_mask_to_str`, `function aa_print_debug_params`, `function aa_resize_str_table`, `function aa_destroy_str_table`, `function aa_info_message`, `function aa_str_kref`, `function aa_perm_mask_to_str`, `function aa_audit_perm_names`.
- 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.