security/apparmor/apparmorfs.c
Source file repositories/reference/linux-study-clean/security/apparmor/apparmorfs.c
File Facts
- System
- Linux kernel
- Corpus path
security/apparmor/apparmorfs.c- Extension
.c- Size
- 69729 bytes
- Lines
- 2774
- 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/ctype.hlinux/security.hlinux/vmalloc.hlinux/init.hlinux/seq_file.hlinux/uaccess.hlinux/mount.hlinux/namei.hlinux/capability.hlinux/rcupdate.hlinux/fs.hlinux/fs_context.hlinux/poll.hlinux/zstd.huapi/linux/major.huapi/linux/magic.hinclude/apparmor.hinclude/apparmorfs.hinclude/audit.hinclude/cred.hinclude/crypto.hinclude/ipc.hinclude/label.hinclude/lib.hinclude/policy.hinclude/policy_ns.hinclude/resource.hinclude/policy_unpack.hinclude/task.h
Detected Declarations
struct rawdata_f_datastruct aa_revisionstruct multi_transactionfunction rawdata_f_data_freefunction mangle_namefunction aafs_show_pathfunction aa_put_common_reffunction aa_get_common_reffunction aafs_evictfunction aafs_free_inodefunction apparmorfs_fill_superfunction apparmorfs_get_treefunction apparmorfs_init_fs_contextfunction __aafs_setup_d_inodefunction aafs_removefunction aafs_removefunction policy_updatefunction profile_loadfunction profile_replacefunction profile_removefunction ns_revision_releasefunction ns_revision_readfunction ns_revision_openfunction ns_revision_pollfunction __aa_bump_ns_revisionfunction profile_query_cbfunction query_datafunction labelfunction label_for_each_in_scopefunction label_for_eachfunction multi_transaction_kreffunction get_multi_transactionfunction put_multi_transactionfunction multi_transaction_setfunction multi_transaction_readfunction multi_transaction_releasefunction openfunction aa_sfs_seq_showfunction aa_sfs_seq_openfunction seq_profile_openfunction seq_profile_releasefunction seq_profile_name_showfunction seq_profile_mode_showfunction seq_profile_attach_showfunction seq_profile_hash_showfunction seq_ns_stacked_showfunction seq_ns_nsstacked_showfunction seq_ns_level_show
Annotated Snippet
* @fops: struct file_operations that should be used
* @iops: struct of inode_operations that should be used
*/
static int __aafs_setup_d_inode(struct inode *dir, struct dentry *dentry,
umode_t mode, void *data, char *link,
const struct file_operations *fops,
const struct inode_operations *iops)
{
struct inode *inode = new_inode(dir->i_sb);
AA_BUG(!dir);
AA_BUG(!dentry);
if (!inode)
return -ENOMEM;
inode->i_ino = get_next_ino();
inode->i_mode = mode;
simple_inode_init_ts(inode);
inode->i_private = data;
if (S_ISDIR(mode)) {
inode->i_op = iops ? iops : &simple_dir_inode_operations;
inode->i_fop = &simple_dir_operations;
inc_nlink(inode);
inc_nlink(dir);
} else if (S_ISLNK(mode)) {
inode->i_op = iops ? iops : &simple_symlink_inode_operations;
inode->i_link = link;
} else {
inode->i_fop = fops;
}
d_instantiate(dentry, inode);
dget(dentry);
return 0;
}
/**
* aafs_create - create a dentry in the apparmorfs filesystem
*
* @name: name of dentry to create
* @mode: permissions the file should have
* @parent: parent directory for this dentry
* @data: data to store on inode.i_private, available in open()
* @link: if symlink, symlink target string
* @fops: struct file_operations that should be used for
* @iops: struct of inode_operations that should be used
*
* This is the basic "create a xxx" function for apparmorfs.
*
* Returns a pointer to a dentry if it succeeds, that must be free with
* aafs_remove(). Will return ERR_PTR on failure.
*/
static struct dentry *aafs_create(const char *name, umode_t mode,
struct dentry *parent,
struct aa_common_ref *data, void *link,
const struct file_operations *fops,
const struct inode_operations *iops)
{
struct dentry *dentry;
struct inode *dir;
int error;
AA_BUG(!name);
AA_BUG(!parent);
if (!(mode & S_IFMT))
mode = (mode & S_IALLUGO) | S_IFREG;
error = simple_pin_fs(&aafs_ops, &aafs_mnt, &aafs_count);
if (error)
return ERR_PTR(error);
dir = d_inode(parent);
dentry = simple_start_creating(parent, name);
if (IS_ERR(dentry)) {
error = PTR_ERR(dentry);
goto fail;
}
error = __aafs_setup_d_inode(dir, dentry, mode, data, link, fops, iops);
simple_done_creating(dentry);
if (error)
goto fail;
if (data)
aa_get_common_ref(data);
return dentry;
Annotation
- Immediate include surface: `linux/ctype.h`, `linux/security.h`, `linux/vmalloc.h`, `linux/init.h`, `linux/seq_file.h`, `linux/uaccess.h`, `linux/mount.h`, `linux/namei.h`.
- Detected declarations: `struct rawdata_f_data`, `struct aa_revision`, `struct multi_transaction`, `function rawdata_f_data_free`, `function mangle_name`, `function aafs_show_path`, `function aa_put_common_ref`, `function aa_get_common_ref`, `function aafs_evict`, `function aafs_free_inode`.
- 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.