security/selinux/selinuxfs.c
Source file repositories/reference/linux-study-clean/security/selinux/selinuxfs.c
File Facts
- System
- Linux kernel
- Corpus path
security/selinux/selinuxfs.c- Extension
.c- Size
- 48259 bytes
- Lines
- 2017
- Domain
- Core OS
- Bucket
- Security And Isolation
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/kernel.hlinux/pagemap.hlinux/slab.hlinux/vmalloc.hlinux/fs.hlinux/fs_context.hlinux/hex.hlinux/mount.hlinux/mutex.hlinux/namei.hlinux/init.hlinux/string.hlinux/security.hlinux/major.hlinux/seq_file.hlinux/percpu.hlinux/audit.hlinux/uaccess.hlinux/kobject.hlinux/ctype.hinitcalls.hflask.havc.havc_ss.hsecurity.hobjsec.hconditional.hima.h
Detected Declarations
struct selinux_fs_infostruct policy_load_memoryenum sel_inosfunction selinux_fs_info_createfunction selinux_fs_info_freefunction sel_read_enforcefunction sel_write_enforcefunction sel_read_handle_unknownfunction sel_open_handle_statusfunction sel_read_handle_statusfunction sel_mmap_handle_statusfunction sel_write_disablefunction sel_read_policyversfunction sel_read_mlsfunction sel_open_policyfunction sel_release_policyfunction sel_read_policyfunction sel_mmap_policy_faultfunction sel_mmap_policyfunction sel_remove_old_bool_datafunction sel_make_policy_nodesfunction sel_write_loadfunction sel_write_contextfunction sel_read_checkreqprotfunction sel_write_checkreqprotfunction sel_write_validatetransfunction selinux_transaction_writefunction sel_write_accessfunction sel_write_createfunction sel_write_relabelfunction sel_write_userfunction sel_write_memberfunction sel_attach_filefunction sel_read_boolfunction sel_write_boolfunction sel_commit_bools_writefunction sel_make_boolsfunction sel_read_avc_cache_thresholdfunction sel_write_avc_cache_thresholdfunction sel_read_avc_hash_statsfunction sel_read_sidtab_hash_statsfunction sel_avc_stats_seq_showfunction sel_avc_stats_seq_stopfunction sel_open_avc_cache_statsfunction sel_make_avc_filesfunction sel_make_ss_filesfunction sel_read_initconfunction sel_make_initcon_files
Annotated Snippet
static const struct file_operations sel_enforce_ops = {
.read = sel_read_enforce,
.write = sel_write_enforce,
.llseek = generic_file_llseek,
};
static ssize_t sel_read_handle_unknown(struct file *filp, char __user *buf,
size_t count, loff_t *ppos)
{
char tmpbuf[TMPBUFLEN];
ssize_t length;
ino_t ino = file_inode(filp)->i_ino;
int handle_unknown = (ino == SEL_REJECT_UNKNOWN) ?
security_get_reject_unknown() :
!security_get_allow_unknown();
length = scnprintf(tmpbuf, TMPBUFLEN, "%d", handle_unknown);
return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
}
static const struct file_operations sel_handle_unknown_ops = {
.read = sel_read_handle_unknown,
.llseek = generic_file_llseek,
};
static int sel_open_handle_status(struct inode *inode, struct file *filp)
{
struct page *status = selinux_kernel_status_page();
if (!status)
return -ENOMEM;
filp->private_data = status;
return 0;
}
static ssize_t sel_read_handle_status(struct file *filp, char __user *buf,
size_t count, loff_t *ppos)
{
struct page *status = filp->private_data;
BUG_ON(!status);
return simple_read_from_buffer(buf, count, ppos,
page_address(status),
sizeof(struct selinux_kernel_status));
}
static int sel_mmap_handle_status(struct file *filp,
struct vm_area_struct *vma)
{
struct page *status = filp->private_data;
unsigned long size = vma->vm_end - vma->vm_start;
BUG_ON(!status);
/* only allows one page from the head */
if (vma->vm_pgoff > 0 || size != PAGE_SIZE)
return -EIO;
/* disallow writable mapping */
if (vma->vm_flags & VM_WRITE)
return -EPERM;
/* disallow mprotect() turns it into writable */
vm_flags_clear(vma, VM_MAYWRITE);
return remap_pfn_range(vma, vma->vm_start,
page_to_pfn(status),
size, vma->vm_page_prot);
}
static const struct file_operations sel_handle_status_ops = {
.open = sel_open_handle_status,
.read = sel_read_handle_status,
.mmap = sel_mmap_handle_status,
.llseek = generic_file_llseek,
};
static ssize_t sel_write_disable(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
/*
* Setting disable is no longer supported, see
* https://github.com/SELinuxProject/selinux-kernel/wiki/DEPRECATE-runtime-disable
*/
pr_err_once("SELinux: %s (%d) wrote to disable. This is no longer supported.\n",
current->comm, current->pid);
return count;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/pagemap.h`, `linux/slab.h`, `linux/vmalloc.h`, `linux/fs.h`, `linux/fs_context.h`, `linux/hex.h`, `linux/mount.h`.
- Detected declarations: `struct selinux_fs_info`, `struct policy_load_memory`, `enum sel_inos`, `function selinux_fs_info_create`, `function selinux_fs_info_free`, `function sel_read_enforce`, `function sel_write_enforce`, `function sel_read_handle_unknown`, `function sel_open_handle_status`, `function sel_read_handle_status`.
- Atlas domain: Core OS / Security And Isolation.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.