FreeBSD kernel kern code
kern_exec.c File Reference
#include <sys/cdefs.h>
#include "opt_capsicum.h"
#include "opt_hwpmc_hooks.h"
#include "opt_kdtrace.h"
#include "opt_ktrace.h"
#include "opt_vm.h"
#include <sys/param.h>
#include <sys/capability.h>
#include <sys/systm.h>
#include <sys/eventhandler.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/sysproto.h>
#include <sys/signalvar.h>
#include <sys/kernel.h>
#include <sys/mount.h>
#include <sys/filedesc.h>
#include <sys/fcntl.h>
#include <sys/acct.h>
#include <sys/exec.h>
#include <sys/imgact.h>
#include <sys/imgact_elf.h>
#include <sys/wait.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/pioctl.h>
#include <sys/namei.h>
#include <sys/resourcevar.h>
#include <sys/sched.h>
#include <sys/sdt.h>
#include <sys/sf_buf.h>
#include <sys/syscallsubr.h>
#include <sys/sysent.h>
#include <sys/shm.h>
#include <sys/sysctl.h>
#include <sys/vnode.h>
#include <sys/stat.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 <machine/reg.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
 

Functions

 __FBSDID ("$BSDSUniX$")
 
 SDT_PROVIDER_DECLARE (proc)
 
 SDT_PROBE_DEFINE1 (proc, kernel,, exec,"char *")
 
 SDT_PROBE_DEFINE1 (proc, kernel,, exec__failure,"int")
 
 SDT_PROBE_DEFINE1 (proc, kernel,, exec__success,"char *")
 
 MALLOC_DEFINE (M_PARGS,"proc-args","Process arguments")
 
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)
 
 SYSCTL_PROC (_kern, KERN_PS_STRINGS, ps_strings, CTLTYPE_ULONG|CTLFLAG_RD, NULL, 0, sysctl_kern_ps_strings,"LU","")
 
 SYSCTL_PROC (_kern, KERN_USRSTACK, usrstack, CTLTYPE_ULONG|CTLFLAG_RD|CTLFLAG_CAPRD, NULL, 0, sysctl_kern_usrstack,"LU","")
 
 SYSCTL_PROC (_kern, OID_AUTO, stackprot, CTLTYPE_INT|CTLFLAG_RD, NULL, 0, sysctl_kern_stackprot,"I","")
 
 SYSCTL_ULONG (_kern, OID_AUTO, ps_arg_cache_limit, CTLFLAG_RW,&ps_arg_cache_limit, 0,"")
 
 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")
 
 TUNABLE_INT ("security.bsd.map_at_zero",&map_at_zero)
 
 SYSCTL_INT (_security_bsd, OID_AUTO, map_at_zero, CTLFLAG_RW,&map_at_zero, 0,"Permit processes to map an object at virtual address 0.")
 
int sys_execve (struct thread *td, struct execve_args *uap)
 
struct fexecve_args sys_fexecve (struct thread *td, struct fexecve_args *uap)
 
int sys___mac_execve (struct thread *td, struct __mac_execve_args *uap)
 
int kern_execve (struct thread *td, struct image_args *args, struct mac *mac_p)
 
int exec_map_first_page (struct image_params *imgp)
 
void exec_unmap_first_page (struct image_params *imgp)
 
int exec_new_vmspace (struct image_params *imgp, struct sysentvec *sv)
 
int exec_copyin_args (struct image_args *args, char *fname, enum uio_seg segflg, char **argv, char **envv)
 
int exec_alloc_args (struct image_args *args)
 
void exec_free_args (struct image_args *args)
 
register_t * exec_copyout_strings (struct image_params *imgp)
 
int exec_check_permissions (struct image_params *imgp)
 
int exec_register (struct execsw *execsw_arg) const
 
int exec_unregister (struct execsw *execsw_arg) const
 

Variables

u_long ps_arg_cache_limit = PAGE_SIZE / 16
 
static int disallow_high_osrel
 
static int map_at_zero = 0
 
static const struct execsw ** execsw
 
int fd
 
char ** argv
 
char ** envv
 
struct __mac_execve_args sys_fexecve
 

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
int exec_alloc_args ( struct image_args *  args)

Definition at line 1229 of file kern_exec.c.

Referenced by exec_copyin_args().

Here is the caller graph for this function:

int exec_check_permissions ( struct image_params *  imgp)

Definition at line 1414 of file kern_exec.c.

Referenced by do_execve(), and load_file().

Here is the caller graph for this function:

int exec_copyin_args ( struct image_args *  args,
char *  fname,
enum uio_seg  segflg,
char **  argv,
char **  envv 
)

Definition at line 1138 of file kern_exec.c.

References exec_alloc_args(), and exec_free_args().

Referenced by sys___mac_execve(), and sys_fexecve().

Here is the call graph for this function:

Here is the caller graph for this function:

register_t* exec_copyout_strings ( struct image_params *  imgp)

Definition at line 1257 of file kern_exec.c.

References pagesizes, and suword.

Referenced by do_execve().

Here is the caller graph for this function:

void exec_free_args ( struct image_args *  args)

Definition at line 1237 of file kern_exec.c.

References free().

Referenced by do_execve(), exec_copyin_args(), and kern_execve().

Here is the call graph for this function:

Here is the caller graph for this function:

int exec_map_first_page ( struct image_params *  imgp)

