From owner-p4-projects Thu Aug 15 7:19:15 2002 Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id AE9D237B401; Thu, 15 Aug 2002 07:19:09 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 49C3D37B400 for ; Thu, 15 Aug 2002 07:19:09 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 06B0F43E4A for ; Thu, 15 Aug 2002 07:19:09 -0700 (PDT) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from freefall.freebsd.org (perforce@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g7FEJ8JU040508 for ; Thu, 15 Aug 2002 07:19:08 -0700 (PDT) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g7FEJ8Wd040505 for perforce@freebsd.org; Thu, 15 Aug 2002 07:19:08 -0700 (PDT) Date: Thu, 15 Aug 2002 07:19:08 -0700 (PDT) Message-Id: <200208151419.g7FEJ8Wd040505@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson Subject: PERFORCE change 16023 for review To: Perforce Change Reviews Sender: owner-p4-projects@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG http://people.freebsd.org/~peter/p4db/chv.cgi?CH=16023 Change 16023 by rwatson@rwatson_tislabs on 2002/08/15 07:18:49 Move the invocation of mac_cred_mmapped_drop_perms() to outside of the proc locking window during a process credential update, closing a race condition opened when mmap revocation was introduced. Otherwise, we were susceptible to check-check-change-change races that violated policy module invariants. The revocation now occurs after the atomic proc credential update prior to re-entering userland and the thread changing the credential re-gaining control. Affected files ... .. //depot/projects/trustedbsd/mac/sys/kern/kern_mac.c#242 edit Differences ... ==== //depot/projects/trustedbsd/mac/sys/kern/kern_mac.c#242 (text+ko) ==== @@ -2271,7 +2271,6 @@ { MAC_PERFORM(relabel_cred, cred, newlabel); - mac_cred_mmapped_drop_perms(curthread, cred); } void @@ -3003,8 +3002,6 @@ /* * MPSAFE - * - * XXX: Needs to be re-written for proc locking. */ int __mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap) @@ -3039,12 +3036,19 @@ setsugid(p); crcopy(newcred, oldcred); - PROC_UNLOCK(p); mac_relabel_cred(newcred, &intlabel); + p->p_ucred = newcred; - PROC_LOCK(p); - p->p_ucred = newcred; + /* + * Grab additional reference for use while revoking mmaps, prior + * to releasing the proc lock and sharing the cred. + */ + crhold(newcred); PROC_UNLOCK(p); + + mac_cred_mmapped_drop_perms(td, newcred); + + crfree(newcred); /* Free revocation reference. */ crfree(oldcred); mac_destroy_temp(&intlabel); return (0); To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message