security/selinux/ss/mls.c
Source file repositories/reference/linux-study-clean/security/selinux/ss/mls.c
File Facts
- System
- Linux kernel
- Corpus path
security/selinux/ss/mls.c- Extension
.c- Size
- 16481 bytes
- Lines
- 664
- 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/kernel.hlinux/slab.hlinux/string.hlinux/errno.hnet/netlabel.hsidtab.hmls.hpolicydb.hservices.h
Detected Declarations
function Copyrightfunction ebitmap_for_each_positive_bitfunction mls_sid_to_contextfunction ebitmap_for_each_positive_bitfunction mls_level_isvalidfunction ebitmap_for_each_positive_bitfunction mls_range_isvalidfunction mls_context_isvalidfunction mls_context_to_sidfunction mls_from_stringfunction mls_range_setfunction mls_setup_user_rangefunction mls_convert_contextfunction ebitmap_for_each_positive_bitfunction mls_compute_sidfunction mls_export_netlbl_lvlfunction mls_import_netlbl_lvlfunction mls_export_netlbl_catfunction mls_import_netlbl_cat
Annotated Snippet
if (i - prev > 1) {
/* one or more negative bits are skipped */
if (head != prev) {
nm = sym_name(p, SYM_CATS, prev);
len += strlen(nm) + 1;
}
nm = sym_name(p, SYM_CATS, i);
len += strlen(nm) + 1;
head = i;
}
prev = i;
}
if (prev != head) {
nm = sym_name(p, SYM_CATS, prev);
len += strlen(nm) + 1;
}
if (l == 0) {
if (mls_level_eq(&context->range.level[0],
&context->range.level[1]))
break;
else
len++;
}
}
return len;
}
/*
* Write the security context string representation of
* the MLS fields of `context' into the string `*scontext'.
* Update `*scontext' to point to the end of the MLS fields.
*/
void mls_sid_to_context(struct policydb *p, struct context *context,
char **scontext)
{
const char *nm;
char *scontextp;
int i, l, head, prev;
struct ebitmap *e;
struct ebitmap_node *node;
if (!p->mls_enabled)
return;
scontextp = *scontext;
*scontextp = ':';
scontextp++;
for (l = 0; l < 2; l++) {
strcpy(scontextp, sym_name(p, SYM_LEVELS,
context->range.level[l].sens - 1));
scontextp += strlen(scontextp);
/* categories */
head = -2;
prev = -2;
e = &context->range.level[l].cat;
ebitmap_for_each_positive_bit(e, node, i)
{
if (i - prev > 1) {
/* one or more negative bits are skipped */
if (prev != head) {
if (prev - head > 1)
*scontextp++ = '.';
else
*scontextp++ = ',';
nm = sym_name(p, SYM_CATS, prev);
strcpy(scontextp, nm);
scontextp += strlen(nm);
}
if (prev < 0)
*scontextp++ = ':';
else
*scontextp++ = ',';
nm = sym_name(p, SYM_CATS, i);
strcpy(scontextp, nm);
scontextp += strlen(nm);
head = i;
}
prev = i;
}
if (prev != head) {
if (prev - head > 1)
*scontextp++ = '.';
else
*scontextp++ = ',';
nm = sym_name(p, SYM_CATS, prev);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/slab.h`, `linux/string.h`, `linux/errno.h`, `net/netlabel.h`, `sidtab.h`, `mls.h`, `policydb.h`.
- Detected declarations: `function Copyright`, `function ebitmap_for_each_positive_bit`, `function mls_sid_to_context`, `function ebitmap_for_each_positive_bit`, `function mls_level_isvalid`, `function ebitmap_for_each_positive_bit`, `function mls_range_isvalid`, `function mls_context_isvalid`, `function mls_context_to_sid`, `function mls_from_string`.
- 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.