summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_exec.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index 0b44d27d700..d62cd072bac 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_exec.c,v 1.48 2001/04/01 21:30:33 art Exp $ */
+/* $OpenBSD: kern_exec.c,v 1.49 2001/06/15 11:10:18 art Exp $ */
/* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */
/*-
@@ -133,6 +133,15 @@ check_exec(p, epp)
(p->p_flag & P_TRACED) || p->p_fd->fd_refcnt > 1)
epp->ep_vap->va_mode &= ~(VSUID | VSGID);
+ /*
+ * Set the P_SUID* flags early so that we won't be fiddled with when
+ * we sleep later in this code.
+ * XXX - this could give us a few false positives and the caller must
+ * make sure to save and restore the flags if exec fails.
+ */
+ if (epp->ep_vap->va_mode & (VSUID|VSGID))
+ p->p_flag |= P_SUGID|P_SUGIDEXEC;
+
/* check access. for root we have to see if any exec bit on */
if ((error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p)) != 0)
goto bad1;
@@ -244,6 +253,7 @@ sys_execve(p, v, retval)
char **tmpfap;
int szsigcode;
extern struct emul emul_native;
+ int saved_sugid;
/*
* figure out the maximum size of an exec header, if necessary.
@@ -274,6 +284,7 @@ sys_execve(p, v, retval)
pack.ep_emul = &emul_native;
pack.ep_flags = 0;
+ saved_sugid = p->p_flag & (P_SUGID|P_SUGIDEXEC);
/* see if we can run it. */
if ((error = check_exec(p, &pack)) != 0) {
goto freehdr;
@@ -646,6 +657,7 @@ bad:
freehdr:
free(pack.ep_hdr, M_EXEC);
+ p->p_flag = (p->p_flag & ~(P_SUGID|P_SUGIDEXEC)) | saved_sugid;
return (error);
exec_abort: