security/selinux/ss/conditional.c
Source file repositories/reference/linux-study-clean/security/selinux/ss/conditional.c
File Facts
- System
- Linux kernel
- Corpus path
security/selinux/ss/conditional.c- Extension
.c- Size
- 17396 bytes
- Lines
- 766
- 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/kernel.hlinux/errno.hlinux/string.hlinux/spinlock.hlinux/slab.hsecurity.hconditional.hpolicydb.hservices.h
Detected Declarations
struct cond_insertf_datafunction Copyrightfunction evaluate_cond_nodefunction evaluate_cond_nodesfunction cond_policydb_initfunction cond_node_destroyfunction cond_list_destroyfunction cond_policydb_destroyfunction cond_init_bool_indexesfunction cond_destroy_boolfunction cond_index_boolfunction cond_read_boolfunction cond_insertffunction listfunction cond_read_av_listfunction expr_node_isvalidfunction cond_read_nodefunction cond_read_listfunction cond_write_boolfunction cond_write_av_listfunction cond_write_nodefunction cond_write_listfunction cond_compute_xpermsfunction cond_compute_avfunction cond_dup_av_listfunction duplicate_policydb_cond_listfunction cond_bools_destroyfunction cond_bools_copyfunction cond_bools_indexfunction duplicate_policydb_boolsfunction cond_policydb_destroy_dupfunction cond_policydb_dup
Annotated Snippet
struct cond_insertf_data {
struct policydb *p;
struct avtab_node **dst;
struct cond_av_list *other;
};
static int cond_insertf(struct avtab *a, const struct avtab_key *k,
const struct avtab_datum *d, void *ptr)
{
struct cond_insertf_data *data = ptr;
struct policydb *p = data->p;
struct cond_av_list *other = data->other;
struct avtab_node *node_ptr;
u32 i;
bool found;
/*
* For type rules we have to make certain there aren't any
* conflicting rules by searching the te_avtab and the
* cond_te_avtab.
*/
if (k->specified & AVTAB_TYPE) {
if (avtab_search_node(&p->te_avtab, k)) {
pr_err("SELinux: type rule already exists outside of a conditional.\n");
return -EINVAL;
}
/*
* If we are reading the false list other will be a pointer to
* the true list. We can have duplicate entries if there is only
* 1 other entry and it is in our true list.
*
* If we are reading the true list (other == NULL) there shouldn't
* be any other entries.
*/
if (other) {
node_ptr = avtab_search_node(&p->te_cond_avtab, k);
if (node_ptr) {
if (avtab_search_node_next(node_ptr,
k->specified)) {
pr_err("SELinux: too many conflicting type rules.\n");
return -EINVAL;
}
found = false;
for (i = 0; i < other->len; i++) {
if (other->nodes[i] == node_ptr) {
found = true;
break;
}
}
if (!found) {
pr_err("SELinux: conflicting type rules.\n");
return -EINVAL;
}
}
} else {
if (avtab_search_node(&p->te_cond_avtab, k)) {
pr_err("SELinux: conflicting type rules when adding type rule for true.\n");
return -EINVAL;
}
}
}
node_ptr = avtab_insert_nonunique(&p->te_cond_avtab, k, d);
if (!node_ptr) {
pr_err("SELinux: could not insert rule.\n");
return -ENOMEM;
}
*data->dst = node_ptr;
return 0;
}
static int cond_read_av_list(struct policydb *p, struct policy_file *fp,
struct cond_av_list *list,
struct cond_av_list *other)
{
int rc;
__le32 buf[1];
u32 i, len;
struct cond_insertf_data data;
rc = next_entry(buf, fp, sizeof(u32));
if (rc)
return rc;
len = le32_to_cpu(buf[0]);
if (len == 0)
return 0;
/* avtab_read_item() reads at least 96 bytes for any valid entry */
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/string.h`, `linux/spinlock.h`, `linux/slab.h`, `security.h`, `conditional.h`, `policydb.h`.
- Detected declarations: `struct cond_insertf_data`, `function Copyright`, `function evaluate_cond_node`, `function evaluate_cond_nodes`, `function cond_policydb_init`, `function cond_node_destroy`, `function cond_list_destroy`, `function cond_policydb_destroy`, `function cond_init_bool_indexes`, `function cond_destroy_bool`.
- 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.