* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: kern_execve.c,v 1.13 1994/01/03 07:56:43 davidg Exp $
+ * $Id: kern_execve.c,v 1.19 1994/03/21 09:35:30 davidg Exp $
*/
#include "param.h"
char *stringbase, *stringp;
int *stack_base;
int error, resid, len, i;
-#if 0
- char image_header[256];
-#endif
struct image_params image_params, *iparams;
struct vnode *vnodep;
struct vattr attr;
if (error)
goto exec_fail_dealloc;
-#if 0
- /*
- * Read the image header from the file.
- */
- error = vn_rdwr(UIO_READ,
- vnodep,
- image_header,
- sizeof(image_header),
- 0,
- UIO_SYSSPACE, IO_NODELOCKED,
- p->p_ucred,
- &resid,
- p);
- if (error)
- goto exec_fail_dealloc;
-
- /* Clear out junk in image_header if a partial read (small file) */
- if (resid)
- bzero(image_header + (sizeof(image_header) - resid), resid);
-#endif
/*
* Map the image header (first page) of the file into
* kernel address space
*/
error = vm_mmap(kernel_map, /* map */
(vm_offset_t *)&image_header, /* address */
- NBPG, /* size */
+ PAGE_SIZE, /* size */
VM_PROT_READ, /* protection */
VM_PROT_READ, /* max protection */
MAP_FILE, /* flags */
(caddr_t)vnodep, /* vnode */
0); /* offset */
if (error) {
- printf("mmap failed: %d\n",error);
+ uprintf("mmap failed: %d\n",error);
goto exec_fail_dealloc;
}
iparams->image_header = image_header;
vput(ndp->ni_vp);
FREE(ndp->ni_pnbuf, M_NAMEI);
if (vm_deallocate(kernel_map,
- (vm_offset_t)image_header, NBPG))
+ (vm_offset_t)image_header, PAGE_SIZE))
panic("execve: header dealloc failed (1)");
/* set new name to that of the interpreter */
stack_base = exec_copyout_strings(iparams);
p->p_vmspace->vm_minsaddr = (char *)stack_base;
- p->p_vmspace->vm_ssize = (((caddr_t)USRSTACK - (char *)stack_base) >> PAGE_SHIFT) + 1;
-
/*
* Stuff argument count as first item on stack
*/
*(--stack_base) = iparams->argc;
- /* close files on exec, fixup signals */
+ /* close files on exec */
fdcloseexec(p);
+
+ /* reset caught signals */
execsigs(p);
/* name this process - nameiexec(p, ndp) */
}
/* implement set userid/groupid */
- if ((attr.va_mode&VSUID) && (p->p_flag & STRC) == 0) {
+ p->p_flag &= ~SUGID;
+
+ /*
+ * Turn off kernel tracing for set-id programs, except for
+ * root.
+ */
+ if (p->p_tracep && (attr.va_mode & (VSUID | VSGID)) &&
+ suser(p->p_ucred, &p->p_acflag)) {
+ p->p_traceflag = 0;
+ vrele(p->p_tracep);
+ p->p_tracep = 0;
+ }
+ if ((attr.va_mode & VSUID) && (p->p_flag & STRC) == 0) {
p->p_ucred = crcopy(p->p_ucred);
- p->p_cred->p_svuid = p->p_ucred->cr_uid = attr.va_uid;
+ p->p_ucred->cr_uid = attr.va_uid;
+ p->p_flag |= SUGID;
}
- if ((attr.va_mode&VSGID) && (p->p_flag & STRC) == 0) {
+ if ((attr.va_mode & VSGID) && (p->p_flag & STRC) == 0) {
p->p_ucred = crcopy(p->p_ucred);
- p->p_cred->p_svgid = p->p_ucred->cr_groups[0] = attr.va_gid;
+ p->p_ucred->cr_groups[0] = attr.va_gid;
+ p->p_flag |= SUGID;
}
+ /*
+ * Implement correct POSIX saved uid behavior.
+ */
+ p->p_cred->p_svuid = p->p_ucred->cr_uid;
+ p->p_cred->p_svgid = p->p_ucred->cr_gid;
+
/* mark vnode pure text */
ndp->ni_vp->v_flag |= VTEXT;
/*
* free various allocated resources
*/
- if (vm_deallocate(kernel_map, (vm_offset_t)iparams->stringbase,
- ARG_MAX))
+ if (vm_deallocate(kernel_map, (vm_offset_t)iparams->stringbase, ARG_MAX))
panic("execve: string buffer dealloc failed (1)");
- if (vm_deallocate(kernel_map, (vm_offset_t)image_header, NBPG))
+ if (vm_deallocate(kernel_map, (vm_offset_t)image_header, PAGE_SIZE))
panic("execve: header dealloc failed (2)");
vput(ndp->ni_vp);
FREE(ndp->ni_pnbuf, M_NAMEI);
panic("execve: string buffer dealloc failed (2)");
if (iparams->image_header && iparams->image_header != (char *)-1)
if (vm_deallocate(kernel_map,
- (vm_offset_t)iparams->image_header, NBPG))
+ (vm_offset_t)iparams->image_header, PAGE_SIZE))
panic("execve: header dealloc failed (3)");
vput(ndp->ni_vp);
FREE(ndp->ni_pnbuf, M_NAMEI);
/*
* Destroy old address space, and allocate a new stack
- * The new stack is only DFLSSIZ large because it is grown
+ * The new stack is only SGROWSIZ large because it is grown
* automatically in trap.c.
*/
int
{
int error;
struct vmspace *vmspace = iparams->proc->p_vmspace;
- caddr_t stack_addr = (caddr_t) (USRSTACK - DFLSSIZ);
+ caddr_t stack_addr = (caddr_t) (USRSTACK - SGROWSIZ);
iparams->vmspace_destroyed = 1;
/* Allocate a new stack */
error = vm_allocate(&vmspace->vm_map, (vm_offset_t *)&stack_addr,
- DFLSSIZ, FALSE);
+ SGROWSIZ, FALSE);
if (error)
return(error);
+ vmspace->vm_ssize = SGROWSIZ >> PAGE_SHIFT;
+
/* Initialize maximum stack address */
vmspace->vm_maxsaddr = (char *)USRSTACK - MAXSSIZ;