1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1993, David Greenman 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of the University nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * 31 * $FreeBSD$ 32 */ 33 34 #ifndef _SYS_IMGACT_H_ 35 #define _SYS_IMGACT_H_ 36 37 #include <sys/_uio.h> 38 39 #include <vm/vm.h> 40 41 #define MAXSHELLCMDLEN PAGE_SIZE 42 43 struct ucred; 44 45 struct image_args { 46 char *buf; /* pointer to string buffer */ 47 void *bufkva; /* cookie for string buffer KVA */ 48 char *begin_argv; /* beginning of argv in buf */ 49 char *begin_envv; /* (interal use only) beginning of envv in buf, 50 * access with exec_args_get_begin_envv(). */ 51 char *endp; /* current `end' pointer of arg & env strings */ 52 char *fname; /* pointer to filename of executable (system space) */ 53 char *fname_buf; /* pointer to optional malloc(M_TEMP) buffer */ 54 int stringspace; /* space left in arg & env buffer */ 55 int argc; /* count of argument strings */ 56 int envc; /* count of environment strings */ 57 int fd; /* file descriptor of the executable */ 58 struct filedesc *fdp; /* new file descriptor table */ 59 }; 60 61 struct image_params { 62 struct proc *proc; /* our process struct */ 63 struct label *execlabel; /* optional exec label */ 64 struct vnode *vp; /* pointer to vnode of file to exec */ 65 struct vm_object *object; /* The vm object for this vp */ 66 struct vattr *attr; /* attributes of file */ 67 const char *image_header; /* head of file to exec */ 68 unsigned long entry_addr; /* entry address of target executable */ 69 unsigned long reloc_base; /* load address of image */ 70 char vmspace_destroyed; /* flag - we've blown away original vm space */ 71 #define IMGACT_SHELL 0x1 72 #define IMGACT_BINMISC 0x2 73 unsigned char interpreted; /* mask of interpreters that have run */ 74 char opened; /* flag - we have opened executable vnode */ 75 char *interpreter_name; /* name of the interpreter */ 76 void *auxargs; /* ELF Auxinfo structure pointer */ 77 struct sf_buf *firstpage; /* first page that we mapped */ 78 unsigned long ps_strings; /* PS_STRINGS for BSD/OS binaries */ 79 struct image_args *args; /* system call arguments */ 80 struct sysentvec *sysent; /* system entry vector */ 81 char *execpath; 82 unsigned long execpathp; 83 char *freepath; 84 unsigned long canary; 85 int canarylen; 86 unsigned long pagesizes; 87 int pagesizeslen; 88 vm_prot_t stack_prot; 89 u_long stack_sz; 90 struct ucred *newcred; /* new credentials if changing */ 91 bool credential_setid; /* true if becoming setid */ 92 u_int map_flags; 93 }; 94 95 #ifdef _KERNEL 96 struct sysentvec; 97 struct thread; 98 struct vmspace; 99 100 int exec_alloc_args(struct image_args *); 101 int exec_args_add_arg(struct image_args *args, const char *argp, 102 enum uio_seg segflg); 103 int exec_args_add_env(struct image_args *args, const char *envp, 104 enum uio_seg segflg); 105 int exec_args_add_fname(struct image_args *args, const char *fname, 106 enum uio_seg segflg); 107 int exec_args_adjust_args(struct image_args *args, size_t consume, 108 ssize_t extend); 109 char *exec_args_get_begin_envv(struct image_args *args); 110 int exec_check_permissions(struct image_params *); 111 register_t *exec_copyout_strings(struct image_params *); 112 void exec_free_args(struct image_args *); 113 int exec_new_vmspace(struct image_params *, struct sysentvec *); 114 void exec_setregs(struct thread *, struct image_params *, u_long); 115 int exec_shell_imgact(struct image_params *); 116 int exec_copyin_args(struct image_args *, const char *, enum uio_seg, 117 char **, char **); 118 int exec_copyin_data_fds(struct thread *, struct image_args *, const void *, 119 size_t, const int *, size_t); 120 int pre_execve(struct thread *td, struct vmspace **oldvmspace); 121 void post_execve(struct thread *td, int error, struct vmspace *oldvmspace); 122 #endif 123 124 #endif /* !_SYS_IMGACT_H_ */ 125