Definition at line 958 of file kern_exec.c.

References busy, and exec_unmap_first_page().

Referenced by do_execve(), and load_file().

Here is the call graph for this function:

Here is the caller graph for this function:

int exec_new_vmspace ( struct image_params *  imgp,
struct sysentvec *  sv 
)

Definition at line 1045 of file kern_exec.c.

References map_at_zero, maxssiz, sgrowsiz, and shmexit().

Referenced by do_aout_hdr(), and exec_aout_imgact().

Here is the call graph for this function:

Here is the caller graph for this function:

int exec_register ( struct execsw execsw_arg) const

Definition at line 1485 of file kern_exec.c.

References count, execsw, free(), and malloc().

Here is the call graph for this function:

void exec_unmap_first_page ( struct image_params *  imgp)

Definition at line 1024 of file kern_exec.c.

Referenced by do_execve(), exec_map_first_page(), and load_file().

Here is the caller graph for this function:

int exec_unregister ( struct execsw execsw_arg) const

Definition at line 1510 of file kern_exec.c.

References count, execsw, free(), malloc(), and panic().

Here is the call graph for this function:

int kern_execve ( struct thread *  td,
struct image_args *  args,
struct mac *  mac_p 
)

Definition at line 279 of file kern_exec.c.

References do_execve(), exec_free_args(), thread_single(), and thread_single_end().

Referenced by sys___mac_execve(), and sys_fexecve().

Here is the call graph for this function:

Here is the caller graph for this function:

MALLOC_DEFINE ( M_PARGS  ,
"proc-args"  ,
"Process arguments"   
)
SDT_PROBE_DEFINE1 ( proc  ,
kernel  ,
exec  ,
"char *"   
)
SDT_PROBE_DEFINE1 ( proc  ,
kernel  ,
exec__failure  ,
"int"   
)
SDT_PROBE_DEFINE1 ( proc  ,
kernel  ,
exec__success  ,
"char *"   
)
SDT_PROVIDER_DECLARE ( proc  )
int sys___mac_execve ( struct thread *  td,
struct __mac_execve_args uap 
)

Definition at line 248 of file kern_exec.c.

References __mac_execve_args::argv, __mac_execve_args::envv, exec_copyin_args(), __mac_execve_args::fname, kern_execve(), and __mac_execve_args::mac_p.

Here is the call graph for this function:

int sys_execve ( struct thread *  td,
struct execve_args uap 
)

Definition at line 198 of file kern_exec.c.

Referenced by start_init().

Here is the caller graph for this function:

struct fexecve_args sys_fexecve ( struct thread *  td,
struct fexecve_args uap 
)

Definition at line 224 of file kern_exec.c.

References fexecve_args::argv, fexecve_args::envv, exec_copyin_args(), fexecve_args::fd, and kern_execve().

Here is the call graph for this function:

SYSCTL_INT ( _kern  ,
OID_AUTO  ,
disallow_high_osrel  ,
CTLFLAG_RW  ,
disallow_high_osrel,
,
"Disallow execution of binaries built for higher version of the world"   
)
SYSCTL_INT ( _security_bsd  ,
OID_AUTO  ,
map_at_zero  ,
CTLFLAG_RW  ,
map_at_zero,
,
"Permit processes to map an object at virtual address 0."   
)
static int sysctl_kern_ps_strings ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 136 of file kern_exec.c.

static int sysctl_kern_stackprot ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 174 of file kern_exec.c.

static int sysctl_kern_usrstack ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 155 of file kern_exec.c.

SYSCTL_PROC ( _kern  ,
KERN_PS_STRINGS  ,
ps_strings  ,
CTLTYPE_ULONG|  CTLFLAG_RD,
NULL  ,
,
sysctl_kern_ps_strings  ,
"LU"  ,
""   
)
SYSCTL_PROC ( _kern  ,
KERN_USRSTACK  ,
usrstack  ,
CTLTYPE_ULONG|CTLFLAG_RD|  CTLFLAG_CAPRD,
NULL  ,
,
sysctl_kern_usrstack  ,
"LU"  ,
""   
)
SYSCTL_PROC ( _kern  ,
OID_AUTO  ,
stackprot  ,
CTLTYPE_INT|  CTLFLAG_RD,
NULL  ,
,
sysctl_kern_stackprot  ,
"I"  ,
""   
)
SYSCTL_ULONG ( _kern  ,
OID_AUTO  ,
ps_arg_cache_limit  ,
CTLFLAG_RW  ,
ps_arg_cache_limit,
,
""   
)
TUNABLE_INT ( "security.bsd.map_at_zero"  ,
map_at_zero 
)

Variable Documentation

char** argv

Definition at line 200 of file kern_exec.c.

int disallow_high_osrel
static

Definition at line 125 of file kern_exec.c.

Referenced by do_execve().

char** envv

Definition at line 201 of file kern_exec.c.

const struct execsw** execsw
static

Definition at line 187 of file kern_exec.c.

Referenced by do_execve(), exec_register(), and exec_unregister().

int map_at_zero = 0
static

Definition at line 130 of file kern_exec.c.

Referenced by exec_new_vmspace().

u_long ps_arg_cache_limit = PAGE_SIZE / 16

Definition at line 121 of file kern_exec.c.

Referenced by do_execve(), and sysctl_kern_proc_args().

struct __mac_execve_args sys_fexecve