FreeBSD kernel kern code
|
#include <sys/cdefs.h>
#include "opt_capsicum.h"
#include "opt_hwpmc_hooks.h"
#include "opt_ktrace.h"
#include "opt_vm.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/acct.h>
#include <sys/asan.h>
#include <sys/capsicum.h>
#include <sys/compressor.h>
#include <sys/eventhandler.h>
#include <sys/exec.h>
#include <sys/fcntl.h>
#include <sys/filedesc.h>
#include <sys/imgact.h>
#include <sys/imgact_elf.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/mutex.h>
#include <sys/namei.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/ptrace.h>
#include <sys/reg.h>
#include <sys/resourcevar.h>
#include <sys/rwlock.h>
#include <sys/sched.h>
#include <sys/sdt.h>
#include <sys/sf_buf.h>
#include <sys/shm.h>
#include <sys/signalvar.h>
#include <sys/smp.h>
#include <sys/stat.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/sysent.h>
#include <sys/sysproto.h>
#include <sys/timers.h>
#include <sys/umtxvar.h>
#include <sys/vnode.h>
#include <sys/wait.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <vm/vm_page.h>
#include <vm/vm_map.h>
#include <vm/vm_kern.h>
#include <vm/vm_extern.h>
#include <vm/vm_object.h>
#include <vm/vm_pager.h>
#include <security/audit/audit.h>
#include <security/mac/mac_framework.h>
Go to the source code of this file.
Data Structures | |
struct | execve_args |
struct | fexecve_args |
struct | __mac_execve_args |
struct | exec_args_kva |
Functions | |
__FBSDID ("$FreeBSD$") | |
SDT_PROVIDER_DECLARE (proc) | |
SDT_PROBE_DEFINE1 (proc,,, exec, "char *") | |
SDT_PROBE_DEFINE1 (proc,,, exec__failure, "int") | |
SDT_PROBE_DEFINE1 (proc,,, exec__success, "char *") | |
MALLOC_DEFINE (M_PARGS, "proc-args", "Process arguments") | |
SYSCTL_INT (_kern, OID_AUTO, coredump_pack_fileinfo, CTLFLAG_RWTUN, &coredump_pack_fileinfo, 0, "Enable file path packing in 'procstat -f' coredump notes") | |
SYSCTL_INT (_kern, OID_AUTO, coredump_pack_vmmapinfo, CTLFLAG_RWTUN, &coredump_pack_vmmapinfo, 0, "Enable file path packing in 'procstat -v' coredump notes") | |
static int | sysctl_kern_ps_strings (SYSCTL_HANDLER_ARGS) |
static int | sysctl_kern_usrstack (SYSCTL_HANDLER_ARGS) |
static int | sysctl_kern_stackprot (SYSCTL_HANDLER_ARGS) |
static int | do_execve (struct thread *td, struct image_args *args, struct mac *mac_p, struct vmspace *oldvmspace) |
SYSCTL_PROC (_kern, KERN_PS_STRINGS, ps_strings, CTLTYPE_ULONG|CTLFLAG_RD|CTLFLAG_CAPRD|CTLFLAG_MPSAFE, NULL, 0, sysctl_kern_ps_strings, "LU", "Location of process' ps_strings structure") | |
SYSCTL_PROC (_kern, KERN_USRSTACK, usrstack, CTLTYPE_ULONG|CTLFLAG_RD|CTLFLAG_CAPRD|CTLFLAG_MPSAFE, NULL, 0, sysctl_kern_usrstack, "LU", "Top of process stack") | |
SYSCTL_PROC (_kern, OID_AUTO, stackprot, CTLTYPE_INT|CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, 0, sysctl_kern_stackprot, "I", "Stack memory permissions") | |
SYSCTL_ULONG (_kern, OID_AUTO, ps_arg_cache_limit, CTLFLAG_RW, &ps_arg_cache_limit, 0, "Process' command line characters cache limit") | |
SYSCTL_INT (_kern, OID_AUTO, disallow_high_osrel, CTLFLAG_RW, &disallow_high_osrel, 0, "Disallow execution of binaries built for higher version of the world") | |
SYSCTL_INT (_security_bsd, OID_AUTO, map_at_zero, CTLFLAG_RWTUN, &map_at_zero, 0, "Permit processes to map an object at virtual address 0.") | |
SYSCTL_INT (_kern, OID_AUTO, core_dump_can_intr, CTLFLAG_RWTUN, &core_dump_can_intr, 0, "Core dumping interruptible with SIGKILL") | |
int | sys_execve (struct thread *td, struct execve_args *uap) |
int | sys_fexecve (struct thread *td, struct fexecve_args *uap) |
int | sys___mac_execve (struct thread *td, struct __mac_execve_args *uap) |
int | pre_execve (struct thread *td, struct vmspace **oldvmspace) |
void | post_execve (struct thread *td, int error, struct vmspace *oldvmspace) |
int | kern_execve (struct thread *td, struct image_args *args, struct mac *mac_p, struct vmspace *oldvmspace) |
static void | execve_nosetid (struct image_params *imgp) |
void | exec_cleanup (struct thread *td, struct vmspace *oldvmspace) |
int | exec_map_first_page (struct image_params *imgp) |
void | exec_unmap_first_page (struct image_params *imgp) |
void | exec_onexec_old (struct thread *td) |
void | exec_free_abi_mappings (struct proc *p) |
int | exec_new_vmspace (struct image_params *imgp, struct sysentvec *sv) |
int | exec_map_stack (struct image_params *imgp) |
int | exec_copyin_args (struct image_args *args, const char *fname, enum uio_seg segflg, char **argv, char **envv) |
DPCPU_DEFINE_STATIC (struct exec_args_kva *, exec_args_kva) | |
static | SLIST_HEAD (exec_args_kva) |
SYSINIT (exec_args_kva, SI_SUB_EXEC, SI_ORDER_ANY, exec_prealloc_args_kva, NULL) | |
static vm_offset_t | exec_alloc_args_kva (void **cookie) |
static void | exec_release_args_kva (struct exec_args_kva *argkva, u_int gen) |
static void | exec_free_args_kva (void *cookie) |
static void | exec_args_kva_lowmem (void *arg __unused) |
EVENTHANDLER_DEFINE (vm_lowmem, exec_args_kva_lowmem, NULL, EVENTHANDLER_PRI_ANY) | |
int | exec_alloc_args (struct image_args *args) |
void | exec_free_args (struct image_args *args) |
int | exec_args_add_fname (struct image_args *args, const char *fname, enum uio_seg segflg) |
static int | exec_args_add_str (struct image_args *args, const char *str, enum uio_seg segflg, int *countp) |
int | exec_args_add_arg (struct image_args *args, const char *argp, enum uio_seg segflg) |
int | exec_args_add_env (struct image_args *args, const char *envp, enum uio_seg segflg) |
int | exec_args_adjust_args (struct image_args *args, size_t consume, ssize_t extend) |
char * | exec_args_get_begin_envv (struct image_args *args) |
int | exec_copyout_strings (struct image_params *imgp, uintptr_t *stack_base) |
int | exec_check_permissions (struct image_params *imgp) |
int | exec_register (const struct execsw *execsw_arg) |
int | exec_unregister (const struct execsw *execsw_arg) |
static int | compress_chunk (struct coredump_params *cp, char *base, char *buf, size_t len) |
int | core_write (struct coredump_params *cp, const void *base, size_t len, off_t offset, enum uio_seg seg, size_t *resid) |
int | core_output (char *base, size_t len, off_t offset, struct coredump_params *cp, void *tmpbuf) |
int | sbuf_drain_core_output (void *arg, const char *data, int len) |
Variables | |
int | coredump_pack_fileinfo = 1 |
int | coredump_pack_vmmapinfo = 1 |
u_long | ps_arg_cache_limit = PAGE_SIZE / 16 |
static int | disallow_high_osrel |
static int | map_at_zero = 0 |
static int | core_dump_can_intr = 1 |
static const struct execsw ** | execsw |
__FBSDID | ( | "$FreeBSD$" | ) |
|
static |
Definition at line 1902 of file kern_exec.c.
References buf, and compressor_write().
Referenced by core_output().
int core_output | ( | char * | base, |
size_t | len, | ||
off_t | offset, | ||
struct coredump_params * | cp, | ||
void * | tmpbuf | ||
) |
Definition at line 1937 of file kern_exec.c.
References compress_chunk(), core_dump_can_intr, core_write(), curproc_sigkilled(), vn_finished_write(), vn_start_write(), and vn_truncate_locked().
Referenced by coredump().
int core_write | ( | struct coredump_params * | cp, |
const void * | base, | ||
size_t | len, | ||
off_t | offset, | ||
enum uio_seg | seg, | ||
size_t * | resid | ||
) |
Definition at line 1927 of file kern_exec.c.
References vn_rdwr_inchunks().
Referenced by core_compressed_write(), core_output(), and sbuf_drain_core_output().
|
static |
Definition at line 383 of file kern_exec.c.
References cap_fexecve_rights, change_egid(), change_euid(), change_svgid(), change_svuid(), crdup(), crfree(), disallow_high_osrel, exec_args_get_begin_envv(), exec_check_permissions(), exec_cleanup(), exec_free_args(), exec_map_first_page(), exec_unmap_first_page(), execsigs(), execsw, execve_nosetid(), exit1(), fdcheckstd(), fdcloseexec(), fdsetugidsafety(), fdunshare(), fgetvp_exec(), free(), malloc(), namei(), NDFREE(), pargs_alloc(), pargs_drop(), pdunshare(), proc_set_cred(), ps_arg_cache_limit, setsugid(), sigacts_alloc(), sigacts_copy(), sigacts_free(), sigacts_shared(), signotify(), stopprofclock(), uifind(), uifree(), uprintf(), vn_commname(), vn_fullpath(), vn_fullpath_hardlink(), vput(), and vrele().
Referenced by kern_execve().
DPCPU_DEFINE_STATIC | ( | struct exec_args_kva * | , |
exec_args_kva | |||
) |
EVENTHANDLER_DEFINE | ( | vm_lowmem | , |
exec_args_kva_lowmem | , | ||
NULL | , | ||
EVENTHANDLER_PRI_ANY | |||
) |
int exec_alloc_args | ( | struct image_args * | args | ) |
Definition at line 1458 of file kern_exec.c.
References exec_alloc_args_kva().
Referenced by exec_copyin_args(), and start_init().
|
static |
Definition at line 1371 of file kern_exec.c.
References exec_args_kva::addr, and kasan_mark().
Referenced by exec_alloc_args().
int exec_args_add_arg | ( | struct image_args * | args, |
const char * | argp, | ||
enum uio_seg | segflg | ||
) |
Definition at line 1548 of file kern_exec.c.
References exec_args_add_str().
Referenced by exec_copyin_args(), and start_init().
int exec_args_add_env | ( | struct image_args * | args, |
const char * | envp, | ||
enum uio_seg | segflg | ||
) |
Definition at line 1558 of file kern_exec.c.
References exec_args_add_str().
Referenced by exec_copyin_args().
int exec_args_add_fname | ( | struct image_args * | args, |
const char * | fname, | ||
enum uio_seg | segflg | ||
) |
Definition at line 1494 of file kern_exec.c.
Referenced by exec_copyin_args(), and start_init().
|
static |
Definition at line 1526 of file kern_exec.c.
Referenced by exec_args_add_arg(), and exec_args_add_env().
int exec_args_adjust_args | ( | struct image_args * | args, |
size_t | consume, | ||
ssize_t | extend | ||
) |
Definition at line 1569 of file kern_exec.c.
Referenced by exec_shell_imgact(), and imgact_binmisc_exec().
char * exec_args_get_begin_envv | ( | struct image_args * | args | ) |
Definition at line 1589 of file kern_exec.c.
Referenced by do_execve(), and kern_execve().
|
static |
Definition at line 1421 of file kern_exec.c.
References exec_release_args_kva(), exec_args_kva::gen, and SLIST_HEAD().
int exec_check_permissions | ( | struct image_params * | imgp | ) |
Definition at line 1772 of file kern_exec.c.
Referenced by do_execve(), and load_file().
void exec_cleanup | ( | struct thread * | td, |
struct vmspace * | oldvmspace | ||
) |
Definition at line 1028 of file kern_exec.c.
Referenced by do_execve(), post_execve(), and start_init().
int exec_copyin_args | ( | struct image_args * | args, |
const char * | fname, | ||
enum uio_seg | segflg, | ||
char ** | argv, | ||
char ** | envv | ||
) |
Definition at line 1273 of file kern_exec.c.
References exec_alloc_args(), exec_args_add_arg(), exec_args_add_env(), exec_args_add_fname(), and exec_free_args().
Referenced by sys___mac_execve(), sys_execve(), and sys_fexecve().
int exec_copyout_strings | ( | struct image_params * | imgp, |
uintptr_t * | stack_base | ||
) |
Definition at line 1605 of file kern_exec.c.
void exec_free_abi_mappings | ( | struct proc * | p | ) |
Definition at line 1097 of file kern_exec.c.
Referenced by exec_new_vmspace(), and exit1().
void exec_free_args | ( | struct image_args * | args | ) |
Definition at line 1466 of file kern_exec.c.
References exec_free_args_kva(), and free().
Referenced by do_execve(), exec_copyin_args(), and kern_execve().
|
static |
Definition at line 1414 of file kern_exec.c.
References exec_release_args_kva().
Referenced by exec_free_args().
int exec_map_first_page | ( | struct image_params * | imgp | ) |
Definition at line 1039 of file kern_exec.c.
References exec_unmap_first_page(), and sf_buf_alloc().
Referenced by do_execve(), and load_file().
int exec_map_stack | ( | struct image_params * | imgp | ) |
Definition at line 1195 of file kern_exec.c.
References kern_setrlimit(), lim_max(), lim_rlimit_proc(), maxssiz, sgrowsiz, and uprintf().
Referenced by exec_aout_imgact().
int exec_new_vmspace | ( | struct image_params * | imgp, |
struct sysentvec * | sv | ||
) |
Definition at line 1119 of file kern_exec.c.
References exec_free_abi_mappings(), itimers_exec(), map_at_zero, and shmexit().
Referenced by exec_aout_imgact().
void exec_onexec_old | ( | struct thread * | td | ) |
Definition at line 1084 of file kern_exec.c.
References sigfastblock_clear(), and umtx_exec().
int exec_register | ( | const struct execsw * | execsw_arg | ) |
|
static |
Definition at line 1392 of file kern_exec.c.
References exec_args_kva::addr, exec_args_kva::gen, kasan_mark(), and wakeup_one().
Referenced by exec_args_kva_lowmem(), and exec_free_args_kva().
void exec_unmap_first_page | ( | struct image_params * | imgp | ) |
Definition at line 1071 of file kern_exec.c.
References sf_buf_free().
Referenced by do_execve(), exec_map_first_page(), and load_file().
int exec_unregister | ( | const struct execsw * | execsw_arg | ) |
|
static |
Definition at line 369 of file kern_exec.c.
References crfree().
Referenced by do_execve().
int kern_execve | ( | struct thread * | td, |
struct image_args * | args, | ||
struct mac * | mac_p, | ||
struct vmspace * | oldvmspace | ||
) |
Definition at line 350 of file kern_exec.c.
References do_execve(), exec_args_get_begin_envv(), and exec_free_args().
Referenced by start_init(), sys___mac_execve(), sys_execve(), and sys_fexecve().
MALLOC_DEFINE | ( | M_PARGS | , |
"proc-args" | , | ||
"Process arguments" | |||
) |
void post_execve | ( | struct thread * | td, |
int | error, | ||
struct vmspace * | oldvmspace | ||
) |
Definition at line 321 of file kern_exec.c.
References exec_cleanup(), thread_single(), and thread_single_end().
Referenced by sys___mac_execve(), sys_execve(), and sys_fexecve().
int pre_execve | ( | struct thread * | td, |
struct vmspace ** | oldvmspace | ||
) |
Definition at line 300 of file kern_exec.c.
References thread_single().
Referenced by sys___mac_execve(), sys_execve(), and sys_fexecve().
int sbuf_drain_core_output | ( | void * | arg, |
const char * | data, | ||
int | len | ||
) |
Definition at line 2014 of file kern_exec.c.
References compressor_write(), core_write(), and data.
Referenced by corehdr().
SDT_PROBE_DEFINE1 | ( | proc | , |
exec | , | ||
"char *" | |||
) |
SDT_PROBE_DEFINE1 | ( | proc | , |
exec__failure | , | ||
"int" | |||
) |
SDT_PROBE_DEFINE1 | ( | proc | , |
exec__success | , | ||
"char *" | |||
) |
SDT_PROVIDER_DECLARE | ( | proc | ) |
|
static |
Definition at line 1349 of file kern_exec.c.
Referenced by exec_args_kva_lowmem().
int sys___mac_execve | ( | struct thread * | td, |
struct __mac_execve_args * | uap | ||
) |
Definition at line 277 of file kern_exec.c.
References __mac_execve_args::argv, __mac_execve_args::envv, exec_copyin_args(), __mac_execve_args::fname, kern_execve(), __mac_execve_args::mac_p, post_execve(), and pre_execve().
int sys_execve | ( | struct thread * | td, |
struct execve_args * | uap | ||
) |
Definition at line 221 of file kern_exec.c.
References execve_args::argv, execve_args::envv, exec_copyin_args(), execve_args::fname, kern_execve(), post_execve(), and pre_execve().
int sys_fexecve | ( | struct thread * | td, |
struct fexecve_args * | uap | ||
) |
Definition at line 247 of file kern_exec.c.
References fexecve_args::argv, fexecve_args::envv, exec_copyin_args(), fexecve_args::fd, kern_execve(), post_execve(), and pre_execve().
SYSCTL_INT | ( | _kern | , |
OID_AUTO | , | ||
core_dump_can_intr | , | ||
CTLFLAG_RWTUN | , | ||
& | core_dump_can_intr, | ||
0 | , | ||
"Core dumping interruptible with SIGKILL" | |||
) |
SYSCTL_INT | ( | _kern | , |
OID_AUTO | , | ||
coredump_pack_fileinfo | , | ||
CTLFLAG_RWTUN | , | ||
& | coredump_pack_fileinfo, | ||
0 | , | ||
"Enable file path packing in 'procstat -f' coredump notes" | |||
) |
SYSCTL_INT | ( | _kern | , |
OID_AUTO | , | ||
coredump_pack_vmmapinfo | , | ||
CTLFLAG_RWTUN | , | ||
& | coredump_pack_vmmapinfo, | ||
0 | , | ||
"Enable file path packing in 'procstat -v' coredump notes" | |||
) |
SYSCTL_INT | ( | _kern | , |
OID_AUTO | , | ||
disallow_high_osrel | , | ||
CTLFLAG_RW | , | ||
& | disallow_high_osrel, | ||
0 | , | ||
"Disallow execution of binaries built for higher version of the world" | |||
) |
SYSCTL_INT | ( | _security_bsd | , |
OID_AUTO | , | ||
map_at_zero | , | ||
CTLFLAG_RWTUN | , | ||
& | map_at_zero, | ||
0 | , | ||
"Permit processes to map an object at virtual address 0." | |||
) |
|
static |
Definition at line 160 of file kern_exec.c.
|
static |
Definition at line 197 of file kern_exec.c.
|
static |
Definition at line 178 of file kern_exec.c.
SYSCTL_PROC | ( | _kern | , |
KERN_PS_STRINGS | , | ||
ps_strings | , | ||
CTLTYPE_ULONG|CTLFLAG_RD|CTLFLAG_CAPRD| | CTLFLAG_MPSAFE, | ||
NULL | , | ||
0 | , | ||
sysctl_kern_ps_strings | , | ||
"LU" | , | ||
"Location of process' ps_strings structure" | |||
) |
SYSCTL_PROC | ( | _kern | , |
KERN_USRSTACK | , | ||
usrstack | , | ||
CTLTYPE_ULONG|CTLFLAG_RD|CTLFLAG_CAPRD| | CTLFLAG_MPSAFE, | ||
NULL | , | ||
0 | , | ||
sysctl_kern_usrstack | , | ||
"LU" | , | ||
"Top of process stack" | |||
) |
SYSCTL_PROC | ( | _kern | , |
OID_AUTO | , | ||
stackprot | , | ||
CTLTYPE_INT|CTLFLAG_RD| | CTLFLAG_MPSAFE, | ||
NULL | , | ||
0 | , | ||
sysctl_kern_stackprot | , | ||
"I" | , | ||
"Stack memory permissions" | |||
) |
SYSCTL_ULONG | ( | _kern | , |
OID_AUTO | , | ||
ps_arg_cache_limit | , | ||
CTLFLAG_RW | , | ||
& | ps_arg_cache_limit, | ||
0 | , | ||
"Process' command line characters cache limit" | |||
) |
SYSINIT | ( | exec_args_kva | , |
SI_SUB_EXEC | , | ||
SI_ORDER_ANY | , | ||
exec_prealloc_args_kva | , | ||
NULL | |||
) |
|
static |
Definition at line 154 of file kern_exec.c.
Referenced by core_output().
int coredump_pack_fileinfo = 1 |
Definition at line 110 of file kern_exec.c.
Referenced by note_procstat_files().
int coredump_pack_vmmapinfo = 1 |
Definition at line 115 of file kern_exec.c.
Referenced by note_procstat_vmmap().
|
static |
Definition at line 145 of file kern_exec.c.
Referenced by do_execve().
|
static |
Definition at line 210 of file kern_exec.c.
Referenced by do_execve(), exec_register(), and exec_unregister().
|
static |
Definition at line 150 of file kern_exec.c.
Referenced by exec_new_vmspace().
u_long ps_arg_cache_limit = PAGE_SIZE / 16 |
Definition at line 140 of file kern_exec.c.
Referenced by do_execve(), and sysctl_kern_proc_args().