Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/sys/kern Pull up revision 1.141 (requested by thorpej):



details:   https://anonhg.NetBSD.org/src/rev/a4e88a71f554
branches:  netbsd-1-5
changeset: 491904:a4e88a71f554
user:      he <he%NetBSD.org@localhost>
date:      Sat Jun 16 20:19:30 2001 +0000

description:
Pull up revision 1.141 (requested by thorpej):
  Close a race condition between exec of a setuid binary and
  ptrace(2): check P_TRACED right before adjusting the privilege
  settings in the exec code.

diffstat:

 sys/kern/kern_exec.c |  22 ++++++++++++++++------
 1 files changed, 16 insertions(+), 6 deletions(-)

diffs (51 lines):

diff -r ebebc2c72c50 -r a4e88a71f554 sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c      Sat Jun 16 20:19:07 2001 +0000
+++ b/sys/kern/kern_exec.c      Sat Jun 16 20:19:30 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_exec.c,v 1.110.4.4 2000/11/03 19:59:41 tv Exp $   */
+/*     $NetBSD: kern_exec.c,v 1.110.4.5 2001/06/16 20:19:30 he Exp $   */
 
 /*-
  * Copyright (C) 1993, 1994, 1996 Christopher G. Demetriou
@@ -123,7 +123,7 @@
                error = EACCES;
                goto bad1;
        }
-       if ((vp->v_mount->mnt_flag & MNT_NOSUID) || (p->p_flag & P_TRACED))
+       if (vp->v_mount->mnt_flag & MNT_NOSUID)
                epp->ep_vap->va_mode &= ~(S_ISUID | S_ISGID);
 
        /* try to open it */
@@ -492,10 +492,21 @@
 
        /*
         * deal with set[ug]id.
-        * MNT_NOSUID and P_TRACED have already been used to disable s[ug]id.
+        * MNT_NOSUID has already been used to disable s[ug]id.
         */
-       if (((attr.va_mode & S_ISUID) != 0 && p->p_ucred->cr_uid != attr.va_uid)
-        || ((attr.va_mode & S_ISGID) != 0 && p->p_ucred->cr_gid != attr.va_gid)){
+       if ((p->p_flag & P_TRACED) == 0 &&
+
+           (((attr.va_mode & S_ISUID) != 0 &&
+             p->p_ucred->cr_uid != attr.va_uid) ||
+
+            ((attr.va_mode & S_ISGID) != 0 &&
+             p->p_ucred->cr_gid != attr.va_gid))) {
+               /*
+                * Mark the process as SUGID before we do
+                * anything that might block.
+                */
+               p_sugid(p);
+
                p->p_ucred = crcopy(cred);
 #ifdef KTRACE
                /*
@@ -509,7 +520,6 @@
                        p->p_ucred->cr_uid = attr.va_uid;
                if (attr.va_mode & S_ISGID)
                        p->p_ucred->cr_gid = attr.va_gid;
-               p_sugid(p);
        } else
                p->p_flag &= ~P_SUGID;
        p->p_cred->p_svuid = p->p_ucred->cr_uid;



Home | Main Index | Thread Index | Old Index