security/selinux/ss/avtab.c
Source file repositories/reference/linux-study-clean/security/selinux/ss/avtab.c
File Facts
- System
- Linux kernel
- Corpus path
security/selinux/ss/avtab.c- Extension
.c- Size
- 15415 bytes
- Lines
- 619
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitops.hlinux/kernel.hlinux/slab.hlinux/errno.havtab.hpolicydb.hhash.h
Detected Declarations
function avtab_hashfunction avtab_node_cmpfunction avtab_insertfunction avtab_search_next_nodefunction avtab_destroyfunction avtab_initfunction avtab_alloc_commonfunction avtab_allocfunction avtab_alloc_dupfunction avtab_hash_evalfunction avtab_read_itemfunction avtab_insertffunction avtab_readfunction avtab_write_itemfunction avtab_writefunction avtab_cache_init
Annotated Snippet
if (xperms == NULL) {
kmem_cache_free(avtab_node_cachep, newnode);
return NULL;
}
*xperms = *(datum->u.xperms);
newnode->datum.u.xperms = xperms;
} else {
newnode->datum.u.data = datum->u.data;
}
newnode->next = *dst;
*dst = newnode;
h->nel++;
return newnode;
}
static int avtab_node_cmp(const struct avtab_key *key1,
const struct avtab_key *key2)
{
u16 specified = key1->specified & ~(AVTAB_ENABLED | AVTAB_ENABLED_OLD);
if (key1->source_type == key2->source_type &&
key1->target_type == key2->target_type &&
key1->target_class == key2->target_class &&
(specified & key2->specified))
return 0;
if (key1->source_type < key2->source_type)
return -1;
if (key1->source_type == key2->source_type &&
key1->target_type < key2->target_type)
return -1;
if (key1->source_type == key2->source_type &&
key1->target_type == key2->target_type &&
key1->target_class < key2->target_class)
return -1;
return 1;
}
static int avtab_insert(struct avtab *h, const struct avtab_key *key,
const struct avtab_datum *datum)
{
u32 hvalue;
struct avtab_node *prev, *cur, *newnode;
int cmp;
if (!h || !h->nslot || h->nel == U32_MAX)
return -EINVAL;
hvalue = avtab_hash(key, h->mask);
for (prev = NULL, cur = h->htable[hvalue]; cur;
prev = cur, cur = cur->next) {
cmp = avtab_node_cmp(key, &cur->key);
/* extended perms may not be unique */
if (cmp == 0 && !(key->specified & AVTAB_XPERMS))
return -EEXIST;
if (cmp <= 0)
break;
}
newnode = avtab_insert_node(h, prev ? &prev->next : &h->htable[hvalue],
key, datum);
if (!newnode)
return -ENOMEM;
return 0;
}
/* Unlike avtab_insert(), this function allow multiple insertions of the same
* key/specified mask into the table, as needed by the conditional avtab.
* It also returns a pointer to the node inserted.
*/
struct avtab_node *avtab_insert_nonunique(struct avtab *h,
const struct avtab_key *key,
const struct avtab_datum *datum)
{
u32 hvalue;
struct avtab_node *prev, *cur;
int cmp;
if (!h || !h->nslot || h->nel == U32_MAX)
return NULL;
hvalue = avtab_hash(key, h->mask);
for (prev = NULL, cur = h->htable[hvalue]; cur;
prev = cur, cur = cur->next) {
cmp = avtab_node_cmp(key, &cur->key);
if (cmp <= 0)
break;
}
return avtab_insert_node(h, prev ? &prev->next : &h->htable[hvalue],
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/kernel.h`, `linux/slab.h`, `linux/errno.h`, `avtab.h`, `policydb.h`, `hash.h`.
- Detected declarations: `function avtab_hash`, `function avtab_node_cmp`, `function avtab_insert`, `function avtab_search_next_node`, `function avtab_destroy`, `function avtab_init`, `function avtab_alloc_common`, `function avtab_alloc`, `function avtab_alloc_dup`, `function avtab_hash_eval`.
- 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.