security/apparmor/policy_unpack.c
Source file repositories/reference/linux-study-clean/security/apparmor/policy_unpack.c
File Facts
- System
- Linux kernel
- Corpus path
security/apparmor/policy_unpack.c- Extension
.c- Size
- 44043 bytes
- Lines
- 1804
- Domain
- Core OS
- Bucket
- Security And Isolation
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/unaligned.hkunit/visibility.hlinux/ctype.hlinux/errno.hlinux/zstd.hinclude/apparmor.hinclude/audit.hinclude/cred.hinclude/crypto.hinclude/file.hinclude/match.hinclude/path.hinclude/policy.hinclude/policy_unpack.hinclude/policy_compat.hinclude/signal.h
Detected Declarations
function Copyrightfunction audit_ifacefunction __aa_loaddata_updatefunction aa_rawdata_eqfunction do_loaddata_freefunction aa_loaddata_kreffunction do_ploaddata_rmfsfunction aa_ploaddata_kreffunction aa_inboundsfunction aa_unpack_u16_chunkfunction aa_unpack_Xfunction successfunction unpack_u8function aa_unpack_u32function aa_unpack_u64function aa_unpack_cap_lowfunction aa_unpack_cap_highfunction aa_unpack_arrayfunction aa_unpack_blobfunction aa_unpack_strfunction aa_unpack_strdupfunction process_strs_entryfunction unpack_strs_tablefunction unpack_xattrsfunction unpack_secmarkfunction unpack_rlimitsfunction verify_tagsfunction unpack_tagsetsfunction unpack_tag_header_entfunction unpack_tag_headersfunction unpack_tagsfunction unpack_permfunction unpack_perms_tablefunction unpack_pdbfunction strhashfunction datacmpfunction verify_headerfunction verify_dfa_accept_indexfunction verify_permfunction verify_permsfunction verify_profilefunction aa_load_ent_freefunction compress_zstdfunction compress_loaddatafunction profile
Annotated Snippet
if (aa_inbounds(e, (size_t) size)) {
*blob = e->pos;
e->pos += size;
return size;
}
}
fail:
e->pos = pos;
return 0;
}
EXPORT_SYMBOL_IF_KUNIT(aa_unpack_blob);
VISIBLE_IF_KUNIT int aa_unpack_str(struct aa_ext *e, const char **string, const char *name)
{
char *src_str;
size_t size = 0;
void *pos = e->pos;
*string = NULL;
if (aa_unpack_nameX(e, AA_STRING, name)) {
size = aa_unpack_u16_chunk(e, &src_str);
if (size) {
/* strings are null terminated, length is size - 1 */
if (src_str[size - 1] != 0)
goto fail;
*string = src_str;
return size;
}
}
fail:
e->pos = pos;
return 0;
}
EXPORT_SYMBOL_IF_KUNIT(aa_unpack_str);
VISIBLE_IF_KUNIT int aa_unpack_strdup(struct aa_ext *e, char **string, const char *name)
{
const char *tmp;
void *pos = e->pos;
int res = aa_unpack_str(e, &tmp, name);
*string = NULL;
if (!res)
return 0;
*string = kmemdup(tmp, res, GFP_KERNEL);
if (!*string) {
e->pos = pos;
return 0;
}
return res;
}
EXPORT_SYMBOL_IF_KUNIT(aa_unpack_strdup);
/**
* unpack_dfa - unpack a file rule dfa
* @e: serialized data extent information (NOT NULL)
* @flags: dfa flags to check
*
* returns dfa or ERR_PTR or NULL if no dfa
*/
static struct aa_dfa *unpack_dfa(struct aa_ext *e, int flags)
{
char *blob = NULL;
size_t size;
struct aa_dfa *dfa = NULL;
size = aa_unpack_blob(e, &blob, "aadfa");
if (size) {
/*
* The dfa is aligned with in the blob to 8 bytes
* from the beginning of the stream.
* alignment adjust needed by dfa unpack
*/
size_t sz = blob - (char *) e->start -
((e->pos - e->start) & 7);
size_t pad = ALIGN(sz, 8) - sz;
if (aa_g_paranoid_load)
flags |= DFA_FLAG_VERIFY_STATES;
dfa = aa_dfa_unpack(blob + pad, size - pad, flags);
if (IS_ERR(dfa))
return dfa;
}
Annotation
- Immediate include surface: `linux/unaligned.h`, `kunit/visibility.h`, `linux/ctype.h`, `linux/errno.h`, `linux/zstd.h`, `include/apparmor.h`, `include/audit.h`, `include/cred.h`.
- Detected declarations: `function Copyright`, `function audit_iface`, `function __aa_loaddata_update`, `function aa_rawdata_eq`, `function do_loaddata_free`, `function aa_loaddata_kref`, `function do_ploaddata_rmfs`, `function aa_ploaddata_kref`, `function aa_inbounds`, `function aa_unpack_u16_chunk`.
- Atlas domain: Core OS / Security And Isolation.
- Implementation status: integration 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.