From owner-freebsd-current Mon Feb 11 19:45:40 2002 Delivered-To: freebsd-current@freebsd.org Received: from newman2.bestweb.net (newman2.bestweb.net [209.94.102.67]) by hub.freebsd.org (Postfix) with ESMTP id A1C2037B63D for ; Mon, 11 Feb 2002 18:18:57 -0800 (PST) Received: from okeeffe.bestweb.net (okeefe.bestweb.net [209.94.100.110]) by newman2.bestweb.net (Postfix) with ESMTP id 46621232BB; Mon, 11 Feb 2002 21:17:57 -0500 (EST) Received: by okeeffe.bestweb.net (Postfix, from userid 0) id E4CA99EFF0; Mon, 11 Feb 2002 21:12:38 -0500 (EST) Date: Mon, 11 Feb 2002 06:32:48 +1100 (EST) From: Bruce Evans To: Julian Elischer Cc: Subject: Re: final ucred patch Message-Id: <20020212021238.E4CA99EFF0@okeeffe.bestweb.net> Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > After comments by jhb and bde > > Index: i386/i386/trap.c > =================================================================== > RCS file: /home/ncvs/src/sys/i386/i386/trap.c,v > retrieving revision 1.211 > diff -u -r1.211 trap.c > --- i386/i386/trap.c 10 Jan 2002 11:49:54 -0000 1.211 > +++ i386/i386/trap.c 10 Feb 2002 00:52:58 -0000 > @@ -256,9 +256,19 @@ > sticks = td->td_kse->ke_sticks; > td->td_frame = &frame; > KASSERT(td->td_ucred == NULL, ("already have a ucred")); > - PROC_LOCK(p); > - td->td_ucred = crhold(p->p_ucred); > - PROC_UNLOCK(p); > + if (td->td_ucred != p->p_ucred) { > + if (td->td_ucred) { > + mtx_lock(&Giant); > + crfree(td->td_ucred); > + td->td_ucred = NULL; > + mtx_unlock(&Giant); See below about placement of this unlock. > + } > + if (p->p_ucred) { How can this be NULL? The old code didn't check. > + PROC_LOCK(p); > + td->td_ucred = crhold(p->p_ucred); > + PROC_UNLOCK(p); > + } > + } The inner block is large enough and repeated enough to turn into a function. > > switch (type) { > case T_PRIVINFLT: /* privileged instruction fault */ > @@ -644,10 +654,12 @@ > userret(td, &frame, sticks); > mtx_assert(&Giant, MA_NOTOWNED); > userout: > +#ifdef INVARIANTS > mtx_lock(&Giant); > crfree(td->td_ucred); > - mtx_unlock(&Giant); > td->td_ucred = NULL; > + mtx_unlock(&Giant); > +#endif > out: > return; > } I think moving the unlock is just an obfuscation. td_ucred isn't locked by Giant. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message