security/selinux/avc.c
Source file repositories/reference/linux-study-clean/security/selinux/avc.c
File Facts
- System
- Linux kernel
- Corpus path
security/selinux/avc.c- Extension
.c- Size
- 31962 bytes
- Lines
- 1209
- 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/types.hlinux/stddef.hlinux/kernel.hlinux/slab.hlinux/fs.hlinux/dcache.hlinux/init.hlinux/skbuff.hlinux/percpu.hlinux/list.hnet/sock.hlinux/un.hnet/af_unix.hlinux/ip.hlinux/audit.hlinux/ipv6.hnet/ipv6.havc.havc_ss.hclassmap.hhash.htrace/events/avc.h
Detected Declarations
struct avc_entrystruct avc_nodestruct avc_xperms_decision_nodestruct avc_xperms_nodestruct avc_cachestruct avc_callback_nodestruct selinux_avcfunction selinux_avc_initfunction avc_get_cache_thresholdfunction avc_set_cache_thresholdfunction avc_hashfunction avc_initfunction avc_get_hash_statsfunction avc_xperms_decision_lookupfunction list_for_each_entryfunction avc_xperms_has_permfunction avc_xperms_allow_permfunction avc_xperms_decision_freefunction avc_xperms_freefunction list_for_each_entry_safefunction avc_copy_xperms_decisionfunction avc_quick_copy_xperms_decisionfunction avc_add_xperms_decisionfunction avc_xperms_populatefunction avc_xperms_audit_requiredfunction avc_xperms_auditfunction avc_node_freefunction avc_node_deletefunction avc_node_killfunction avc_node_replacefunction avc_reclaim_nodefunction hlist_for_each_entryfunction avc_node_populatefunction avc_latest_notif_updatefunction security_compute_avfunction avc_audit_pre_callbackfunction avc_audit_post_callbackfunction rcu_read_lockfunction avc_add_callbackfunction kmallocfunction hlist_for_each_entryfunction avc_flushfunction avc_ss_resetfunction avc_compute_avfunction avc_deniedfunction avc_has_extended_permsfunction avc_perm_nonodefunction pair
Annotated Snippet
struct avc_entry {
u32 ssid;
u32 tsid;
u16 tclass;
struct av_decision avd;
struct avc_xperms_node *xp_node;
};
struct avc_node {
struct avc_entry ae;
struct hlist_node list; /* anchored in avc_cache->slots[i] */
struct rcu_head rhead;
};
struct avc_xperms_decision_node {
struct extended_perms_decision xpd;
struct list_head xpd_list; /* list of extended_perms_decision */
};
struct avc_xperms_node {
struct extended_perms xp;
struct list_head xpd_head; /* list head of extended_perms_decision */
};
struct avc_cache {
struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
atomic_t lru_hint; /* LRU hint for reclaim scan */
atomic_t active_nodes;
u32 latest_notif; /* latest revocation notification */
};
struct avc_callback_node {
int (*callback) (u32 event);
u32 events;
struct avc_callback_node *next;
};
#ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
DEFINE_PER_CPU(struct avc_cache_stats, avc_cache_stats) = { 0 };
#endif
struct selinux_avc {
unsigned int avc_cache_threshold;
struct avc_cache avc_cache;
};
static struct selinux_avc selinux_avc;
void selinux_avc_init(void)
{
int i;
selinux_avc.avc_cache_threshold = AVC_DEF_CACHE_THRESHOLD;
for (i = 0; i < AVC_CACHE_SLOTS; i++) {
INIT_HLIST_HEAD(&selinux_avc.avc_cache.slots[i]);
spin_lock_init(&selinux_avc.avc_cache.slots_lock[i]);
}
atomic_set(&selinux_avc.avc_cache.active_nodes, 0);
atomic_set(&selinux_avc.avc_cache.lru_hint, 0);
}
unsigned int avc_get_cache_threshold(void)
{
return selinux_avc.avc_cache_threshold;
}
void avc_set_cache_threshold(unsigned int cache_threshold)
{
selinux_avc.avc_cache_threshold = cache_threshold;
}
static struct avc_callback_node *avc_callbacks __ro_after_init;
static struct kmem_cache *avc_node_cachep __ro_after_init;
static struct kmem_cache *avc_xperms_data_cachep __ro_after_init;
static struct kmem_cache *avc_xperms_decision_cachep __ro_after_init;
static struct kmem_cache *avc_xperms_cachep __ro_after_init;
static inline u32 avc_hash(u32 ssid, u32 tsid, u16 tclass)
{
return av_hash(ssid, tsid, (u32)tclass, (u32)(AVC_CACHE_SLOTS - 1));
}
/**
* avc_init - Initialize the AVC.
*
* Initialize the access vector cache.
*/
void __init avc_init(void)
{
Annotation
- Immediate include surface: `linux/types.h`, `linux/stddef.h`, `linux/kernel.h`, `linux/slab.h`, `linux/fs.h`, `linux/dcache.h`, `linux/init.h`, `linux/skbuff.h`.
- Detected declarations: `struct avc_entry`, `struct avc_node`, `struct avc_xperms_decision_node`, `struct avc_xperms_node`, `struct avc_cache`, `struct avc_callback_node`, `struct selinux_avc`, `function selinux_avc_init`, `function avc_get_cache_threshold`, `function avc_set_cache_threshold`.
- 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.