• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.5.8/xnu-1228.15.4/bsd/kern/

Lines Matching refs:imgp

203 static int exec_activate_image(struct image_params *imgp);
204 static int exec_copyout_strings(struct image_params *imgp, user_addr_t *stackp);
206 static int execargs_alloc(struct image_params *imgp);
207 static int execargs_free(struct image_params *imgp);
208 static int exec_check_permissions(struct image_params *imgp);
209 static int exec_extract_strings(struct image_params *imgp);
210 static int exec_handle_sugid(struct image_params *imgp);
234 * (imgp->ip_strendp) updated location of next add, if any
235 * (imgp->ip_strspace) updated byte count of space remaining
238 exec_add_string(struct image_params *imgp, user_addr_t str)
244 if (imgp->ip_strspace <= 0) {
248 if (IS_UIO_SYS_SPACE(imgp->ip_seg)) {
250 error = copystr(kstr, imgp->ip_strendp, imgp->ip_strspace, &len);
252 error = copyinstr(str, imgp->ip_strendp, imgp->ip_strspace,
255 imgp->ip_strendp += len;
256 imgp->ip_strspace -= len;
284 * (imgp->ip_strings) saved path
285 * (imgp->ip_strspace) space remaining in ip_strings
286 * (imgp->ip_argv) beginning of argument list
287 * (imgp->ip_strendp) start of remaining copy area
297 exec_save_path(struct image_params *imgp, user_addr_t path, int seg)
303 imgp->ip_strendp = imgp->ip_strings;
304 imgp->ip_strspace = SIZE_IMG_STRSPACE;
306 len = MIN(MAXPATHLEN, imgp->ip_strspace);
311 error = copyinstr(path, imgp->ip_strings, len, &len);
314 error = copystr(kpath, imgp->ip_strings, len, &len);
322 imgp->ip_strendp += len;
323 imgp->ip_strspace -= len;
324 imgp->ip_argv = imgp->ip_strendp;
357 exec_powerpc32_imgact(struct image_params *imgp)
359 struct mach_header *mach_header = (struct mach_header *)imgp->ip_vdata;
382 if (!imgp->ip_origcputype) {
383 imgp->ip_origcputype =
385 imgp->ip_origcpusubtype =
394 imgp->ip_flags |= IMGPF_POWERPC;
397 error = copystr(exec_archhandler_ppc.path, imgp->ip_interp_name,
408 strlcpy(imgp->ip_p_comm, imgp->ip_ndp->ni_cnd.cn_nameptr, MAXCOMLEN);
437 exec_shell_imgact(struct image_params *imgp)
439 char *vdata = imgp->ip_vdata;
460 (imgp->ip_flags & IMGPF_INTERPRET) != 0) {
465 if ((imgp->ip_flags & IMGPF_POWERPC) != 0)
469 imgp->ip_flags |= IMGPF_INTERPRET;
473 * imgp->ip_vattr is known to be valid.
476 imgp->ip_origvattr->va_mode &= ~(VSUID | VSGID);
503 interp = imgp->ip_interp_name;
508 exec_save_path(imgp, CAST_USER_ADDR_T(imgp->ip_interp_name),
522 *imgp->ip_strendp++ = *ihp++;
523 imgp->ip_strspace--;
525 *imgp->ip_strendp++ = 0;
526 imgp->ip_strspace--;
527 imgp->ip_argc++;
535 if (imgp->ip_origvattr->va_mode & (VSUID | VSGID)) {
536 p = vfs_context_proc(imgp->ip_vfs_context);
537 error = falloc(p, &fp, &fd, imgp->ip_vfs_context);
544 fp->f_fglob->fg_data = (caddr_t)imgp->ip_vp;
550 vnode_ref(imgp->ip_vp);
553 error = copyoutstr(temp, imgp->ip_user_fname, sizeof(temp), &len);
590 exec_fat_imgact(struct image_params *imgp)
592 proc_t p = vfs_context_proc(imgp->ip_vfs_context);
594 struct fat_header *fat_header = (struct fat_header *)imgp->ip_vdata;
608 psa = (struct _posix_spawnattr *) imgp->ip_px_sa;
651 lret = fatfile_getarch_affinity(imgp->ip_vp,
662 error = vn_rdwr(UIO_READ, imgp->ip_vp, imgp->ip_vdata,
678 imgp->ip_arch_offset = (user_size_t)fat_arch.offset;
679 imgp->ip_arch_size = (user_size_t)fat_arch.size;
710 exec_mach_imgact(struct image_params *imgp)
712 struct mach_header *mach_header = (struct mach_header *)imgp->ip_vdata;
713 proc_t p = vfs_context_proc(imgp->ip_vfs_context);
744 if (!imgp->ip_origcputype) {
745 imgp->ip_origcputype = mach_header->cputype;
746 imgp->ip_origcpusubtype = mach_header->cpusubtype;
757 imgp->ip_flags |= IMGPF_IS_64BIT;
760 psa = (struct _posix_spawnattr *) imgp->ip_px_sa;
776 if (pref == imgp->ip_origcputype) {
785 if (!grade_binary(imgp->ip_origcputype & ~CPU_SUBTYPE_LIB64,
786 imgp->ip_origcpusubtype & ~CPU_SUBTYPE_MASK)) {
792 error = exec_extract_strings(imgp);
801 imgp->ip_strendp[0] = 0;
802 imgp->ip_strendp[1] = 0;
803 imgp->ip_strendp[2] = 0;
804 imgp->ip_strendp += (((imgp->ip_strendp - imgp->ip_strings) + NBPW-1) & ~(NBPW-1));
815 if (imgp->ip_vattr->va_fsid == exec_archhandler_ppc.fsid &&
816 imgp->ip_vattr->va_fileid == (uint64_t)((u_long)exec_archhandler_ppc.fileid)) {
817 imgp->ip_flags |= IMGPF_POWERPC;
822 imgp->ip_vfork_thread = fork_create_child(task, p, FALSE, (imgp->ip_flags & IMGPF_IS_64BIT));
823 if (imgp->ip_vfork_thread == NULL) {
828 thread = imgp->ip_vfork_thread;
840 if (imgp->ip_flags & IMGPF_IS_64BIT) {
864 ((imgp->ip_flags & IMGPF_IS_64BIT) == IMGPF_IS_64BIT));
869 lret = load_machfile(imgp, mach_header, thread, map, &load_result);
883 imgp->ip_csflags |= load_result.csflags &
887 imgp->ip_csflags &= ~CS_VALID;
891 imgp->ip_csflags |= CS_HARD;
893 imgp->ip_csflags |= CS_KILL;
903 imgp->ip_flags & IMGPF_POWERPC ?
917 error = exec_handle_sugid(imgp);
954 error = exec_copyout_strings(imgp, &ap);
968 if (imgp->ip_flags & IMGPF_IS_64BIT) {
1020 if (0 != imgp->ip_p_comm[0]) {
1021 bcopy((caddr_t)imgp->ip_p_comm, (caddr_t)p->p_comm,
1024 if (imgp->ip_ndp->ni_cnd.cn_namelen > MAXCOMLEN)
1025 imgp->ip_ndp->ni_cnd.cn_namelen = MAXCOMLEN;
1026 bcopy((caddr_t)imgp->ip_ndp->ni_cnd.cn_nameptr, (caddr_t)p->p_comm,
1027 (unsigned)imgp->ip_ndp->ni_cnd.cn_namelen);
1028 p->p_comm[imgp->ip_ndp->ni_cnd.cn_namelen] = '\0';
1094 if (((imgp->ip_flags & IMGPF_POWERPC) != 0))
1105 if (imgp->ip_px_sa != NULL) {
1106 psa = (struct _posix_spawnattr *) imgp->ip_px_sa;
1173 * the image associated with the imgp structure. We start with
1195 exec_activate_image(struct image_params *imgp)
1203 proc_t p = vfs_context_proc(imgp->ip_vfs_context);
1205 error = execargs_alloc(imgp);
1215 error = exec_save_path(imgp, imgp->ip_user_fname, imgp->ip_seg);
1220 DTRACE_PROC1(exec, uintptr_t, imgp->ip_strings);
1223 imgp->ip_seg, imgp->ip_user_fname, imgp->ip_vfs_context);
1229 imgp->ip_ndp = &nd; /* successful namei(); call nameidone() later */
1230 imgp->ip_vp = nd.ni_vp; /* if set, need to vnode_put() at some point */
1234 error = exec_check_permissions(imgp);
1241 *imgp->ip_origvattr = *imgp->ip_vattr;
1244 error = vn_rdwr(UIO_READ, imgp->ip_vp, imgp->ip_vdata, PAGE_SIZE, 0,
1246 vfs_context_ucred(imgp->ip_vfs_context),
1247 &resid, vfs_context_proc(imgp->ip_vfs_context));
1260 error = (*execsw[i].ex_imgact)(imgp);
1274 if (imgp->ip_scriptlabelp)
1275 mac_vnode_label_free(imgp->ip_scriptlabelp);
1276 imgp->ip_scriptlabelp = mac_vnode_label_alloc();
1277 if (imgp->ip_scriptlabelp == NULL) {
1281 mac_vnode_label_copy(imgp->ip_vp->v_label,
1282 imgp->ip_scriptlabelp);
1284 vnode_put(imgp->ip_vp);
1285 imgp->ip_vp = NULL; /* already put */
1296 if (imgp->ip_flags & IMGPF_POWERPC)
1301 nd.ni_dirp = CAST_USER_ADDR_T(imgp->ip_interp_name);
1315 kauth_authorize_fileop(vfs_context_ucred(imgp->ip_vfs_context),
1324 if (imgp->ip_strings)
1325 execargs_free(imgp);
1326 if (imgp->ip_ndp)
1327 nameidone(imgp->ip_ndp);
1345 exec_handle_port_actions(struct image_params *imgp)
1347 _posix_spawn_port_actions_t pacts = imgp->ip_px_spa;
1348 proc_t p = vfs_context_proc(imgp->ip_vfs_context);
1411 exec_handle_file_actions(struct image_params *imgp)
1415 proc_t p = vfs_context_proc(imgp->ip_vfs_context);
1416 _posix_spawn_file_actions_t px_sfap = imgp->ip_px_sfa;
1446 imgp->ip_vfs_context);
1448 error = open1(imgp->ip_vfs_context,
1564 struct image_params image_params, *imgp;
1581 imgp = &image_params;
1584 bzero(imgp, sizeof(*imgp));
1585 imgp->ip_user_fname = uap->path;
1586 imgp->ip_user_argv = uap->argv;
1587 imgp->ip_user_envv = uap->envp;
1588 imgp->ip_vattr = &va;
1589 imgp->ip_origvattr = &origva;
1590 imgp->ip_vfs_context = &context;
1591 imgp->ip_flags = (is_64 ? IMGPF_WAS_64BIT : IMGPF_NONE);
1592 imgp->ip_p_comm = alt_p_comm; /* for PowerPC */
1593 imgp->ip_seg = (is_64 ? UIO_USERSPACE64 : UIO_USERSPACE32);
1625 imgp->ip_px_sa = &px_sa;
1640 imgp->ip_px_sfa = px_sfap;
1660 imgp->ip_px_spa = px_spap;
1668 if (imgp->ip_px_sa == NULL || !(px_sa.psa_flags & POSIX_SPAWN_SETEXEC)){
1689 if (imgp->ip_px_sfa != NULL &&
1690 (error = exec_handle_file_actions(imgp)) != 0) {
1695 if (imgp->ip_px_spa != NULL) {
1701 if((error = exec_handle_port_actions(imgp)) != 0)
1706 if (imgp->ip_px_sa != NULL) {
1782 error = mac_execve_enter(uap->mac_p, imgp);
1788 if ((error = exec_activate_image(imgp)) != 0)
1795 exec_resettextvp(p, imgp);
1797 if (imgp->ip_vp)
1798 vnode_put(imgp->ip_vp);
1799 if (imgp->ip_strings)
1800 execargs_free(imgp);
1801 if (imgp->ip_px_sfa != NULL)
1802 FREE(imgp->ip_px_sfa, M_TEMP);
1803 if (imgp->ip_px_spa != NULL)
1804 FREE(imgp->ip_px_spa, M_TEMP);
1807 if (imgp->ip_execlabelp)
1808 mac_cred_label_free(imgp->ip_execlabelp);
1809 if (imgp->ip_scriptlabelp)
1810 mac_vnode_label_free(imgp->ip_scriptlabelp);
1833 p->p_csflags = imgp->ip_csflags;
1836 (void)thread_resume(imgp->ip_vfork_thread);
1846 p->p_csflags = imgp->ip_csflags;
1923 struct image_params image_params, *imgp;
1937 imgp = &image_params;
1940 bzero(imgp, sizeof(*imgp));
1941 imgp->ip_user_fname = uap->fname;
1942 imgp->ip_user_argv = uap->argp;
1943 imgp->ip_user_envv = uap->envp;
1944 imgp->ip_vattr = &va;
1945 imgp->ip_origvattr = &origva;
1946 imgp->ip_vfs_context = &context;
1947 imgp->ip_flags = (is_64 ? IMGPF_WAS_64BIT : IMGPF_NONE);
1948 imgp->ip_p_comm = alt_p_comm; /* for PowerPC */
1949 imgp->ip_seg = (is_64 ? UIO_USERSPACE64 : UIO_USERSPACE32);
1980 error = mac_execve_enter(uap->mac_p, imgp);
1988 error = exec_activate_image(imgp);
1997 exec_resettextvp(p, imgp);
1999 if (imgp->ip_vp != NULLVP)
2000 vnode_put(imgp->ip_vp);
2001 if (imgp->ip_strings)
2002 execargs_free(imgp);
2004 if (imgp->ip_execlabelp)
2005 mac_cred_label_free(imgp->ip_execlabelp);
2006 if (imgp->ip_scriptlabelp)
2007 mac_vnode_label_free(imgp->ip_scriptlabelp);
2016 p->p_csflags = imgp->ip_csflags;
2022 (void)thread_resume(imgp->ip_vfork_thread);
2165 exec_copyout_strings(struct image_params *imgp, user_addr_t *stackp)
2167 proc_t p = vfs_context_proc(imgp->ip_vfs_context);
2168 int ptr_size = (imgp->ip_flags & IMGPF_IS_64BIT) ? 8 : 4;
2169 char *argv = imgp->ip_argv; /* modifiable copy of argv */
2174 int stringc = imgp->ip_argc + imgp->ip_envc;
2181 unsigned patharea_len = imgp->ip_argv - imgp->ip_strings;
2190 string_area = stack - (((imgp->ip_strendp - imgp->ip_strings) + ptr_size-1) & ~(ptr_size-1)) - ptr_size;
2192 ptr_area = path_area - ((imgp->ip_argc + imgp->ip_envc + 4 + envc_add) * ptr_size) - ptr_size /*argc*/;
2202 p->p_argc = imgp->ip_argc;
2209 * the "path" at the begining of the imgp->ip_strings buffer.
2213 error = copyoutstr(imgp->ip_strings, path_area,
2234 (void)suword(ptr_area, imgp->ip_argc);
2237 if (imgp->ip_flags & IMGPF_IS_64BIT) {
2248 * intuitive (imgp->ip_argv - imgp->ip_strings) because we are
2256 if (stringc == imgp->ip_envc) {
2308 * (imgp->ip_argc) Count of arguments, updated
2309 * (imgp->ip_envc) Count of environment strings, updated
2316 exec_extract_strings(struct image_params *imgp)
2319 int ptr_size = (imgp->ip_flags & IMGPF_WAS_64BIT) ? 8 : 4;
2320 user_addr_t argv = imgp->ip_user_argv;
2321 user_addr_t envv = imgp->ip_user_envv;
2327 if (imgp->ip_user_argv == 0LL)
2338 if((imgp->ip_flags & IMGPF_INTERPRET) != 0 && argv != 0LL) {
2346 error = exec_add_string(imgp, imgp->ip_user_fname);
2349 imgp->ip_argc++;
2371 error = exec_add_string(imgp, arg);
2374 imgp->ip_argc++;
2395 error = exec_add_string(imgp, env);
2398 imgp->ip_envc++;
2424 exec_check_permissions(struct image_params *imgp)
2426 struct vnode *vp = imgp->ip_vp;
2427 struct vnode_attr *vap = imgp->ip_vattr;
2428 proc_t p = vfs_context_proc(imgp->ip_vfs_context);
2444 if ((error = vnode_getattr(vp, vap, imgp->ip_vfs_context)) != 0)
2459 imgp->ip_arch_offset = (user_size_t)0;
2460 imgp->ip_arch_size = vap->va_data_size;
2466 imgp->ip_no_trans = 1;
2471 error = mac_vnode_check_exec(imgp->ip_vfs_context, vp, imgp);
2481 if ((error = vnode_authorize(vp, NULL, action, imgp->ip_vfs_context)) != 0)
2504 imgp->ip_flags |= IMGPF_POWERPC;
2541 exec_handle_sugid(struct image_params *imgp)
2543 kauth_cred_t cred = vfs_context_ucred(imgp->ip_vfs_context);
2544 proc_t p = vfs_context_proc(imgp->ip_vfs_context);
2562 imgp->ip_vfs_context,
2563 imgp->ip_vp,
2564 imgp->ip_scriptlabelp,
2565 imgp->ip_execlabelp, p);
2584 if (((imgp->ip_origvattr->va_mode & VSUID) != 0 &&
2585 kauth_cred_getuid(cred) != imgp->ip_origvattr->va_uid) ||
2586 ((imgp->ip_origvattr->va_mode & VSGID) != 0 &&
2587 ((kauth_cred_ismember_gid(cred, imgp->ip_origvattr->va_gid, &leave_sugid_clear) || !leave_sugid_clear) ||
2588 (cred->cr_gid != imgp->ip_origvattr->va_gid)))) {
2611 if (imgp->ip_origvattr->va_mode & VSUID) {
2612 p->p_ucred = kauth_cred_setresuid(p->p_ucred, KAUTH_UID_NONE, imgp->ip_origvattr->va_uid, imgp->ip_origvattr->va_uid, KAUTH_UID_NONE);
2614 if (imgp->ip_origvattr->va_mode & VSGID) {
2615 p->p_ucred = kauth_cred_setresgid(p->p_ucred, KAUTH_GID_NONE, imgp->ip_origvattr->va_gid, imgp->ip_origvattr->va_gid);
2628 imgp->ip_vfs_context,
2629 imgp->ip_vp,
2630 imgp->ip_scriptlabelp,
2631 imgp->ip_execlabelp)) {
2679 imgp->ip_vfs_context);
2709 if ((error = falloc(p, &fp, &indx, imgp->ip_vfs_context)) != 0)
3022 execargs_alloc(struct image_params *imgp)
3039 kret = kmem_alloc_pageable(bsd_pageable_map, (vm_offset_t *)&imgp->ip_strings, NCARGS + PAGE_SIZE);
3040 imgp->ip_vdata = imgp->ip_strings + NCARGS;
3062 execargs_free(struct image_params *imgp)
3066 kmem_free(bsd_pageable_map, (vm_offset_t)imgp->ip_strings, NCARGS + PAGE_SIZE);
3067 imgp->ip_strings = NULL;
3085 exec_resettextvp(proc_t p, struct image_params *imgp)
3092 vp = imgp->ip_vp;
3093 offset = imgp->ip_arch_offset;