From owner-p4-projects@FreeBSD.ORG Sat Jun 6 22:41:43 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 3FB2E106566C; Sat, 6 Jun 2009 22:41:43 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F3FDE106564A for ; Sat, 6 Jun 2009 22:41:42 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id C634D8FC08 for ; Sat, 6 Jun 2009 22:41:42 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n56MfgEV082588 for ; Sat, 6 Jun 2009 22:41:42 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n56MfgNH082586 for perforce@freebsd.org; Sat, 6 Jun 2009 22:41:42 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Sat, 6 Jun 2009 22:41:42 GMT Message-Id: <200906062241.n56MfgNH082586@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Cc: Subject: PERFORCE change 163674 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Jun 2009 22:41:44 -0000 http://perforce.freebsd.org/chv.cgi?CH=163674 Change 163674 by rwatson@rwatson_freebsd_capabilities on 2009/06/06 22:40:45 Complete merge of new file descriptor referencing and locking into the capabilities version of _fget(). Improve ifdefing. Affected files ... .. //depot/projects/trustedbsd/capabilities/src/sys/kern/kern_descrip.c#23 edit Differences ... ==== //depot/projects/trustedbsd/capabilities/src/sys/kern/kern_descrip.c#23 (text+ko) ==== @@ -2155,7 +2155,10 @@ { struct filedesc *fdp; struct file *fp; +#ifdef CAPABILITIES + struct file *fp_fromcap; int error; +#endif /* * Validate the file descriptor number and find the struct file. @@ -2170,6 +2173,7 @@ return (EBADF); } +#ifdef CAPABILITIES /* * If a capability has been requested, return the capability * directly. Otherwise, check capability rights, extract the @@ -2177,30 +2181,40 @@ */ if (fget_flags & FGET_GETCAP) { if (fp->f_type != DTYPE_CAPABILITY) { - FILEDESC_SUNLOCK(fdp); + fdrop(fp, td); return (EINVAL); } } else { /* * If a capability hasn't been requested, then validate the - * capability and find the underlying object. From now on - * 'fp' refers to the actual object of interest. + * capability and find the underlying object. */ if (maxprotp != NULL) - error = cap_fextract_mmap(fp, rights, maxprotp, &fp); + error = cap_fextract_mmap(fp, rights, maxprotp, + &fp_fromcap); else - error = cap_fextract(fp, rights, &fp); + error = cap_fextract(fp, rights, &fp_fromcap); if (error) { - FILEDESC_SUNLOCK(fdp); + fdrop(fp, td); return (error); } + /* + * Hold the new file descriptor and drop the capability file + * descriptor; after this point fp refers to the new object. + */ + fhold(fp_fromcap); + fdrop(fp, td); + fp = fp_fromcap; +#endif if ((flags == FREAD && (fp->f_flag & FREAD) == 0) || (flags == FWRITE && (fp->f_flag & FWRITE) == 0)) { fdrop(fp, td); return (EBADF); } +#ifdef CAPABILITIES } +#endif *fpp = fp; return (0); } @@ -2224,7 +2238,7 @@ fget_read(struct thread *td, int fd, cap_rights_t rights, struct file **fpp) { - return(_fget(td, fd, fpp, FWRITE, rights, NULL, 0)); + return(_fget(td, fd, fpp, FREAD, rights, NULL, 0)); } int