From owner-p4-projects@FreeBSD.ORG Tue Nov 25 12:13:42 2003 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E9EF416A4D0; Tue, 25 Nov 2003 12:13:41 -0800 (PST) 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 BFDBE16A4CE for ; Tue, 25 Nov 2003 12:13:41 -0800 (PST) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7F59D43F75 for ; Tue, 25 Nov 2003 12:13:40 -0800 (PST) (envelope-from areisse@nailabs.com) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.9/8.12.9) with ESMTP id hAPKDeXJ025181 for ; Tue, 25 Nov 2003 12:13:40 -0800 (PST) (envelope-from areisse@nailabs.com) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.9/8.12.9/Submit) id hAPKDeoD025178 for perforce@freebsd.org; Tue, 25 Nov 2003 12:13:40 -0800 (PST) (envelope-from areisse@nailabs.com) Date: Tue, 25 Nov 2003 12:13:40 -0800 (PST) Message-Id: <200311252013.hAPKDeoD025178@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to areisse@nailabs.com using -f From: Andrew Reisse To: Perforce Change Reviews Subject: PERFORCE change 43042 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Nov 2003 20:13:42 -0000 http://perforce.freebsd.org/chv.cgi?CH=43042 Change 43042 by areisse@areisse_ibook on 2003/11/25 12:13:24 Alternate implementation of mac checks in hfs_readdirattr. Here, the file is displayed with the "do not enter" when mac denies access (the same behavior as dac denials). Affected files ... .. //depot/projects/trustedbsd/sedarwin/apsl/xnu/bsd/hfs/hfs_attrlist.c#3 edit Differences ... ==== //depot/projects/trustedbsd/sedarwin/apsl/xnu/bsd/hfs/hfs_attrlist.c#3 (text+ko) ==== @@ -779,6 +779,7 @@ /* * Get in memory cnode data (if any). */ + int mperm = 0; #ifdef MAC /* * XXXMAC: Try forcing the vnode into memory so that @@ -790,16 +791,8 @@ printf("hfs_readdirattr(): warning got %d\n", error); cp = hfs_chashget(dcp->c_dev, cattrp->ca_fileid, 0, &vp, &rvp); } else { - error = mac_check_vnode_stat(current_proc()->p_ucred, ap->a_cred, vp); - if (error) { -#if 0 - vput(vp); -#endif - printf("hfs_readdirattr(): FYI, failed with %d\n", error); -#if 0 - continue; -#endif - } + mperm = mac_check_vnode_stat(current_proc()->p_ucred, ap->a_cred, vp); + cp = vp->v_data; rvp = NULL; } @@ -824,6 +817,16 @@ } } } + struct cat_attr cattrtmp; + if (mperm) + { + bzero (&cattrtmp, sizeof (struct cat_attr)); + cattrtmp.ca_fileid = cattrp->ca_fileid; + cattrtmp.ca_mode = cattrp->ca_mode & ~07777; + cattrtmp.ca_nlink = 1; + cattrp = &cattrtmp; + } + *((u_long *)attrptr)++ = 0; /* move it past length */ attrblk.ab_attrlist = alist; attrblk.ab_attrbufpp = &attrptr; @@ -1048,6 +1051,19 @@ *abp->ab_varbufpp = varbufptr; } +#ifdef MAC +static int access_all (struct vnode *vp, struct proc *p) +{ + int r = VOP_ACCESS (vp, VREAD, p->p_ucred, p) || mac_check_vnode_access (p->p_ucred, vp, VREAD) ? 0 : R_OK; + if (!VOP_ACCESS (vp, VWRITE, p->p_ucred, p) && !mac_check_vnode_access (p->p_ucred, vp, VWRITE)) + r |= W_OK; + if (!VOP_ACCESS (vp, VEXEC, p->p_ucred, p) && !mac_check_vnode_access (p->p_ucred, vp, VEXEC)) + r |= X_OK; + + return r; +} +#endif + /* * Pack common volume attributes. */ @@ -1174,8 +1190,11 @@ } if (ATTR_CMN_USERACCESS & attr) { *((u_long *)attrbufptr)++ = - DerivePermissionSummary(cp->c_uid, cp->c_gid, cp->c_mode, - VTOVFS(vp), current_proc()->p_ucred, current_proc()); +#ifdef MAC + vp ? access_all (vp, current_proc()) : +#endif + DerivePermissionSummary(cp->c_uid, cp->c_gid, cp->c_mode, + VTOVFS(vp), current_proc()->p_ucred, current_proc()); } *abp->ab_attrbufpp = attrbufptr; @@ -1474,9 +1493,12 @@ } if (ATTR_CMN_USERACCESS & attr) { *((u_long *)attrbufptr)++ = - DerivePermissionSummary(cap->ca_uid, cap->ca_gid, - cap->ca_mode, mp, current_proc()->p_ucred, - current_proc()); +#ifdef MAC + vp ? access_all (vp, current_proc()) : +#endif + DerivePermissionSummary(cap->ca_uid, cap->ca_gid, + cap->ca_mode, mp, current_proc()->p_ucred, + current_proc()); } *abp->ab_attrbufpp = attrbufptr;