Lines Matching +full:es +full:- +full:enable

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
106 MALLOC_DEFINE(M_PARGS, "proc-args", "Process arguments");
111 "Enable file path packing in 'procstat -f' coredump notes");
116 "Enable file path packing in 'procstat -v' coredump notes");
165 if (req->flags & SCTL_MASK32) { in sysctl_kern_ps_strings()
183 if (req->flags & SCTL_MASK32) { in sysctl_kern_usrstack()
186 val32 = round_page((unsigned int)p->p_vmspace->vm_stacktop); in sysctl_kern_usrstack()
190 val = round_page(p->p_vmspace->vm_stacktop); in sysctl_kern_usrstack()
200 return (SYSCTL_OUT(req, &p->p_sysent->sv_stackprot, in sysctl_kern_stackprot()
201 sizeof(p->p_sysent->sv_stackprot))); in sysctl_kern_stackprot()
228 error = exec_copyin_args(&args, uap->fname, UIO_USERSPACE, in sys_execve()
229 uap->argv, uap->envv); in sys_execve()
255 uap->argv, uap->envv); in sys_fexecve()
257 args.fd = uap->fd; in sys_fexecve()
285 error = exec_copyin_args(&args, uap->fname, UIO_USERSPACE, in sys___mac_execve()
286 uap->argv, uap->envv); in sys___mac_execve()
288 error = kern_execve(td, &args, uap->mac_p, oldvmspace); in sys___mac_execve()
303 KASSERT(td == curthread, ("non-current thread %p", td)); in pre_execve()
305 p = td->td_proc; in pre_execve()
306 if ((p->p_flag & P_HADTHREADS) != 0) { in pre_execve()
312 KASSERT(error != 0 || (td->td_pflags & TDP_EXECVMSPC) == 0, in pre_execve()
314 *oldvmspace = p->p_vmspace; in pre_execve()
323 KASSERT(td == curthread, ("non-current thread %p", td)); in post_execve()
324 p = td->td_proc; in post_execve()
325 if ((p->p_flag & P_HADTHREADS) != 0) { in post_execve()
352 TSEXEC(td->td_proc->p_pid, args->begin_argv); in kern_execve()
353 AUDIT_ARG_ARGV(args->begin_argv, args->argc, in kern_execve()
354 exec_args_get_begin_envv(args) - args->begin_argv); in kern_execve()
355 AUDIT_ARG_ENVV(exec_args_get_begin_envv(args), args->envc, in kern_execve()
356 args->endp - exec_args_get_begin_envv(args)); in kern_execve()
359 ktrdata(KTR_ARGS, args->begin_argv, in kern_execve()
360 exec_args_get_begin_envv(args) - args->begin_argv); in kern_execve()
364 args->endp - exec_args_get_begin_envv(args)); in kern_execve()
368 if (args->argc == 0) { in kern_execve()
378 imgp->credential_setid = false; in execve_nosetid()
379 if (imgp->newcred != NULL) { in execve_nosetid()
380 crfree(imgp->newcred); in execve_nosetid()
381 imgp->newcred = NULL; in execve_nosetid()
386 * In-kernel implementation of execve(). All arguments are assumed to be
393 struct proc *p = td->td_proc; in do_execve()
433 * necessary to avoid race conditions - e.g. in ptrace() - in do_execve()
438 KASSERT((p->p_flag & P_INEXEC) == 0, in do_execve()
440 p->p_flag |= P_INEXEC; in do_execve()
447 imgp->proc = p; in do_execve()
448 imgp->attr = &attr; in do_execve()
449 imgp->args = args; in do_execve()
450 oldcred = p->p_ucred; in do_execve()
451 orig_osrel = p->p_osrel; in do_execve()
452 orig_fctl0 = p->p_fctl0; in do_execve()
453 orig_brandinfo = p->p_elf_brandinfo; in do_execve()
461 SDT_PROBE1(proc, , , exec, args->fname); in do_execve()
464 if (args->fname != NULL) { in do_execve()
467 ktrcapfail(CAPFAIL_NAMEI, args->fname); in do_execve()
486 args->fname); in do_execve()
499 imgp->vp = newtextvp; in do_execve()
504 if (args->fname[0] == '/') { in do_execve()
505 imgp->execpath = args->fname; in do_execve()
507 VOP_UNLOCK(imgp->vp); in do_execve()
510 newbinname, nd.ni_cnd.cn_namelen, &imgp->execpath, in do_execve()
511 &imgp->freepath, &freepath_size) != 0) in do_execve()
512 imgp->execpath = args->fname; in do_execve()
513 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in do_execve()
515 } else if (imgp->interpreter_vp) { in do_execve()
519 newtextvp = imgp->interpreter_vp; in do_execve()
520 imgp->interpreter_vp = NULL; in do_execve()
521 if (vn_fullpath(newtextvp, &imgp->execpath, in do_execve()
522 &imgp->freepath) != 0) in do_execve()
523 imgp->execpath = args->fname; in do_execve()
526 imgp->vp = newtextvp; in do_execve()
528 AUDIT_ARG_FD(args->fd); in do_execve()
538 error = fgetvp_exec(td, args->fd, &cap_fexecve_rights, in do_execve()
543 if (vn_fullpath(newtextvp, &imgp->execpath, in do_execve()
544 &imgp->freepath) != 0) in do_execve()
545 imgp->execpath = args->fname; in do_execve()
548 imgp->vp = newtextvp; in do_execve()
559 imgp->object = imgp->vp->v_object; in do_execve()
560 if (imgp->object != NULL) in do_execve()
561 vm_object_reference(imgp->object); in do_execve()
567 imgp->proc->p_osrel = 0; in do_execve()
568 imgp->proc->p_fctl0 = 0; in do_execve()
569 imgp->proc->p_elf_brandinfo = NULL; in do_execve()
593 oldcred->cr_uid != attr.va_uid; in do_execve()
595 oldcred->cr_gid != attr.va_gid; in do_execve()
597 will_transition = mac_vnode_execve_will_transition(oldcred, imgp->vp, in do_execve()
604 imgp->proc->p_pdeathsig = 0; in do_execve()
608 ((oldcred->cr_flags & CRED_FLAG_CAPMODE) == 0) && in do_execve()
610 (imgp->vp->v_mount->mnt_flag & MNT_NOSUID) == 0 && in do_execve()
611 (p->p_flag & P_TRACED) == 0) { in do_execve()
612 imgp->credential_setid = true; in do_execve()
613 VOP_UNLOCK(imgp->vp); in do_execve()
614 imgp->newcred = crdup(oldcred); in do_execve()
617 change_euid(imgp->newcred, euip); in do_execve()
619 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in do_execve()
621 change_egid(imgp->newcred, attr.va_gid); in do_execve()
623 * Implement correct POSIX saved-id behavior. in do_execve()
629 change_svuid(imgp->newcred, imgp->newcred->cr_uid); in do_execve()
630 change_svgid(imgp->newcred, imgp->newcred->cr_gid); in do_execve()
633 * Implement correct POSIX saved-id behavior. in do_execve()
636 * POSIX-compliant. A number of sources indicate that the in do_execve()
644 if (oldcred->cr_svuid != oldcred->cr_uid || in do_execve()
645 oldcred->cr_svgid != oldcred->cr_gid) { in do_execve()
646 VOP_UNLOCK(imgp->vp); in do_execve()
647 imgp->newcred = crdup(oldcred); in do_execve()
648 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in do_execve()
649 change_svuid(imgp->newcred, imgp->newcred->cr_uid); in do_execve()
650 change_svgid(imgp->newcred, imgp->newcred->cr_gid); in do_execve()
657 * An activator returns -1 if there is no match, 0 on success, in do_execve()
660 error = -1; in do_execve()
661 for (i = 0; error == -1 && execsw[i]; ++i) { in do_execve()
662 if (execsw[i]->ex_imgact == NULL) in do_execve()
664 error = (*execsw[i]->ex_imgact)(imgp); in do_execve()
668 if (error == -1) in do_execve()
677 if (imgp->interpreted) { in do_execve()
686 MPASS(imgp->textset); in do_execve()
688 imgp->textset = false; in do_execve()
693 if (imgp->opened) { in do_execve()
694 VOP_CLOSE(newtextvp, FREAD, td->td_ucred, td); in do_execve()
695 imgp->opened = false; in do_execve()
698 imgp->vp = newtextvp = NULL; in do_execve()
699 if (args->fname != NULL) { in do_execve()
708 vm_object_deallocate(imgp->object); in do_execve()
709 imgp->object = NULL; in do_execve()
711 imgp->execpath = NULL; in do_execve()
712 free(imgp->freepath, M_TEMP); in do_execve()
713 imgp->freepath = NULL; in do_execve()
715 if (imgp->interpreter_vp) { in do_execve()
716 args->fname = NULL; in do_execve()
718 args->fname = imgp->interpreter_name; in do_execve()
727 VOP_UNLOCK(imgp->vp); in do_execve()
730 P_OSREL_MAJOR(p->p_osrel) > P_OSREL_MAJOR(__FreeBSD_version)) { in do_execve()
732 uprintf("Osrel %d for image %s too high\n", p->p_osrel, in do_execve()
733 imgp->execpath != NULL ? imgp->execpath : "<unresolved>"); in do_execve()
734 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in do_execve()
741 error = (*p->p_sysent->sv_copyout_strings)(imgp, &stack_base); in do_execve()
743 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in do_execve()
750 error = (*p->p_sysent->sv_fixup)(&stack_base, imgp); in do_execve()
752 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in do_execve()
768 i = exec_args_get_begin_envv(imgp->args) - imgp->args->begin_argv; in do_execve()
772 bcopy(imgp->args->begin_argv, newargs->ar_args, i); in do_execve()
781 if (sigacts_shared(p->p_sigacts)) { in do_execve()
782 oldsigacts = p->p_sigacts; in do_execve()
787 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in do_execve()
791 p->p_sigacts = newsigacts; in do_execve()
798 /* name this process - nameiexec(p, ndp) */ in do_execve()
799 bzero(p->p_comm, sizeof(p->p_comm)); in do_execve()
800 if (args->fname) in do_execve()
801 bcopy(nd.ni_cnd.cn_nameptr, p->p_comm, in do_execve()
803 else if (vn_commname(newtextvp, p->p_comm, sizeof(p->p_comm)) != 0) in do_execve()
804 bcopy(fexecv_proc_title, p->p_comm, sizeof(fexecv_proc_title)); in do_execve()
805 bcopy(p->p_comm, td->td_name, sizeof(td->td_name)); in do_execve()
814 p->p_flag |= P_EXEC; in do_execve()
815 if ((p->p_flag2 & P2_NOTRACE_EXEC) == 0) in do_execve()
816 p->p_flag2 &= ~P2_NOTRACE; in do_execve()
817 if ((p->p_flag2 & P2_STKGAP_DISABLE_EXEC) == 0) in do_execve()
818 p->p_flag2 &= ~P2_STKGAP_DISABLE; in do_execve()
819 p->p_flag2 &= ~(P2_MEMBAR_PRIVE | P2_MEMBAR_PRIVE_SYNCORE | in do_execve()
821 if (p->p_flag & P_PPWAIT) { in do_execve()
822 p->p_flag &= ~(P_PPWAIT | P_PPTRACE); in do_execve()
823 cv_broadcast(&p->p_pwait); in do_execve()
828 if ((imgp->sysent->sv_setid_allowed != NULL && in do_execve()
829 !(*imgp->sysent->sv_setid_allowed)(td, imgp)) || in do_execve()
830 (p->p_flag2 & P2_NO_NEW_PRIVS) != 0) in do_execve()
836 if (imgp->credential_setid) { in do_execve()
838 * Turn off syscall tracing for set-id programs, except for in do_execve()
839 * root. Record any set-id flags first to make sure that in do_execve()
854 VOP_UNLOCK(imgp->vp); in do_execve()
857 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in do_execve()
863 mac_vnode_execve_transition(oldcred, imgp->newcred, in do_execve()
864 imgp->vp, interpvplabel, imgp); in do_execve()
868 if (oldcred->cr_uid == oldcred->cr_ruid && in do_execve()
869 oldcred->cr_gid == oldcred->cr_rgid) in do_execve()
870 p->p_flag &= ~P_SUGID; in do_execve()
875 if (imgp->newcred != NULL) { in do_execve()
876 proc_set_cred(p, imgp->newcred); in do_execve()
885 oldtextvp = p->p_textvp; in do_execve()
886 p->p_textvp = newtextvp; in do_execve()
887 oldtextdvp = p->p_textdvp; in do_execve()
888 p->p_textdvp = newtextdvp; in do_execve()
890 oldbinname = p->p_binname; in do_execve()
891 p->p_binname = newbinname; in do_execve()
905 * as we're now a bona fide freshly-execed process. in do_execve()
907 KNOTE_LOCKED(p->p_klist, NOTE_EXEC); in do_execve()
908 p->p_flag &= ~P_INEXEC; in do_execve()
911 p->p_acflag &= ~AFORK; in do_execve()
917 oldargs = p->p_args; in do_execve()
918 p->p_args = newargs; in do_execve()
925 * Check if system-wide sampling is in effect or if the in do_execve()
931 VOP_UNLOCK(imgp->vp); in do_execve()
933 pe.pm_baseaddr = imgp->reloc_base; in do_execve()
934 pe.pm_dynaddr = imgp->et_dyn_addr; in do_execve()
937 vn_lock(imgp->vp, LK_SHARED | LK_RETRY); in do_execve()
942 (*p->p_sysent->sv_setregs)(td, imgp, stack_base); in do_execve()
944 VOP_MMAPPED(imgp->vp); in do_execve()
946 SDT_PROBE1(proc, , , exec__success, args->fname); in do_execve()
950 p->p_osrel = orig_osrel; in do_execve()
951 p->p_fctl0 = orig_fctl0; in do_execve()
952 p->p_elf_brandinfo = orig_brandinfo; in do_execve()
955 if (imgp->firstpage != NULL) in do_execve()
958 if (imgp->vp != NULL) { in do_execve()
959 if (imgp->opened) in do_execve()
960 VOP_CLOSE(imgp->vp, FREAD, td->td_ucred, td); in do_execve()
961 if (imgp->textset) in do_execve()
962 VOP_UNSET_TEXT_CHECKED(imgp->vp); in do_execve()
964 vput(imgp->vp); in do_execve()
966 VOP_UNLOCK(imgp->vp); in do_execve()
967 if (args->fname != NULL) in do_execve()
974 if (imgp->object != NULL) in do_execve()
975 vm_object_deallocate(imgp->object); in do_execve()
977 free(imgp->freepath, M_TEMP); in do_execve()
980 if (p->p_ptevents & PTRACE_EXEC) { in do_execve()
982 if (p->p_ptevents & PTRACE_EXEC) in do_execve()
983 td->td_dbgflags |= TDB_EXEC; in do_execve()
990 p->p_flag &= ~P_INEXEC; in do_execve()
996 if (imgp->newcred != NULL && oldcred != NULL) in do_execve()
997 crfree(imgp->newcred); in do_execve()
1023 if (error && imgp->vmspace_destroyed) { in do_execve()
1047 if ((td->td_pflags & TDP_EXECVMSPC) != 0) { in exec_cleanup()
1048 KASSERT(td->td_proc->p_vmspace != oldvmspace, in exec_cleanup()
1051 td->td_pflags &= ~TDP_EXECVMSPC; in exec_cleanup()
1062 if (imgp->firstpage != NULL) in exec_map_first_page()
1065 object = imgp->vp->v_object; in exec_map_first_page()
1069 if ((object->flags & OBJ_COLORED) == 0) { in exec_map_first_page()
1081 imgp->firstpage = sf_buf_alloc(m, 0); in exec_map_first_page()
1082 imgp->image_header = (char *)sf_buf_kva(imgp->firstpage); in exec_map_first_page()
1092 if (imgp->firstpage != NULL) { in exec_unmap_first_page()
1093 m = sf_buf_page(imgp->firstpage); in exec_unmap_first_page()
1094 sf_buf_free(imgp->firstpage); in exec_unmap_first_page()
1095 imgp->firstpage = NULL; in exec_unmap_first_page()
1104 umtx_exec(td->td_proc); in exec_onexec_old()
1118 vmspace = p->p_vmspace; in exec_free_abi_mappings()
1119 if (refcount_load(&vmspace->vm_refcnt) != 1) in exec_free_abi_mappings()
1125 pmap_remove(vmspace_pmap(vmspace), vmspace->vm_shp_base, in exec_free_abi_mappings()
1126 vmspace->vm_shp_base + p->p_sysent->sv_shared_page_len); in exec_free_abi_mappings()
1136 struct proc *p = imgp->proc; in exec_new_vmspace()
1137 struct vmspace *vmspace = p->p_vmspace; in exec_new_vmspace()
1142 imgp->vmspace_destroyed = true; in exec_new_vmspace()
1143 imgp->sysent = sv; in exec_new_vmspace()
1145 if (p->p_sysent->sv_onexec_old != NULL) in exec_new_vmspace()
1146 p->p_sysent->sv_onexec_old(td); in exec_new_vmspace()
1156 map = &vmspace->vm_map; in exec_new_vmspace()
1158 sv_minuser = sv->sv_minuser; in exec_new_vmspace()
1160 sv_minuser = MAX(sv->sv_minuser, PAGE_SIZE); in exec_new_vmspace()
1161 if (refcount_load(&vmspace->vm_refcnt) == 1 && in exec_new_vmspace()
1163 vm_map_max(map) == sv->sv_maxuser && in exec_new_vmspace()
1171 * ASLR and W^X states must be re-evaluated. in exec_new_vmspace()
1178 error = vmspace_exec(p, sv_minuser, sv->sv_maxuser); in exec_new_vmspace()
1181 vmspace = p->p_vmspace; in exec_new_vmspace()
1182 map = &vmspace->vm_map; in exec_new_vmspace()
1184 map->flags |= imgp->map_flags; in exec_new_vmspace()
1186 return (sv->sv_onexec != NULL ? sv->sv_onexec(p, imgp) : 0); in exec_new_vmspace()
1208 p = imgp->proc; in exec_map_stack()
1209 sv = p->p_sysent; in exec_map_stack()
1211 if (imgp->stack_sz != 0) { in exec_map_stack()
1212 ssiz = trunc_page(imgp->stack_sz); in exec_map_stack()
1222 } else if (sv->sv_maxssiz != NULL) { in exec_map_stack()
1223 ssiz = *sv->sv_maxssiz; in exec_map_stack()
1228 vmspace = p->p_vmspace; in exec_map_stack()
1229 map = &vmspace->vm_map; in exec_map_stack()
1231 stack_prot = sv->sv_shared_page_obj != NULL && imgp->stack_prot != 0 ? in exec_map_stack()
1232 imgp->stack_prot : sv->sv_stackprot; in exec_map_stack()
1233 if ((map->flags & MAP_ASLR_STACK) != 0) { in exec_map_stack()
1234 stack_addr = round_page((vm_offset_t)p->p_vmspace->vm_daddr + in exec_map_stack()
1238 stack_addr = sv->sv_usrstack - ssiz; in exec_map_stack()
1242 sv->sv_usrstack, find_space, stack_prot, VM_PROT_ALL, in exec_map_stack()
1252 if ((map->flags & MAP_ASLR_STACK) != 0) { in exec_map_stack()
1255 stack_top -= rounddown2(stack_off & PAGE_MASK, sizeof(void *)); in exec_map_stack()
1259 obj = sv->sv_shared_page_obj; in exec_map_stack()
1274 if ((imgp->imgp_flags & IMGP_ASLR_SHARED_PAGE) != 0) { in exec_map_stack()
1275 sharedpage_addr = round_page((vm_offset_t)p->p_vmspace->vm_daddr + in exec_map_stack()
1279 sv->sv_maxuser - PAGE_SIZE, PAGE_SIZE, in exec_map_stack()
1292 &sharedpage_addr, sv->sv_shared_page_len, in exec_map_stack()
1293 sv->sv_maxuser, VMFS_ANY_SPACE, in exec_map_stack()
1298 sharedpage_addr = sv->sv_shared_page_base; in exec_map_stack()
1300 sharedpage_addr, sv->sv_shared_page_len, in exec_map_stack()
1317 vmspace->vm_maxsaddr = (char *)stack_addr; in exec_map_stack()
1318 vmspace->vm_stacktop = stack_top; in exec_map_stack()
1319 vmspace->vm_ssize = sgrowsiz >> PAGE_SHIFT; in exec_map_stack()
1320 vmspace->vm_shp_base = sharedpage_addr; in exec_map_stack()
1341 * Allocate demand-paged memory for the file name, argument, and in exec_copyin_args()
1360 if (error == -1) { in exec_copyin_args()
1378 if (error == -1) { in exec_copyin_args()
1420 argkva->addr = kmap_alloc_wait(exec_map, exec_map_entry_size); in exec_prealloc_args_kva()
1421 argkva->gen = exec_args_gen; in exec_prealloc_args_kva()
1442 kasan_mark((void *)argkva->addr, exec_map_entry_size, in exec_alloc_args_kva()
1445 return (argkva->addr); in exec_alloc_args_kva()
1453 base = argkva->addr; in exec_release_args_kva()
1454 kasan_mark((void *)argkva->addr, 0, exec_map_entry_size, in exec_release_args_kva()
1456 if (argkva->gen != gen) { in exec_release_args_kva()
1459 argkva->gen = gen; in exec_release_args_kva()
1511 * Allocate temporary demand-paged, zero-filled memory for the file name,
1518 args->buf = (char *)exec_alloc_args_kva(&args->bufkva); in exec_alloc_args()
1526 if (args->buf != NULL) { in exec_free_args()
1527 exec_free_args_kva(args->bufkva); in exec_free_args()
1528 args->buf = NULL; in exec_free_args()
1530 if (args->fname_buf != NULL) { in exec_free_args()
1531 free(args->fname_buf, M_TEMP); in exec_free_args()
1532 args->fname_buf = NULL; in exec_free_args()
1544 * exec_args_add_fname() - install path to be executed
1545 * exec_args_add_arg() - append an argument string
1546 * exec_args_add_env() - append an env string
1547 * exec_args_adjust_args() - adjust location of the argument list to
1557 KASSERT(args->fname == NULL, ("fname already appended")); in exec_args_add_fname()
1558 KASSERT(args->endp == NULL, ("already appending to args")); in exec_args_add_fname()
1561 args->fname = args->buf; in exec_args_add_fname()
1563 copystr(fname, args->fname, PATH_MAX, &length) : in exec_args_add_fname()
1564 copyinstr(fname, args->fname, PATH_MAX, &length); in exec_args_add_fname()
1571 args->endp = args->buf + length; in exec_args_add_fname()
1573 args->begin_argv = args->endp; in exec_args_add_fname()
1574 KASSERT(exec_map_entry_size - length >= ARG_MAX, in exec_args_add_fname()
1576 exec_map_entry_size - length, (size_t)ARG_MAX)); in exec_args_add_fname()
1577 args->stringspace = ARG_MAX; in exec_args_add_fname()
1589 KASSERT(args->endp != NULL, ("endp not initialized")); in exec_args_add_str()
1590 KASSERT(args->begin_argv != NULL, ("begin_argp not initialized")); in exec_args_add_str()
1593 copystr(str, args->endp, args->stringspace, &length) : in exec_args_add_str()
1594 copyinstr(str, args->endp, args->stringspace, &length); in exec_args_add_str()
1597 args->stringspace -= length; in exec_args_add_str()
1598 args->endp += length; in exec_args_add_str()
1609 KASSERT(args->envc == 0, ("appending args after env")); in exec_args_add_arg()
1611 return (exec_args_add_str(args, argp, segflg, &args->argc)); in exec_args_add_arg()
1619 if (args->envc == 0) in exec_args_add_env()
1620 args->begin_envv = args->endp; in exec_args_add_env()
1622 return (exec_args_add_str(args, envp, segflg, &args->envc)); in exec_args_add_env()
1630 KASSERT(args->endp != NULL, ("endp not initialized")); in exec_args_adjust_args()
1631 KASSERT(args->begin_argv != NULL, ("begin_argp not initialized")); in exec_args_adjust_args()
1633 offset = extend - consume; in exec_args_adjust_args()
1634 if (args->stringspace < offset) in exec_args_adjust_args()
1636 memmove(args->begin_argv + extend, args->begin_argv + consume, in exec_args_adjust_args()
1637 args->endp - args->begin_argv + consume); in exec_args_adjust_args()
1638 if (args->envc > 0) in exec_args_adjust_args()
1639 args->begin_envv += offset; in exec_args_adjust_args()
1640 args->endp += offset; in exec_args_adjust_args()
1641 args->stringspace -= offset; in exec_args_adjust_args()
1649 KASSERT(args->endp != NULL, ("endp not initialized")); in exec_args_get_begin_envv()
1651 if (args->envc > 0) in exec_args_get_begin_envv()
1652 return (args->begin_envv); in exec_args_get_begin_envv()
1653 return (args->endp); in exec_args_get_begin_envv()
1675 p = imgp->proc; in exec_copyout_strings()
1676 sysent = p->p_sysent; in exec_copyout_strings()
1679 arginfo = imgp->ps_strings = (void *)destp; in exec_copyout_strings()
1684 if (sysent->sv_shared_page_base == 0 && sysent->sv_szsigcode != NULL) { in exec_copyout_strings()
1685 szsigcode = *(sysent->sv_szsigcode); in exec_copyout_strings()
1686 destp -= szsigcode; in exec_copyout_strings()
1688 error = copyout(sysent->sv_sigcode, (void *)destp, szsigcode); in exec_copyout_strings()
1696 if (imgp->execpath != NULL && imgp->auxargs != NULL) { in exec_copyout_strings()
1697 execpath_len = strlen(imgp->execpath) + 1; in exec_copyout_strings()
1698 destp -= execpath_len; in exec_copyout_strings()
1700 imgp->execpathp = (void *)destp; in exec_copyout_strings()
1701 error = copyout(imgp->execpath, imgp->execpathp, execpath_len); in exec_copyout_strings()
1710 destp -= sizeof(canary); in exec_copyout_strings()
1711 imgp->canary = (void *)destp; in exec_copyout_strings()
1712 error = copyout(canary, imgp->canary, sizeof(canary)); in exec_copyout_strings()
1715 imgp->canarylen = sizeof(canary); in exec_copyout_strings()
1720 imgp->pagesizeslen = sizeof(pagesizes[0]) * MAXPAGESIZES; in exec_copyout_strings()
1721 destp -= imgp->pagesizeslen; in exec_copyout_strings()
1723 imgp->pagesizes = (void *)destp; in exec_copyout_strings()
1724 error = copyout(pagesizes, imgp->pagesizes, imgp->pagesizeslen); in exec_copyout_strings()
1731 destp -= ARG_MAX - imgp->args->stringspace; in exec_copyout_strings()
1735 if (imgp->auxargs) { in exec_copyout_strings()
1740 destp -= AT_COUNT * sizeof(Elf_Auxinfo); in exec_copyout_strings()
1750 vectp -= imgp->args->argc + 1 + imgp->args->envc + 1; in exec_copyout_strings()
1757 stringp = imgp->args->begin_argv; in exec_copyout_strings()
1758 argc = imgp->args->argc; in exec_copyout_strings()
1759 envc = imgp->args->envc; in exec_copyout_strings()
1762 * Copy out strings - arguments and environment. in exec_copyout_strings()
1765 ARG_MAX - imgp->args->stringspace); in exec_copyout_strings()
1772 imgp->argv = vectp; in exec_copyout_strings()
1773 if (suword(&arginfo->ps_argvstr, (long)(intptr_t)vectp) != 0 || in exec_copyout_strings()
1774 suword32(&arginfo->ps_nargvstr, argc) != 0) in exec_copyout_strings()
1780 for (; argc > 0; --argc) { in exec_copyout_strings()
1792 imgp->envv = vectp; in exec_copyout_strings()
1793 if (suword(&arginfo->ps_envstr, (long)(intptr_t)vectp) != 0 || in exec_copyout_strings()
1794 suword32(&arginfo->ps_nenvstr, envc) != 0) in exec_copyout_strings()
1800 for (; envc > 0; --envc) { in exec_copyout_strings()
1812 if (imgp->auxargs) { in exec_copyout_strings()
1814 error = imgp->sysent->sv_copyout_auxargs(imgp, in exec_copyout_strings()
1825 * Called with imgp->vp locked.
1831 struct vnode *vp = imgp->vp; in exec_check_permissions()
1832 struct vattr *attr = imgp->attr; in exec_check_permissions()
1839 error = VOP_GETATTR(vp, attr, td->td_ucred); in exec_check_permissions()
1844 error = mac_vnode_check_exec(td->td_ucred, imgp->vp, imgp); in exec_check_permissions()
1857 if ((vp->v_mount->mnt_flag & MNT_NOEXEC) || in exec_check_permissions()
1858 (attr->va_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) == 0 || in exec_check_permissions()
1859 (attr->va_type != VREG)) in exec_check_permissions()
1865 if (attr->va_size == 0) in exec_check_permissions()
1871 error = VOP_ACCESS(vp, VEXEC, td->td_ucred, td); in exec_check_permissions()
1876 * Check number of open-for-writes on the file and deny execution in exec_check_permissions()
1888 imgp->textset = true; in exec_check_permissions()
1894 error = VOP_OPEN(vp, FREAD, td->td_ucred, td, NULL); in exec_check_permissions()
1896 imgp->opened = true; in exec_check_permissions()
1906 const struct execsw **es, **xs, **newexecsw; in exec_register() local
1910 for (es = execsw; *es; es++) in exec_register()
1912 newexecsw = malloc(count * sizeof(*es), M_TEMP, M_WAITOK); in exec_register()
1915 for (es = execsw; *es; es++) in exec_register()
1916 *xs++ = *es; in exec_register()
1928 const struct execsw **es, **xs, **newexecsw; in exec_unregister() local
1934 for (es = execsw; *es; es++) { in exec_unregister()
1935 if (*es == execsw_arg) in exec_unregister()
1938 if (*es == NULL) in exec_unregister()
1940 for (es = execsw; *es; es++) in exec_unregister()
1941 if (*es != execsw_arg) in exec_unregister()
1943 newexecsw = malloc(count * sizeof(*es), M_TEMP, M_WAITOK); in exec_unregister()
1945 for (es = execsw; *es; es++) in exec_unregister()
1946 if (*es != execsw_arg) in exec_unregister()
1947 *xs++ = *es; in exec_unregister()
1975 error = compressor_write(cp->comp, buf, chunk_len); in compress_chunk()
1979 len -= chunk_len; in compress_chunk()
1989 return (vn_rdwr_inchunks(UIO_WRITE, cp->vp, __DECONST(void *, base), in core_write()
1991 cp->active_cred, cp->file_cred, resid, cp->td)); in core_write()
2005 ("%s: user address %p is not page-aligned", __func__, base)); in core_output()
2007 if (cp->comp != NULL) in core_output()
2011 map = &cp->td->td_proc->p_vmspace->vm_map; in core_output()
2012 for (; len > 0; base += runlen, offset += runlen, len -= runlen) { in core_output()
2016 * a hole in the file. This can occur with zero-filled in core_output()
2046 runlen -= resid; in core_output()
2054 error = vn_start_write(cp->vp, &mp, V_WAIT); in core_output()
2057 vn_lock(cp->vp, LK_EXCLUSIVE | LK_RETRY); in core_output()
2058 error = vn_truncate_locked(cp->vp, offset + runlen, in core_output()
2059 false, cp->td->td_ucred); in core_output()
2060 VOP_UNLOCK(cp->vp); in core_output()
2080 p = cp->td->td_proc; in sbuf_drain_core_output()
2085 * non-sleepable lock held is unsafe. The lock is needed for in sbuf_drain_core_output()
2093 if (cp->comp != NULL) in sbuf_drain_core_output()
2094 error = compressor_write(cp->comp, __DECONST(char *, data), in sbuf_drain_core_output()
2097 error = core_write(cp, __DECONST(void *, data), len, cp->offset, in sbuf_drain_core_output()
2102 return (-error); in sbuf_drain_core_output()
2103 cp->offset += len; in sbuf_drain_core_output()