27 #include <sys/cdefs.h>
30 #include "opt_capsicum.h"
31 #include "opt_hwpmc_hooks.h"
32 #include "opt_kdtrace.h"
33 #include "opt_ktrace.h"
36 #include <sys/param.h>
37 #include <sys/capability.h>
38 #include <sys/systm.h>
39 #include <sys/capability.h>
40 #include <sys/eventhandler.h>
42 #include <sys/mutex.h>
43 #include <sys/sysproto.h>
44 #include <sys/signalvar.h>
45 #include <sys/kernel.h>
46 #include <sys/mount.h>
47 #include <sys/filedesc.h>
48 #include <sys/fcntl.h>
51 #include <sys/imgact.h>
52 #include <sys/imgact_elf.h>
54 #include <sys/malloc.h>
57 #include <sys/pioctl.h>
58 #include <sys/namei.h>
59 #include <sys/resourcevar.h>
60 #include <sys/sched.h>
62 #include <sys/sf_buf.h>
63 #include <sys/syscallsubr.h>
64 #include <sys/sysent.h>
66 #include <sys/sysctl.h>
67 #include <sys/vnode.h>
70 #include <sys/ktrace.h>
74 #include <vm/vm_param.h>
76 #include <vm/vm_page.h>
77 #include <vm/vm_map.h>
78 #include <vm/vm_kern.h>
79 #include <vm/vm_extern.h>
80 #include <vm/vm_object.h>
81 #include <vm/vm_pager.h>
84 #include <sys/pmckern.h>
87 #include <machine/reg.h>
89 #include <security/audit/audit.h>
90 #include <security/mac/mac_framework.h>
93 #include <sys/dtrace_bsd.h>
94 dtrace_execexit_func_t dtrace_fasttrap_exec;
107 static int do_execve(
struct thread *td,
struct image_args *args,
111 SYSCTL_PROC(_kern, KERN_PS_STRINGS, ps_strings, CTLTYPE_ULONG|CTLFLAG_RD,
115 SYSCTL_PROC(_kern, KERN_USRSTACK, usrstack, CTLTYPE_ULONG|CTLFLAG_RD|
118 SYSCTL_PROC(_kern, OID_AUTO, stackprot, CTLTYPE_INT|CTLFLAG_RD,
128 "Disallow execution of binaries built for higher version of the world");
133 "Permit processes to map an object at virtual address 0.");
143 if (req->flags & SCTL_MASK32) {
145 val = (
unsigned int)p->p_sysent->sv_psstrings;
146 error = SYSCTL_OUT(req, &val,
sizeof(val));
149 error = SYSCTL_OUT(req, &p->p_sysent->sv_psstrings,
150 sizeof(p->p_sysent->sv_psstrings));
162 if (req->flags & SCTL_MASK32) {
164 val = (
unsigned int)p->p_sysent->sv_usrstack;
165 error = SYSCTL_OUT(req, &val,
sizeof(val));
168 error = SYSCTL_OUT(req, &p->p_sysent->sv_usrstack,
169 sizeof(p->p_sysent->sv_usrstack));
179 return (SYSCTL_OUT(req, &p->p_sysent->sv_stackprot,
180 sizeof(p->p_sysent->sv_stackprot)));
189 #ifndef _SYS_SYSPROTO_H_
207 struct image_args args;
210 uap->argv, uap->envv);
216 #ifndef _SYS_SYSPROTO_H_
227 struct image_args args;
238 #ifndef _SYS_SYSPROTO_H_
259 struct image_args args;
281 struct image_args *args;
284 struct proc *p = td->td_proc;
285 struct vmspace *oldvmspace;
288 AUDIT_ARG_ARGV(args->begin_argv, args->argc,
289 args->begin_envv - args->begin_argv);
290 AUDIT_ARG_ENVV(args->begin_envv, args->envc,
291 args->endp - args->begin_envv);
292 if (p->p_flag & P_HADTHREADS) {
302 KASSERT((td->td_pflags & TDP_EXECVMSPC) == 0, (
"nested execve"));
303 oldvmspace = td->td_proc->p_vmspace;
306 if (p->p_flag & P_HADTHREADS) {
318 if ((td->td_pflags & TDP_EXECVMSPC) != 0) {
319 KASSERT(td->td_proc->p_vmspace != oldvmspace,
320 (
"oldvmspace still used"));
321 vmspace_free(oldvmspace);
322 td->td_pflags &= ~TDP_EXECVMSPC;
335 struct image_args *args;
338 struct proc *p = td->td_proc;
340 struct ucred *newcred = NULL, *oldcred;
341 struct uidinfo *euip;
342 register_t *stack_base;
344 struct image_params image_params, *imgp;
346 int (*img_first)(
struct image_params *);
347 struct pargs *oldargs = NULL, *newargs = NULL;
348 struct sigacts *oldsigacts, *newsigacts;
350 struct vnode *tracevp = NULL;
351 struct ucred *tracecred = NULL;
353 struct vnode *textvp = NULL, *binvp = NULL;
354 int credential_changing;
358 struct label *interpvplabel = NULL;
362 struct pmckern_procexec pe;
364 static const char fexecv_proc_title[] =
"(fexecv)";
367 imgp = &image_params;
377 KASSERT((p->p_flag & P_INEXEC) == 0,
378 (
"%s(): process already has P_INEXEC flag", __func__));
379 p->p_flag |= P_INEXEC;
386 imgp->execlabel = NULL;
388 imgp->entry_addr = 0;
389 imgp->reloc_base = 0;
390 imgp->vmspace_destroyed = 0;
391 imgp->interpreted = 0;
393 imgp->interpreter_name = NULL;
394 imgp->auxargs = NULL;
397 imgp->firstpage = NULL;
398 imgp->ps_strings = 0;
399 imgp->auxarg_size = 0;
401 imgp->execpath = imgp->freepath = NULL;
406 imgp->pagesizeslen = 0;
407 imgp->stack_prot = 0;
410 error = mac_execve_enter(imgp, mac_p);
415 imgp->image_header = NULL;
424 if (args->fname != NULL) {
425 NDINIT(&nd, LOOKUP, ISOPEN | LOCKLEAF | FOLLOW | SAVENAME
426 | MPSAFE | AUDITVNODE1, UIO_SYSSPACE, args->fname, td);
429 SDT_PROBE1(proc, kernel, , exec, args->fname);
432 if (args->fname != NULL) {
433 #ifdef CAPABILITY_MODE
440 if (IN_CAPABILITY_MODE(td)) {
449 vfslocked = NDHASGIANT(&nd);
453 AUDIT_ARG_FD(args->fd);
460 error =
fgetvp_exec(td, args->fd, CAP_FEXECVE, &binvp);
463 vfslocked = VFS_LOCK_GIANT(binvp->v_mount);
464 vn_lock(binvp, LK_EXCLUSIVE | LK_RETRY);
465 AUDIT_ARG_VNODE1(binvp);
474 goto exec_fail_dealloc;
476 imgp->object = imgp->vp->v_object;
477 if (imgp->object != NULL)
478 vm_object_reference(imgp->object);
487 textset = VOP_IS_TEXT(imgp->vp);
488 VOP_SET_TEXT(imgp->vp);
492 goto exec_fail_dealloc;
494 imgp->proc->p_osrel = 0;
501 if ((img_first = imgp->proc->p_sysent->sv_imgact_try) != NULL)
502 error = img_first(imgp);
509 for (i = 0; error == -1 &&
execsw[i]; ++i) {
510 if (
execsw[i]->ex_imgact == NULL ||
511 execsw[i]->ex_imgact == img_first) {
514 error = (*
execsw[i]->ex_imgact)(imgp);
520 VOP_UNSET_TEXT(imgp->vp);
523 goto exec_fail_dealloc;
530 if (imgp->interpreted) {
538 VOP_UNSET_TEXT(imgp->vp);
540 if (args->fname != NULL)
541 NDFREE(&nd, NDF_ONLY_PNBUF);
543 mac_execve_interpreter_enter(binvp, &interpvplabel);
546 VOP_CLOSE(binvp, FREAD, td->td_ucred, td);
550 vm_object_deallocate(imgp->object);
552 VFS_UNLOCK_GIANT(vfslocked);
555 NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW | SAVENAME | MPSAFE,
556 UIO_SYSSPACE, imgp->interpreter_name, td);
557 args->fname = imgp->interpreter_name;
565 VOP_UNLOCK(imgp->vp, 0);
570 if (imgp->auxargs != NULL &&
571 ((args->fname != NULL && args->fname[0] ==
'/') ||
572 vn_fullpath(td, imgp->vp, &imgp->execpath, &imgp->freepath) != 0))
573 imgp->execpath = args->fname;
576 P_OSREL_MAJOR(p->p_osrel) > P_OSREL_MAJOR(__BSDSUniX_version)) {
578 uprintf(
"Osrel %d for image %s too high\n", p->p_osrel,
579 imgp->execpath != NULL ? imgp->execpath :
"<unresolved>");
580 vn_lock(imgp->vp, LK_SHARED | LK_RETRY);
581 goto exec_fail_dealloc;
587 if (p->p_sysent->sv_copyout_strings)
588 stack_base = (*p->p_sysent->sv_copyout_strings)(imgp);
597 if (p->p_sysent->sv_fixup != NULL)
598 (*p->p_sysent->sv_fixup)(&stack_base, imgp);
600 suword(--stack_base, imgp->args->argc);
612 euip =
uifind(attr.va_uid);
613 i = imgp->args->begin_envv - imgp->args->begin_argv;
617 bcopy(imgp->args->begin_argv, newargs->ar_args, i);
622 vn_lock(imgp->vp, LK_SHARED | LK_RETRY);
636 oldsigacts = p->p_sigacts;
641 p->p_sigacts = newsigacts;
652 bzero(p->p_comm,
sizeof(p->p_comm));
654 bcopy(nd.ni_cnd.cn_nameptr, p->p_comm,
655 min(nd.ni_cnd.cn_namelen, MAXCOMLEN));
656 else if (
vn_commname(binvp, p->p_comm,
sizeof(p->p_comm)) != 0)
657 bcopy(fexecv_proc_title, p->p_comm,
sizeof(fexecv_proc_title));
658 bcopy(p->p_comm, td->td_name,
sizeof(td->td_name));
660 sched_clear_tdname(td);
668 if (p->p_pptr && (p->p_flag & P_PPWAIT)) {
669 p->p_flag &= ~(P_PPWAIT | P_PPTRACE);
670 cv_broadcast(&p->p_pwait);
689 credential_changing = 0;
690 credential_changing |= (attr.va_mode & S_ISUID) && oldcred->cr_uid !=
692 credential_changing |= (attr.va_mode & S_ISGID) && oldcred->cr_gid !=
695 will_transition = mac_vnode_execve_will_transition(oldcred, imgp->vp,
696 interpvplabel, imgp);
697 credential_changing |= will_transition;
700 if (credential_changing &&
701 #ifdef CAPABILITY_MODE
702 ((oldcred->cr_flags & CRED_FLAG_CAPMODE) == 0) &&
704 (imgp->vp->v_mount->mnt_flag & MNT_NOSUID) == 0 &&
705 (p->p_flag & P_TRACED) == 0) {
714 if (p->p_tracecred != NULL &&
716 ktrprocexec(p, &tracecred, &tracevp);
728 VOP_UNLOCK(imgp->vp, 0);
731 vn_lock(imgp->vp, LK_SHARED | LK_RETRY);
738 if (attr.va_mode & S_ISUID)
740 if (attr.va_mode & S_ISGID)
743 if (will_transition) {
744 mac_vnode_execve_transition(oldcred, newcred, imgp->vp,
745 interpvplabel, imgp);
757 p->p_ucred = newcred;
760 if (oldcred->cr_uid == oldcred->cr_ruid &&
761 oldcred->cr_gid == oldcred->cr_rgid)
762 p->p_flag &= ~P_SUGID;
775 if (oldcred->cr_svuid != oldcred->cr_uid ||
776 oldcred->cr_svgid != oldcred->cr_gid) {
779 p->p_ucred = newcred;
788 textvp = p->p_textvp;
796 if (dtrace_fasttrap_exec)
797 dtrace_fasttrap_exec(p);
804 KNOTE_LOCKED(&p->p_klist, NOTE_EXEC);
805 p->p_flag &= ~P_INEXEC;
808 p->p_acflag &= ~AFORK;
828 if (PMC_SYSTEM_SAMPLING_ACTIVE() || PMC_PROC_IS_USING_PMCS(p)) {
830 VOP_UNLOCK(imgp->vp, 0);
831 pe.pm_credentialschanged = credential_changing;
832 pe.pm_entryaddr = imgp->entry_addr;
834 PMC_CALL_HOOK_X(td, PMC_FN_PROCESS_EXEC, (
void *) &pe);
835 vn_lock(imgp->vp, LK_SHARED | LK_RETRY);
843 if (p->p_sysent->sv_setregs)
844 (*p->p_sysent->sv_setregs)(td, imgp,
845 (u_long)(uintptr_t)stack_base);
847 exec_setregs(td, imgp, (u_long)(uintptr_t)stack_base);
851 SDT_PROBE1(proc, kernel, , exec__success, args->fname);
862 VOP_UNLOCK(imgp->vp, 0);
867 if (textvp != NULL) {
870 tvfslocked = VFS_LOCK_GIANT(textvp->v_mount);
872 VFS_UNLOCK_GIANT(tvfslocked);
874 if (binvp && error != 0)
877 if (tracevp != NULL) {
880 tvfslocked = VFS_LOCK_GIANT(tracevp->v_mount);
882 VFS_UNLOCK_GIANT(tvfslocked);
884 if (tracecred != NULL)
887 vn_lock(imgp->vp, LK_SHARED | LK_RETRY);
890 if (oldsigacts != NULL)
898 if (imgp->firstpage != NULL)
901 if (imgp->vp != NULL) {
903 NDFREE(&nd, NDF_ONLY_PNBUF);
905 VOP_CLOSE(imgp->vp, FREAD, td->td_ucred, td);
909 if (imgp->object != NULL)
910 vm_object_deallocate(imgp->object);
912 free(imgp->freepath, M_TEMP);
916 td->td_dbgflags |= TDB_EXEC;
923 STOPEVENT(p, S_EXEC, 0);
930 p->p_flag &= ~P_INEXEC;
933 SDT_PROBE1(proc, kernel, , exec__failure, error);
937 mac_execve_exit(imgp);
938 mac_execve_interpreter_exit(interpvplabel);
940 VFS_UNLOCK_GIANT(vfslocked);
943 if (error && imgp->vmspace_destroyed) {
945 exit1(td, W_EXITCODE(0, SIGABRT));
959 struct image_params *imgp;
963 vm_page_t ma[VM_INITIAL_PAGEIN];
966 if (imgp->firstpage != NULL)
969 object = imgp->vp->v_object;
972 VM_OBJECT_LOCK(
object);
973 #if VM_NRESERVLEVEL > 0
974 if ((object->flags & OBJ_COLORED) == 0) {
975 object->flags |= OBJ_COLORED;
976 object->pg_color = 0;
979 ma[0] = vm_page_grab(
object, 0, VM_ALLOC_NORMAL | VM_ALLOC_RETRY);
980 if (ma[0]->valid != VM_PAGE_BITS_ALL) {
981 initial_pagein = VM_INITIAL_PAGEIN;
982 if (initial_pagein > object->size)
983 initial_pagein =
object->size;
984 for (i = 1; i < initial_pagein; i++) {
985 if ((ma[i] = vm_page_next(ma[i - 1])) != NULL) {
988 if ((ma[i]->oflags & VPO_BUSY) || ma[i]->
busy)
992 ma[i] = vm_page_alloc(
object, i,
993 VM_ALLOC_NORMAL | VM_ALLOC_IFNOTCACHED);
999 rv = vm_pager_get_pages(
object, ma, initial_pagein, 0);
1000 ma[0] = vm_page_lookup(
object, 0);
1001 if ((rv != VM_PAGER_OK) || (ma[0] == NULL)) {
1002 if (ma[0] != NULL) {
1003 vm_page_lock(ma[0]);
1004 vm_page_free(ma[0]);
1005 vm_page_unlock(ma[0]);
1007 VM_OBJECT_UNLOCK(
object);
1011 vm_page_lock(ma[0]);
1012 vm_page_hold(ma[0]);
1013 vm_page_unlock(ma[0]);
1014 vm_page_wakeup(ma[0]);
1015 VM_OBJECT_UNLOCK(
object);
1017 imgp->firstpage = sf_buf_alloc(ma[0], 0);
1018 imgp->image_header = (
char *)sf_buf_kva(imgp->firstpage);
1025 struct image_params *imgp;
1029 if (imgp->firstpage != NULL) {
1030 m = sf_buf_page(imgp->firstpage);
1031 sf_buf_free(imgp->firstpage);
1032 imgp->firstpage = NULL;
1046 struct image_params *imgp;
1047 struct sysentvec *sv;
1050 struct proc *p = imgp->proc;
1051 struct vmspace *vmspace = p->p_vmspace;
1053 vm_offset_t sv_minuser, stack_addr;
1057 imgp->vmspace_destroyed = 1;
1061 EVENTHANDLER_INVOKE(process_exec, p, imgp);
1068 map = &vmspace->vm_map;
1070 sv_minuser = sv->sv_minuser;
1072 sv_minuser = MAX(sv->sv_minuser, PAGE_SIZE);
1073 if (vmspace->vm_refcnt == 1 && vm_map_min(map) == sv_minuser &&
1074 vm_map_max(map) == sv->sv_maxuser) {
1076 pmap_remove_pages(vmspace_pmap(vmspace));
1077 vm_map_remove(map, vm_map_min(map), vm_map_max(map));
1079 error = vmspace_exec(p, sv_minuser, sv->sv_maxuser);
1082 vmspace = p->p_vmspace;
1083 map = &vmspace->vm_map;
1087 obj = sv->sv_shared_page_obj;
1089 vm_object_reference(obj);
1090 error = vm_map_fixed(map, obj, 0,
1091 sv->sv_shared_page_base, sv->sv_shared_page_len,
1092 VM_PROT_READ | VM_PROT_EXECUTE,
1093 VM_PROT_READ | VM_PROT_EXECUTE,
1094 MAP_INHERIT_SHARE | MAP_ACC_NO_CHARGE);
1096 vm_object_deallocate(obj);
1102 if (sv->sv_maxssiz != NULL)
1103 ssiz = *sv->sv_maxssiz;
1106 stack_addr = sv->sv_usrstack - ssiz;
1107 error = vm_map_stack(map, stack_addr, (vm_size_t)ssiz,
1108 obj != NULL && imgp->stack_prot != 0 ? imgp->stack_prot :
1110 VM_PROT_ALL, MAP_STACK_GROWS_DOWN);
1116 stack_addr = IA64_BACKINGSTORE;
1117 error = vm_map_stack(map, stack_addr, (vm_size_t)ssiz,
1118 sv->sv_stackprot, VM_PROT_ALL, MAP_STACK_GROWS_UP);
1127 vmspace->vm_ssize =
sgrowsiz >> PAGE_SHIFT;
1128 vmspace->vm_maxsaddr = (
char *)sv->sv_usrstack - ssiz;
1139 enum uio_seg segflg,
char **
argv,
char **
envv)
1145 bzero(args,
sizeof(*args));
1160 if (fname != NULL) {
1161 args->fname = args->buf;
1162 error = (segflg == UIO_SYSSPACE) ?
1163 copystr(fname, args->fname, PATH_MAX, &length) :
1164 copyinstr(fname, args->fname, PATH_MAX, &length);
1170 args->begin_argv = args->buf + length;
1171 args->endp = args->begin_argv;
1172 args->stringspace = ARG_MAX;
1177 while ((argp = (caddr_t) (intptr_t) fuword(argv++))) {
1178 if (argp == (caddr_t) -1) {
1182 if ((error = copyinstr(argp, args->endp,
1183 args->stringspace, &length))) {
1184 if (error == ENAMETOOLONG)
1188 args->stringspace -= length;
1189 args->endp += length;
1193 args->begin_envv = args->endp;
1199 while ((envp = (caddr_t)(intptr_t)fuword(envv++))) {
1200 if (envp == (caddr_t)-1) {
1204 if ((error = copyinstr(envp, args->endp,
1205 args->stringspace, &length))) {
1206 if (error == ENAMETOOLONG)
1210 args->stringspace -= length;
1211 args->endp += length;
1232 args->buf = (
char *)kmem_alloc_wait(exec_map, PATH_MAX + ARG_MAX);
1233 return (args->buf != NULL ? 0 : ENOMEM);
1240 if (args->buf != NULL) {
1241 kmem_free_wakeup(exec_map, (vm_offset_t)args->buf,
1242 PATH_MAX + ARG_MAX);
1245 if (args->fname_buf != NULL) {
1246 free(args->fname_buf, M_TEMP);
1247 args->fname_buf = NULL;
1258 struct image_params *imgp;
1264 register_t *stack_base;
1265 struct ps_strings *arginfo;
1267 size_t execpath_len;
1268 int szsigcode, szps;
1269 char canary[
sizeof(long) * 8];
1271 szps =
sizeof(
pagesizes[0]) * MAXPAGESIZES;
1276 if (imgp->execpath != NULL && imgp->auxargs != NULL)
1277 execpath_len = strlen(imgp->execpath) + 1;
1282 arginfo = (
struct ps_strings *)p->p_sysent->sv_psstrings;
1283 if (p->p_sysent->sv_sigcode_base == 0) {
1284 if (p->p_sysent->sv_szsigcode != NULL)
1285 szsigcode = *(p->p_sysent->sv_szsigcode);
1287 destp = (uintptr_t)arginfo;
1292 if (szsigcode != 0) {
1294 destp = rounddown2(destp,
sizeof(
void *));
1295 copyout(p->p_sysent->sv_sigcode, (
void *)destp, szsigcode);
1301 if (execpath_len != 0) {
1302 destp -= execpath_len;
1303 imgp->execpathp = destp;
1304 copyout(imgp->execpath, (
void *)destp, execpath_len);
1310 arc4rand(canary,
sizeof(canary), 0);
1311 destp -=
sizeof(canary);
1312 imgp->canary = destp;
1313 copyout(canary, (
void *)destp,
sizeof(canary));
1314 imgp->canarylen =
sizeof(canary);
1320 destp = rounddown2(destp,
sizeof(
void *));
1321 imgp->pagesizes = destp;
1322 copyout(
pagesizes, (
void *)destp, szps);
1323 imgp->pagesizeslen = szps;
1325 destp -= ARG_MAX - imgp->args->stringspace;
1326 destp = rounddown2(destp,
sizeof(
void *));
1332 if (imgp->auxargs) {
1337 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size :
1344 vectp = (
char **)(destp - (imgp->args->argc +
1345 imgp->args->envc + 2 + imgp->auxarg_size)
1352 vectp = (
char **)(destp - (imgp->args->argc + imgp->args->envc
1353 + 2) *
sizeof(
char *));
1359 stack_base = (register_t *)vectp;
1361 stringp = imgp->args->begin_argv;
1362 argc = imgp->args->argc;
1363 envc = imgp->args->envc;
1368 copyout(stringp, (
void *)destp, ARG_MAX - imgp->args->stringspace);
1373 suword(&arginfo->ps_argvstr, (
long)(intptr_t)vectp);
1374 suword32(&arginfo->ps_nargvstr, argc);
1379 for (; argc > 0; --argc) {
1380 suword(vectp++, (
long)(intptr_t)destp);
1381 while (*stringp++ != 0)
1389 suword(&arginfo->ps_envstr, (
long)(intptr_t)vectp);
1390 suword32(&arginfo->ps_nenvstr, envc);
1395 for (; envc > 0; --envc) {
1396 suword(vectp++, (
long)(intptr_t)destp);
1397 while (*stringp++ != 0)
1405 return (stack_base);
1415 struct image_params *imgp;
1417 struct vnode *vp = imgp->vp;
1418 struct vattr *attr = imgp->attr;
1420 int error, writecount;
1425 error = VOP_GETATTR(vp, attr, td->td_ucred);
1430 error = mac_vnode_check_exec(td->td_ucred, imgp->vp, imgp);
1443 if ((vp->v_mount->mnt_flag & MNT_NOEXEC) ||
1444 (attr->va_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) == 0 ||
1445 (attr->va_type != VREG))
1451 if (attr->va_size == 0)
1457 error = VOP_ACCESS(vp, VEXEC, td->td_ucred, td);
1465 error = VOP_GET_WRITECOUNT(vp, &writecount);
1468 if (writecount != 0)
1475 error = VOP_OPEN(vp, FREAD, td->td_ucred, td, NULL);
1486 const struct
execsw *execsw_arg;
1488 const struct execsw **es, **xs, **newexecsw;
1492 for (es =
execsw; *es; es++)
1494 newexecsw =
malloc(count *
sizeof(*es), M_TEMP, M_WAITOK);
1495 if (newexecsw == NULL)
1499 for (es =
execsw; *es; es++)
1511 const struct
execsw *execsw_arg;
1513 const struct execsw **es, **xs, **newexecsw;
1517 panic(
"unregister with no handlers left?\n");
1519 for (es =
execsw; *es; es++) {
1520 if (*es == execsw_arg)
1525 for (es =
execsw; *es; es++)
1526 if (*es != execsw_arg)
1528 newexecsw =
malloc(count *
sizeof(*es), M_TEMP, M_WAITOK);
1529 if (newexecsw == NULL)
1532 for (es =
execsw; *es; es++)
1533 if (*es != execsw_arg)
void exec_free_args(struct image_args *args)
void sigacts_copy(struct sigacts *dest, struct sigacts *src)
struct sigacts * sigacts_alloc(void)
int sys___mac_execve(struct thread *td, struct __mac_execve_args *uap)
int exec_check_permissions(struct image_params *imgp)
void change_svgid(struct ucred *newcred, gid_t svgid)
void thread_single_end(void)
SDT_PROBE_DEFINE1(proc, kernel,, exec,"char *")
MALLOC_DEFINE(M_PARGS,"proc-args","Process arguments")
void uifree(struct uidinfo *uip)
SYSCTL_PROC(_kern, KERN_PS_STRINGS, ps_strings, CTLTYPE_ULONG|CTLFLAG_RD, NULL, 0, sysctl_kern_ps_strings,"LU","")
void NDFREE(struct nameidata *ndp, const u_int flags)
int priv_check_cred(struct ucred *cred, int priv, int flags)
void change_svuid(struct ucred *newcred, uid_t svuid)
u_long ps_arg_cache_limit
void * malloc(unsigned long size, struct malloc_type *mtp, int flags)
void setugidsafety(struct thread *td)
struct uidinfo * uifind(uid_t uid)
void pargs_drop(struct pargs *pa)
void panic(const char *fmt,...)
void sigacts_free(struct sigacts *ps)
register_t * exec_copyout_strings(struct image_params *imgp)
void exec_unmap_first_page(struct image_params *imgp)
int vn_fullpath(struct thread *td, struct vnode *vn, char **retbuf, char **freebuf)
int vn_commname(struct vnode *vp, char *buf, u_int buflen)
void setsugid(struct proc *p)
struct __mac_execve_args sys_fexecve
struct ucred * crcopysafe(struct proc *p, struct ucred *cr)
int uprintf(const char *fmt,...)
int kern_execve(struct thread *td, struct image_args *args, struct mac *mac_p)
int fgetvp_exec(struct thread *td, int fd, cap_rights_t rights, struct vnode **vpp)
void fdunshare(struct proc *p, struct thread *td)
void fdcloseexec(struct thread *td)
void vput(struct vnode *vp)
SYSCTL_ULONG(_kern, OID_AUTO, ps_arg_cache_limit, CTLFLAG_RW,&ps_arg_cache_limit, 0,"")
int exec_alloc_args(struct image_args *args)
SDT_PROVIDER_DECLARE(proc)
int exec_unregister(struct execsw *execsw_arg) const
int exec_new_vmspace(struct image_params *imgp, struct sysentvec *sv)
void exit1(struct thread *td, int rv)
u_long pagesizes[MAXPAGESIZES]
static int sysctl_kern_ps_strings(SYSCTL_HANDLER_ARGS)
int namei(struct nameidata *ndp)
static int sysctl_kern_usrstack(SYSCTL_HANDLER_ARGS)
void crfree(struct ucred *cr)
static const struct execsw ** execsw
void stopprofclock(struct proc *p)
int sigacts_shared(struct sigacts *ps)
int thread_single(int mode)
static int sysctl_kern_stackprot(SYSCTL_HANDLER_ARGS)
void execsigs(struct proc *p)
int fdcheckstd(struct thread *td)
int sys_execve(struct thread *td, struct execve_args *uap)
int exec_register(struct execsw *execsw_arg) const
void free(void *addr, struct malloc_type *mtp)
struct pargs * pargs_alloc(int len)
void vrele(struct vnode *vp)
void change_euid(struct ucred *newcred, struct uidinfo *euip)
static int do_execve(struct thread *td, struct image_args *args, struct mac *mac_p)
void shmexit(struct vmspace *vm)
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")
int exec_copyin_args(struct image_args *args, char *fname, enum uio_seg segflg, char **argv, char **envv)
TUNABLE_INT("security.bsd.map_at_zero",&map_at_zero)
void change_egid(struct ucred *newcred, gid_t egid)
void vfs_mark_atime(struct vnode *vp, struct ucred *cred)
struct ucred * crget(void)
static int disallow_high_osrel
int exec_map_first_page(struct image_params *imgp)