kern_exec.c (87593) | kern_exec.c (88633) |
---|---|
1/* 2 * Copyright (c) 1993, David Greenman 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/* 2 * Copyright (c) 1993, David Greenman 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/sys/kern/kern_exec.c 87593 2001-12-10 05:40:12Z obrien $ | 26 * $FreeBSD: head/sys/kern/kern_exec.c 88633 2001-12-29 07:13:47Z alfred $ |
27 */ 28 29#include <sys/param.h> 30#include <sys/systm.h> 31#include <sys/lock.h> 32#include <sys/mutex.h> 33#include <sys/sysproto.h> 34#include <sys/signalvar.h> --- 25 unchanged lines hidden (view full) --- 60#include <vm/vm_extern.h> 61#include <vm/vm_object.h> 62#include <vm/vm_pager.h> 63 64#include <machine/reg.h> 65 66MALLOC_DEFINE(M_PARGS, "proc-args", "Process arguments"); 67 | 27 */ 28 29#include <sys/param.h> 30#include <sys/systm.h> 31#include <sys/lock.h> 32#include <sys/mutex.h> 33#include <sys/sysproto.h> 34#include <sys/signalvar.h> --- 25 unchanged lines hidden (view full) --- 60#include <vm/vm_extern.h> 61#include <vm/vm_object.h> 62#include <vm/vm_pager.h> 63 64#include <machine/reg.h> 65 66MALLOC_DEFINE(M_PARGS, "proc-args", "Process arguments"); 67 |
68static MALLOC_DEFINE(M_ATEXEC, "atexec", "atexec callback"); 69 70/* 71 * callout list for things to do at exec time 72 */ 73struct execlist { 74 execlist_fn function; 75 TAILQ_ENTRY(execlist) next; 76}; 77 78TAILQ_HEAD(exec_list_head, execlist); 79static struct exec_list_head exec_list = TAILQ_HEAD_INITIALIZER(exec_list); 80 |
|
68static register_t *exec_copyout_strings __P((struct image_params *)); 69 70/* XXX This should be vm_size_t. */ 71static u_long ps_strings = PS_STRINGS; 72SYSCTL_ULONG(_kern, KERN_PS_STRINGS, ps_strings, CTLFLAG_RD, &ps_strings, 0, ""); 73 74/* XXX This should be vm_size_t. */ 75static u_long usrstack = USRSTACK; --- 34 unchanged lines hidden (view full) --- 110 struct nameidata nd, *ndp; 111 struct ucred *newcred, *oldcred; 112 register_t *stack_base; 113 int error, len, i; 114 struct image_params image_params, *imgp; 115 struct vattr attr; 116 int (*img_first) __P((struct image_params *)); 117 struct pargs *pa; | 81static register_t *exec_copyout_strings __P((struct image_params *)); 82 83/* XXX This should be vm_size_t. */ 84static u_long ps_strings = PS_STRINGS; 85SYSCTL_ULONG(_kern, KERN_PS_STRINGS, ps_strings, CTLFLAG_RD, &ps_strings, 0, ""); 86 87/* XXX This should be vm_size_t. */ 88static u_long usrstack = USRSTACK; --- 34 unchanged lines hidden (view full) --- 123 struct nameidata nd, *ndp; 124 struct ucred *newcred, *oldcred; 125 register_t *stack_base; 126 int error, len, i; 127 struct image_params image_params, *imgp; 128 struct vattr attr; 129 int (*img_first) __P((struct image_params *)); 130 struct pargs *pa; |
131 struct execlist *ep; |
|
118 119 imgp = &image_params; 120 121 /* 122 * Lock the process and set the P_INEXEC flag to indicate that 123 * it should be left alone until we're done here. This is 124 * necessary to avoid race conditions - e.g. in ptrace() - 125 * that might allow a local user to illicitly obtain elevated --- 113 unchanged lines hidden (view full) --- 239 NDFREE(ndp, NDF_ONLY_PNBUF); 240 vrele(ndp->ni_vp); 241 /* set new name to that of the interpreter */ 242 NDINIT(ndp, LOOKUP, LOCKLEAF | FOLLOW | SAVENAME, 243 UIO_SYSSPACE, imgp->interpreter_name, td); 244 goto interpret; 245 } 246 | 132 133 imgp = &image_params; 134 135 /* 136 * Lock the process and set the P_INEXEC flag to indicate that 137 * it should be left alone until we're done here. This is 138 * necessary to avoid race conditions - e.g. in ptrace() - 139 * that might allow a local user to illicitly obtain elevated --- 113 unchanged lines hidden (view full) --- 253 NDFREE(ndp, NDF_ONLY_PNBUF); 254 vrele(ndp->ni_vp); 255 /* set new name to that of the interpreter */ 256 NDINIT(ndp, LOOKUP, LOCKLEAF | FOLLOW | SAVENAME, 257 UIO_SYSSPACE, imgp->interpreter_name, td); 258 goto interpret; 259 } 260 |
261 TAILQ_FOREACH(ep, &exec_list, next) 262 (*ep->function)(p); 263 |
|
247 /* 248 * Copy out strings (args and env) and initialize stack base 249 */ 250 stack_base = exec_copyout_strings(imgp); 251 p->p_vmspace->vm_minsaddr = (char *)stack_base; 252 253 /* 254 * If custom stack fixup routine present for this process --- 666 unchanged lines hidden (view full) --- 921 if (*es != execsw_arg) 922 *xs++ = *es; 923 *xs = NULL; 924 if (execsw) 925 free(execsw, M_TEMP); 926 execsw = newexecsw; 927 return 0; 928} | 264 /* 265 * Copy out strings (args and env) and initialize stack base 266 */ 267 stack_base = exec_copyout_strings(imgp); 268 p->p_vmspace->vm_minsaddr = (char *)stack_base; 269 270 /* 271 * If custom stack fixup routine present for this process --- 666 unchanged lines hidden (view full) --- 938 if (*es != execsw_arg) 939 *xs++ = *es; 940 *xs = NULL; 941 if (execsw) 942 free(execsw, M_TEMP); 943 execsw = newexecsw; 944 return 0; 945} |
946 947int 948at_exec(function) 949 execlist_fn function; 950{ 951 struct execlist *ep; 952 953#ifdef INVARIANTS 954 /* Be noisy if the programmer has lost track of things */ 955 if (rm_at_exec(function)) 956 printf("WARNING: exec callout entry (%p) already present\n", 957 function); 958#endif 959 ep = malloc(sizeof(*ep), M_ATEXEC, M_NOWAIT); 960 if (ep == NULL) 961 return (ENOMEM); 962 ep->function = function; 963 TAILQ_INSERT_TAIL(&exec_list, ep, next); 964 return (0); 965} 966 967/* 968 * Scan the exec callout list for the given item and remove it. 969 * Returns the number of items removed (0 or 1) 970 */ 971int 972rm_at_exec(function) 973 execlist_fn function; 974{ 975 struct execlist *ep; 976 977 TAILQ_FOREACH(ep, &exec_list, next) { 978 if (ep->function == function) { 979 TAILQ_REMOVE(&exec_list, ep, next); 980 free(ep, M_ATEXEC); 981 return(1); 982 } 983 } 984 return (0); 985} 986 |
|