From owner-svn-src-head@FreeBSD.ORG Tue Jul 1 09:21:33 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7F80EA47; Tue, 1 Jul 2014 09:21:33 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5322B2942; Tue, 1 Jul 2014 09:21:33 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s619LXkP063078; Tue, 1 Jul 2014 09:21:33 GMT (envelope-from mjg@svn.freebsd.org) Received: (from mjg@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s619LXHL063077; Tue, 1 Jul 2014 09:21:33 GMT (envelope-from mjg@svn.freebsd.org) Message-Id: <201407010921.s619LXHL063077@svn.freebsd.org> From: Mateusz Guzik Date: Tue, 1 Jul 2014 09:21:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r268087 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Jul 2014 09:21:33 -0000 Author: mjg Date: Tue Jul 1 09:21:32 2014 New Revision: 268087 URL: http://svnweb.freebsd.org/changeset/base/268087 Log: Don't call crcopysafe or uifind unnecessarily in execve. MFC after: 1 week Modified: head/sys/kern/kern_exec.c Modified: head/sys/kern/kern_exec.c ============================================================================== --- head/sys/kern/kern_exec.c Tue Jul 1 08:36:56 2014 (r268086) +++ head/sys/kern/kern_exec.c Tue Jul 1 09:21:32 2014 (r268087) @@ -336,7 +336,7 @@ do_execve(td, args, mac_p) struct proc *p = td->td_proc; struct nameidata nd; struct ucred *newcred = NULL, *oldcred; - struct uidinfo *euip; + struct uidinfo *euip = NULL; register_t *stack_base; int error, i; struct image_params image_params, *imgp; @@ -601,8 +601,6 @@ interpret: /* * Malloc things before we need locks. */ - newcred = crget(); - euip = uifind(attr.va_uid); i = imgp->args->begin_envv - imgp->args->begin_argv; /* Cache arguments if they fit inside our allowance */ if (ps_arg_cache_limit >= i + sizeof(struct pargs)) { @@ -631,7 +629,7 @@ interpret: PROC_LOCK(p); if (oldsigacts) p->p_sigacts = newsigacts; - oldcred = crcopysafe(p, newcred); + oldcred = p->p_ucred; /* Stop profiling */ stopprofclock(p); @@ -721,6 +719,8 @@ interpret: vn_lock(imgp->vp, LK_SHARED | LK_RETRY); if (error != 0) goto done1; + newcred = crdup(oldcred); + euip = uifind(attr.va_uid); PROC_LOCK(p); /* * Set the new credentials. @@ -745,7 +745,6 @@ interpret: change_svuid(newcred, newcred->cr_uid); change_svgid(newcred, newcred->cr_gid); p->p_ucred = newcred; - newcred = NULL; } else { if (oldcred->cr_uid == oldcred->cr_ruid && oldcred->cr_gid == oldcred->cr_rgid) @@ -764,10 +763,12 @@ interpret: */ if (oldcred->cr_svuid != oldcred->cr_uid || oldcred->cr_svgid != oldcred->cr_gid) { + PROC_UNLOCK(p); + newcred = crdup(oldcred); + PROC_LOCK(p); change_svuid(newcred, newcred->cr_uid); change_svgid(newcred, newcred->cr_gid); p->p_ucred = newcred; - newcred = NULL; } } @@ -844,11 +845,10 @@ done1: /* * Free any resources malloc'd earlier that we didn't use. */ - uifree(euip); - if (newcred == NULL) + if (euip != NULL) + uifree(euip); + if (newcred != NULL) crfree(oldcred); - else - crfree(newcred); VOP_UNLOCK(imgp->vp, 0); /*