From owner-svn-src-all@FreeBSD.ORG Wed Jul 20 09:53:35 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B185C1065670; Wed, 20 Jul 2011 09:53:35 +0000 (UTC) (envelope-from jonathan@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 96E618FC14; Wed, 20 Jul 2011 09:53:35 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p6K9rZNd010698; Wed, 20 Jul 2011 09:53:35 GMT (envelope-from jonathan@svn.freebsd.org) Received: (from jonathan@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p6K9rZjh010695; Wed, 20 Jul 2011 09:53:35 GMT (envelope-from jonathan@svn.freebsd.org) Message-Id: <201107200953.p6K9rZjh010695@svn.freebsd.org> From: Jonathan Anderson Date: Wed, 20 Jul 2011 09:53:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r224225 - in head/sys: kern sys X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jul 2011 09:53:35 -0000 Author: jonathan Date: Wed Jul 20 09:53:35 2011 New Revision: 224225 URL: http://svn.freebsd.org/changeset/base/224225 Log: Export capability information via sysctls. When reporting on a capability, flag the fact that it is a capability, but also unwrap to report all of the usual information about the underlying file. Approved by: re (kib), mentor (rwatson) Sponsored by: Google Inc Modified: head/sys/kern/kern_descrip.c head/sys/sys/user.h Modified: head/sys/kern/kern_descrip.c ============================================================================== --- head/sys/kern/kern_descrip.c Wed Jul 20 05:59:28 2011 (r224224) +++ head/sys/kern/kern_descrip.c Wed Jul 20 09:53:35 2011 (r224225) @@ -2946,6 +2946,22 @@ sysctl_kern_proc_ofiledesc(SYSCTL_HANDLE so = NULL; tp = NULL; kif->kf_fd = i; + +#ifdef CAPABILITIES + /* + * When reporting a capability, most fields will be from the + * underlying object, but do mark as a capability. With + * ofiledesc, we don't have a field to export the cap_rights_t, + * but we do with the new filedesc. + */ + if (fp->f_type == DTYPE_CAPABILITY) { + kif->kf_flags |= KF_FLAG_CAPABILITY; + (void)cap_funwrap(fp, 0, &fp); + } +#else + KASSERT(fp->f_type != DTYPE_CAPABILITY, + ("sysctl_kern_proc_ofiledesc: saw capability")); +#endif switch (fp->f_type) { case DTYPE_VNODE: kif->kf_type = KF_TYPE_VNODE; @@ -3262,6 +3278,22 @@ sysctl_kern_proc_filedesc(SYSCTL_HANDLER if ((fp = fdp->fd_ofiles[i]) == NULL) continue; data = NULL; + +#ifdef CAPABILITIES + /* + * When reporting a capability, most fields will be from the + * underlying object, but do mark as a capability and export + * the capability rights mask. + */ + if (fp->f_type == DTYPE_CAPABILITY) { + kif->kf_flags |= KF_FLAG_CAPABILITY; + kif->kf_cap_rights = cap_rights(fp); + (void)cap_funwrap(fp, 0, &fp); + } +#else /* !CAPABILITIES */ + KASSERT(fp->f_type != DTYPE_CAPABILITY, + ("sysctl_kern_proc_filedesc: saw capability")); +#endif switch (fp->f_type) { case DTYPE_VNODE: type = KF_TYPE_VNODE; Modified: head/sys/sys/user.h ============================================================================== --- head/sys/sys/user.h Wed Jul 20 05:59:28 2011 (r224224) +++ head/sys/sys/user.h Wed Jul 20 09:53:35 2011 (r224225) @@ -251,6 +251,7 @@ struct user { #define KF_TYPE_SHM 8 #define KF_TYPE_SEM 9 #define KF_TYPE_PTS 10 +/* no KF_TYPE_CAPABILITY (11), since capabilities wrap other file objects */ #define KF_TYPE_UNKNOWN 255 #define KF_VTYPE_VNON 0 @@ -286,6 +287,7 @@ struct user { #define KF_FLAG_TRUNC 0x00001000 #define KF_FLAG_EXCL 0x00002000 #define KF_FLAG_EXEC 0x00004000 +#define KF_FLAG_CAPABILITY 0x00008000 /* * Old format. Has variable hidden padding due to alignment. @@ -378,7 +380,9 @@ struct kinfo_file { } kf_un; uint16_t kf_status; /* Status flags. */ uint16_t kf_pad1; /* Round to 32 bit alignment. */ - int _kf_ispare[7]; /* Space for more stuff. */ + int _kf_ispare0; /* Space for more stuff. */ + cap_rights_t kf_cap_rights; /* Capability rights. */ + int _kf_ispare[4]; /* Space for more stuff. */ /* Truncated before copyout in sysctl */ char kf_path[PATH_MAX]; /* Path to file, if any. */ };