security/smack/smackfs.c
Source file repositories/reference/linux-study-clean/security/smack/smackfs.c
File Facts
- System
- Linux kernel
- Corpus path
security/smack/smackfs.c- Extension
.c- Size
- 71713 bytes
- Lines
- 3045
- 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/vmalloc.hlinux/security.hlinux/mutex.hlinux/slab.hnet/net_namespace.hnet/cipso_ipv4.hlinux/seq_file.hlinux/ctype.hlinux/audit.hlinux/magic.hlinux/mount.hlinux/fs_context.hsmack.h
Detected Declarations
struct smack_parsed_ruleenum smk_inosfunction smack_catset_bitfunction smk_netlabel_audit_setfunction smk_set_accessfunction smk_perm_from_strfunction smk_fill_rulefunction smk_parse_rulefunction smk_parse_long_rulefunction smk_write_rules_listfunction smk_seq_stopfunction smk_rule_showfunction load_seq_showfunction smk_open_loadfunction smk_write_loadfunction smk_cipso_doifunction smk_unlbl_ambientfunction cipso_seq_showfunction smk_open_cipsofunction smk_set_cipsofunction smk_write_cipsofunction cipso2_seq_showfunction smk_open_cipso2function smk_write_cipso2function net4addr_seq_showfunction smk_open_net4addrfunction lengthfunction list_for_each_entry_rcufunction smk_write_net4addrfunction net6addr_seq_showfunction smk_open_net6addrfunction lengthfunction list_for_each_entry_rcufunction smk_write_net6addrfunction smk_read_doifunction smk_write_doifunction smk_read_directfunction smk_write_directfunction smk_read_mappedfunction smk_write_mappedfunction smk_read_ambientfunction smk_write_ambientfunction onlycap_seq_showfunction smk_open_onlycapfunction smk_list_swap_rcufunction smk_parse_label_listfunction smk_destroy_label_listfunction smk_write_onlycap
Annotated Snippet
static const struct file_operations smk_load_ops = {
.open = smk_open_load,
.read = seq_read,
.llseek = seq_lseek,
.write = smk_write_load,
.release = seq_release,
};
/**
* smk_cipso_doi - set netlabel maps
* @ndoi: new value for our CIPSO DOI
* @gfp_flags: kmalloc allocation context
*/
static int
smk_cipso_doi(u32 ndoi, gfp_t gfp_flags)
{
int rc = 0;
struct cipso_v4_doi *doip;
struct netlbl_audit nai;
mutex_lock(&smk_cipso_doi_lock);
if (smk_cipso_doi_value == ndoi)
goto clr_doi_lock;
smk_netlabel_audit_set(&nai);
doip = kmalloc_obj(struct cipso_v4_doi, gfp_flags);
if (!doip) {
rc = -ENOMEM;
goto clr_doi_lock;
}
doip->map.std = NULL;
doip->doi = ndoi;
doip->type = CIPSO_V4_MAP_PASS;
doip->tags[0] = CIPSO_V4_TAG_RBITMAP;
for (rc = 1; rc < CIPSO_V4_TAG_MAXCNT; rc++)
doip->tags[rc] = CIPSO_V4_TAG_INVALID;
rc = netlbl_cfg_cipsov4_add(doip, &nai);
if (rc) {
kfree(doip);
goto clr_doi_lock;
}
if (smk_cipso_doi_value != CIPSO_V4_DOI_UNKNOWN) {
rc = netlbl_cfg_map_del(NULL, PF_INET, NULL, NULL, &nai);
if (rc && rc != -ENOENT)
goto clr_ndoi_def;
netlbl_cfg_cipsov4_del(smk_cipso_doi_value, &nai);
}
rc = netlbl_cfg_cipsov4_map_add(ndoi, NULL, NULL, NULL, &nai);
if (rc) {
smk_cipso_doi_value = CIPSO_V4_DOI_UNKNOWN; // no default map
clr_ndoi_def: netlbl_cfg_cipsov4_del(ndoi, &nai);
} else
smk_cipso_doi_value = ndoi;
clr_doi_lock:
mutex_unlock(&smk_cipso_doi_lock);
return rc;
}
/**
* smk_unlbl_ambient - initialize the unlabeled domain
* @oldambient: previous domain string
*/
static void smk_unlbl_ambient(char *oldambient)
{
int rc;
struct netlbl_audit nai;
smk_netlabel_audit_set(&nai);
if (oldambient != NULL) {
rc = netlbl_cfg_map_del(oldambient, PF_INET, NULL, NULL, &nai);
if (rc != 0)
printk(KERN_WARNING "%s:%d remove rc = %d\n",
__func__, __LINE__, rc);
}
if (smack_net_ambient == NULL)
smack_net_ambient = &smack_known_floor;
rc = netlbl_cfg_unlbl_map_add(smack_net_ambient->smk_known, PF_INET,
NULL, NULL, &nai);
if (rc != 0)
printk(KERN_WARNING "%s:%d add rc = %d\n",
__func__, __LINE__, rc);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/vmalloc.h`, `linux/security.h`, `linux/mutex.h`, `linux/slab.h`, `net/net_namespace.h`, `net/cipso_ipv4.h`, `linux/seq_file.h`.
- Detected declarations: `struct smack_parsed_rule`, `enum smk_inos`, `function smack_catset_bit`, `function smk_netlabel_audit_set`, `function smk_set_access`, `function smk_perm_from_str`, `function smk_fill_rule`, `function smk_parse_rule`, `function smk_parse_long_rule`, `function smk_write_rules_list`.
- 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.