fs/binfmt_misc.c
Source file repositories/reference/linux-study-clean/fs/binfmt_misc.c
File Facts
- System
- Linux kernel
- Corpus path
fs/binfmt_misc.c- Extension
.c- Size
- 25697 bytes
- Lines
- 1048
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- 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.
- 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/module.hlinux/hex.hlinux/init.hlinux/sched/mm.hlinux/magic.hlinux/binfmts.hlinux/slab.hlinux/ctype.hlinux/string_helpers.hlinux/file.hlinux/pagemap.hlinux/namei.hlinux/mount.hlinux/fs_context.hlinux/syscalls.hlinux/fs.hlinux/uaccess.hinternal.h
Detected Declarations
function load_misc_binaryfunction load_misc_binaryfunction load_misc_binaryfunction errorfunction parse_commandfunction entry_statusfunction bm_evict_inodefunction remove_binfmt_handlerfunction bm_entry_readfunction bm_entry_writefunction add_entryfunction bm_register_writefunction bm_status_readfunction bm_status_writefunction bm_put_superfunction bm_fill_superfunction bm_freefunction bm_get_treefunction bm_init_fs_contextfunction init_misc_binfmtfunction exit_misc_binfmtmodule init init_misc_binfmt
Annotated Snippet
static const struct file_operations bm_entry_operations = {
.read = bm_entry_read,
.write = bm_entry_write,
.llseek = default_llseek,
};
/* /register */
/* add to filesystem */
static int add_entry(Node *e, struct super_block *sb)
{
struct dentry *dentry = simple_start_creating(sb->s_root, e->name);
struct inode *inode;
struct binfmt_misc *misc;
if (IS_ERR(dentry))
return PTR_ERR(dentry);
inode = bm_get_inode(sb, S_IFREG | 0644);
if (unlikely(!inode)) {
simple_done_creating(dentry);
return -ENOMEM;
}
refcount_set(&e->users, 1);
e->dentry = dentry;
inode->i_private = e;
inode->i_fop = &bm_entry_operations;
d_make_persistent(dentry, inode);
misc = i_binfmt_misc(inode);
write_lock(&misc->entries_lock);
list_add(&e->list, &misc->entries);
write_unlock(&misc->entries_lock);
simple_done_creating(dentry);
return 0;
}
static ssize_t bm_register_write(struct file *file, const char __user *buffer,
size_t count, loff_t *ppos)
{
Node *e;
struct super_block *sb = file_inode(file)->i_sb;
int err = 0;
struct file *f = NULL;
e = create_entry(buffer, count);
if (IS_ERR(e))
return PTR_ERR(e);
if (e->flags & MISC_FMT_OPEN_FILE) {
/*
* Now that we support unprivileged binfmt_misc mounts make
* sure we use the credentials that the register @file was
* opened with to also open the interpreter. Before that this
* didn't matter much as only a privileged process could open
* the register file.
*/
scoped_with_creds(file->f_cred)
f = open_exec(e->interpreter);
if (IS_ERR(f)) {
pr_notice("register: failed to install interpreter file %s\n",
e->interpreter);
kfree(e);
return PTR_ERR(f);
}
e->interp_file = f;
}
err = add_entry(e, sb);
if (err) {
if (f) {
exe_file_allow_write_access(f);
filp_close(f, NULL);
}
kfree(e);
return err;
}
return count;
}
static const struct file_operations bm_register_operations = {
.write = bm_register_write,
.llseek = noop_llseek,
};
/* /status */
static ssize_t
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/hex.h`, `linux/init.h`, `linux/sched/mm.h`, `linux/magic.h`, `linux/binfmts.h`, `linux/slab.h`.
- Detected declarations: `function load_misc_binary`, `function load_misc_binary`, `function load_misc_binary`, `function error`, `function parse_command`, `function entry_status`, `function bm_evict_inode`, `function remove_binfmt_handler`, `function bm_entry_read`, `function bm_entry_write`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.