kernel/umh.c
Source file repositories/reference/linux-study-clean/kernel/umh.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/umh.c- Extension
.c- Size
- 15602 bytes
- Lines
- 571
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/module.hlinux/sched.hlinux/sched/task.hlinux/binfmts.hlinux/syscalls.hlinux/unistd.hlinux/kmod.hlinux/slab.hlinux/completion.hlinux/cred.hlinux/file.hlinux/fs_struct.hlinux/workqueue.hlinux/security.hlinux/mount.hlinux/kernel.hlinux/init.hlinux/resource.hlinux/notifier.hlinux/suspend.hlinux/rwsem.hlinux/ptrace.hlinux/async.hlinux/uaccess.hlinux/initrd.hlinux/freezer.htrace/events/module.h
Detected Declarations
function call_usermodehelper_freeinfofunction umh_completefunction call_usermodehelper_exec_asyncfunction call_usermodehelper_exec_syncfunction CPUsfunction usermodehelper_disablefunction usermodehelper_read_lock_waitfunction usermodehelper_read_unlockfunction usermodehelper_disabledfunction __usermodehelper_disablefunction helper_lockfunction helper_unlockfunction intfunction call_usermodehelper_execfunction call_usermodehelperfunction proc_cap_handlerfunction new_capfunction init_umh_sysctlsexport usermodehelper_read_trylockexport usermodehelper_read_lock_waitexport usermodehelper_read_unlockexport call_usermodehelper_setupexport call_usermodehelper_execexport call_usermodehelper
Annotated Snippet
if (retval) {
abort_creds(new);
goto out;
}
}
commit_creds(new);
wait_for_initramfs();
retval = kernel_execve(sub_info->path,
(const char *const *)sub_info->argv,
(const char *const *)sub_info->envp);
out:
sub_info->retval = retval;
/*
* call_usermodehelper_exec_sync() will call umh_complete
* if UHM_WAIT_PROC.
*/
if (!(sub_info->wait & UMH_WAIT_PROC))
umh_complete(sub_info);
if (!retval)
return 0;
do_exit(0);
}
/* Handles UMH_WAIT_PROC. */
static void call_usermodehelper_exec_sync(struct subprocess_info *sub_info)
{
pid_t pid;
/* If SIGCLD is ignored do_wait won't populate the status. */
kernel_sigaction(SIGCHLD, SIG_DFL);
pid = user_mode_thread(call_usermodehelper_exec_async, sub_info, SIGCHLD);
if (pid < 0)
sub_info->retval = pid;
else
kernel_wait(pid, &sub_info->retval);
/* Restore default kernel sig handler */
kernel_sigaction(SIGCHLD, SIG_IGN);
umh_complete(sub_info);
}
/*
* We need to create the usermodehelper kernel thread from a task that is affine
* to an optimized set of CPUs (or nohz housekeeping ones) such that they
* inherit a widest affinity irrespective of call_usermodehelper() callers with
* possibly reduced affinity (eg: per-cpu workqueues). We don't want
* usermodehelper targets to contend a busy CPU.
*
* Unbound workqueues provide such wide affinity and allow to block on
* UMH_WAIT_PROC requests without blocking pending request (up to some limit).
*
* Besides, workqueues provide the privilege level that caller might not have
* to perform the usermodehelper request.
*
*/
static void call_usermodehelper_exec_work(struct work_struct *work)
{
struct subprocess_info *sub_info =
container_of(work, struct subprocess_info, work);
if (sub_info->wait & UMH_WAIT_PROC) {
call_usermodehelper_exec_sync(sub_info);
} else {
pid_t pid;
/*
* Use CLONE_PARENT to reparent it to kthreadd; we do not
* want to pollute current->children, and we need a parent
* that always ignores SIGCHLD to ensure auto-reaping.
*/
pid = user_mode_thread(call_usermodehelper_exec_async, sub_info,
CLONE_PARENT | SIGCHLD);
if (pid < 0) {
sub_info->retval = pid;
umh_complete(sub_info);
}
}
}
/*
* If set, call_usermodehelper_exec() will exit immediately returning -EBUSY
* (used for preventing user land processes from being created after the user
* land has been frozen during a system-wide hibernation or suspend operation).
* Should always be manipulated under umhelper_sem acquired for write.
*/
static enum umh_disable_depth usermodehelper_disabled = UMH_DISABLED;
/* Number of helpers running */
static atomic_t running_helpers = ATOMIC_INIT(0);
Annotation
- Immediate include surface: `linux/module.h`, `linux/sched.h`, `linux/sched/task.h`, `linux/binfmts.h`, `linux/syscalls.h`, `linux/unistd.h`, `linux/kmod.h`, `linux/slab.h`.
- Detected declarations: `function call_usermodehelper_freeinfo`, `function umh_complete`, `function call_usermodehelper_exec_async`, `function call_usermodehelper_exec_sync`, `function CPUs`, `function usermodehelper_disable`, `function usermodehelper_read_lock_wait`, `function usermodehelper_read_unlock`, `function usermodehelper_disabled`, `function __usermodehelper_disable`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration implementation candidate.
- 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.