From owner-svn-src-all@FreeBSD.ORG Sun Jun 21 13:41:32 2009 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 B8BFE106564A; Sun, 21 Jun 2009 13:41:32 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A398B8FC0A; Sun, 21 Jun 2009 13:41:32 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n5LDfWJn008290; Sun, 21 Jun 2009 13:41:32 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n5LDfWEx008281; Sun, 21 Jun 2009 13:41:32 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <200906211341.n5LDfWEx008281@svn.freebsd.org> From: Konstantin Belousov Date: Sun, 21 Jun 2009 13:41:32 +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: r194586 - in head/sys: cddl/compat/opensolaris/kern cddl/compat/opensolaris/sys cddl/contrib/opensolaris/uts/common/fs/zfs 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: Sun, 21 Jun 2009 13:41:33 -0000 Author: kib Date: Sun Jun 21 13:41:32 2009 New Revision: 194586 URL: http://svn.freebsd.org/changeset/base/194586 Log: Add another flags argument to vn_open_cred. Use it to specify that some vn_open_cred invocations shall not audit namei path. In particular, specify VN_OPEN_NOAUDIT for dotdot lookup performed by default implementation of vop_vptocnp, and for the open done for core file. vn_fullpath is called from the audit code, and vn_open there need to disable audit to avoid infinite recursion. Core file is created on return to user mode, that, in particular, happens during syscall return. The creation of the core file is audited by direct calls, and we do not want to overwrite audit information for syscall. Reported, reviewed and tested by: rwatson Modified: head/sys/cddl/compat/opensolaris/kern/opensolaris_kobj.c head/sys/cddl/compat/opensolaris/sys/vnode.h head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c head/sys/kern/kern_alq.c head/sys/kern/kern_sig.c head/sys/kern/vfs_default.c head/sys/kern/vfs_vnops.c head/sys/sys/vnode.h Modified: head/sys/cddl/compat/opensolaris/kern/opensolaris_kobj.c ============================================================================== --- head/sys/cddl/compat/opensolaris/kern/opensolaris_kobj.c Sun Jun 21 13:15:56 2009 (r194585) +++ head/sys/cddl/compat/opensolaris/kern/opensolaris_kobj.c Sun Jun 21 13:41:32 2009 (r194586) @@ -85,7 +85,8 @@ kobj_open_file_vnode(const char *file) flags = FREAD; NDINIT(&nd, LOOKUP, MPSAFE, UIO_SYSSPACE, file, td); - error = vn_open_cred(&nd, &flags, O_NOFOLLOW, curthread->td_ucred, NULL); + error = vn_open_cred(&nd, &flags, O_NOFOLLOW, 0, curthread->td_ucred, + NULL); NDFREE(&nd, NDF_ONLY_PNBUF); if (error != 0) return (NULL); Modified: head/sys/cddl/compat/opensolaris/sys/vnode.h ============================================================================== --- head/sys/cddl/compat/opensolaris/sys/vnode.h Sun Jun 21 13:15:56 2009 (r194585) +++ head/sys/cddl/compat/opensolaris/sys/vnode.h Sun Jun 21 13:41:32 2009 (r194586) @@ -182,7 +182,7 @@ vn_openat(char *pnamep, enum uio_seg seg vref(startvp); NDINIT_ATVP(&nd, operation, MPSAFE, UIO_SYSSPACE, pnamep, startvp, td); filemode |= O_NOFOLLOW; - error = vn_open_cred(&nd, &filemode, createmode, td->td_ucred, NULL); + error = vn_open_cred(&nd, &filemode, createmode, 0, td->td_ucred, NULL); NDFREE(&nd, NDF_ONLY_PNBUF); if (error == 0) { /* We just unlock so we hold a reference. */ Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c ============================================================================== --- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c Sun Jun 21 13:15:56 2009 (r194585) +++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c Sun Jun 21 13:41:32 2009 (r194586) @@ -4519,7 +4519,7 @@ vop_getextattr { flags = FREAD; NDINIT_ATVP(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, attrname, xvp, td); - error = vn_open_cred(&nd, &flags, 0, ap->a_cred, NULL); + error = vn_open_cred(&nd, &flags, 0, 0, ap->a_cred, NULL); vp = nd.ni_vp; NDFREE(&nd, NDF_ONLY_PNBUF); if (error != 0) { @@ -4640,7 +4640,7 @@ vop_setextattr { flags = FFLAGS(O_WRONLY | O_CREAT); NDINIT_ATVP(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, attrname, xvp, td); - error = vn_open_cred(&nd, &flags, 0600, ap->a_cred, NULL); + error = vn_open_cred(&nd, &flags, 0600, 0, ap->a_cred, NULL); vp = nd.ni_vp; NDFREE(&nd, NDF_ONLY_PNBUF); if (error != 0) { Modified: head/sys/kern/kern_alq.c ============================================================================== --- head/sys/kern/kern_alq.c Sun Jun 21 13:15:56 2009 (r194585) +++ head/sys/kern/kern_alq.c Sun Jun 21 13:41:32 2009 (r194586) @@ -351,7 +351,7 @@ alq_open(struct alq **alqp, const char * NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, file, td); flags = FWRITE | O_NOFOLLOW | O_CREAT; - error = vn_open_cred(&nd, &flags, cmode, cred, NULL); + error = vn_open_cred(&nd, &flags, cmode, 0, cred, NULL); if (error) return (error); Modified: head/sys/kern/kern_sig.c ============================================================================== --- head/sys/kern/kern_sig.c Sun Jun 21 13:15:56 2009 (r194585) +++ head/sys/kern/kern_sig.c Sun Jun 21 13:41:32 2009 (r194586) @@ -2940,7 +2940,8 @@ coredump(struct thread *td) restart: NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, name, td); flags = O_CREAT | FWRITE | O_NOFOLLOW; - error = vn_open(&nd, &flags, S_IRUSR | S_IWUSR, NULL); + error = vn_open_cred(&nd, &flags, S_IRUSR | S_IWUSR, VN_OPEN_NOAUDIT, + NULL, NULL); if (error) { #ifdef AUDIT audit_proc_coredump(td, name, error); Modified: head/sys/kern/vfs_default.c ============================================================================== --- head/sys/kern/vfs_default.c Sun Jun 21 13:15:56 2009 (r194585) +++ head/sys/kern/vfs_default.c Sun Jun 21 13:41:32 2009 (r194586) @@ -723,7 +723,7 @@ vop_stdvptocnp(struct vop_vptocnp_args * NDINIT_ATVP(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, "..", vp, td); flags = FREAD; - error = vn_open(&nd, &flags, 0, NULL); + error = vn_open_cred(&nd, &flags, 0, VN_OPEN_NOAUDIT, NULL, NULL); if (error) { vn_lock(vp, locked | LK_RETRY); return (error); Modified: head/sys/kern/vfs_vnops.c ============================================================================== --- head/sys/kern/vfs_vnops.c Sun Jun 21 13:15:56 2009 (r194585) +++ head/sys/kern/vfs_vnops.c Sun Jun 21 13:41:32 2009 (r194586) @@ -91,7 +91,7 @@ vn_open(ndp, flagp, cmode, fp) { struct thread *td = ndp->ni_cnd.cn_thread; - return (vn_open_cred(ndp, flagp, cmode, td->td_ucred, fp)); + return (vn_open_cred(ndp, flagp, cmode, 0, td->td_ucred, fp)); } /* @@ -102,11 +102,8 @@ vn_open(ndp, flagp, cmode, fp) * due to the NDINIT being done elsewhere. */ int -vn_open_cred(ndp, flagp, cmode, cred, fp) - struct nameidata *ndp; - int *flagp, cmode; - struct ucred *cred; - struct file *fp; +vn_open_cred(struct nameidata *ndp, int *flagp, int cmode, u_int vn_open_flags, + struct ucred *cred, struct file *fp) { struct vnode *vp; struct mount *mp; @@ -124,9 +121,11 @@ restart: if (fmode & O_CREAT) { ndp->ni_cnd.cn_nameiop = CREATE; ndp->ni_cnd.cn_flags = ISOPEN | LOCKPARENT | LOCKLEAF | - MPSAFE | AUDITVNODE1; + MPSAFE; if ((fmode & O_EXCL) == 0 && (fmode & O_NOFOLLOW) == 0) ndp->ni_cnd.cn_flags |= FOLLOW; + if (!(vn_open_flags & VN_OPEN_NOAUDIT)) + ndp->ni_cnd.cn_flags |= AUDITVNODE1; bwillwrite(); if ((error = namei(ndp)) != 0) return (error); @@ -181,9 +180,11 @@ restart: ndp->ni_cnd.cn_nameiop = LOOKUP; ndp->ni_cnd.cn_flags = ISOPEN | ((fmode & O_NOFOLLOW) ? NOFOLLOW : FOLLOW) | - LOCKLEAF | MPSAFE | AUDITVNODE1; + LOCKLEAF | MPSAFE; if (!(fmode & FWRITE)) ndp->ni_cnd.cn_flags |= LOCKSHARED; + if (!(vn_open_flags & VN_OPEN_NOAUDIT)) + ndp->ni_cnd.cn_flags |= AUDITVNODE1; if ((error = namei(ndp)) != 0) return (error); if (!mpsafe) Modified: head/sys/sys/vnode.h ============================================================================== --- head/sys/sys/vnode.h Sun Jun 21 13:15:56 2009 (r194585) +++ head/sys/sys/vnode.h Sun Jun 21 13:41:32 2009 (r194586) @@ -562,6 +562,9 @@ vn_canvmio(struct vnode *vp) */ #include "vnode_if.h" +/* vn_open_flags */ +#define VN_OPEN_NOAUDIT 0x00000001 + /* * Public vnode manipulation functions. */ @@ -637,7 +640,7 @@ int _vn_lock(struct vnode *vp, int flags #define vn_lock(vp, flags) _vn_lock(vp, flags, __FILE__, __LINE__) int vn_open(struct nameidata *ndp, int *flagp, int cmode, struct file *fp); int vn_open_cred(struct nameidata *ndp, int *flagp, int cmode, - struct ucred *cred, struct file *fp); + u_int vn_open_flags, struct ucred *cred, struct file *fp); int vn_pollrecord(struct vnode *vp, struct thread *p, int events); int vn_rdwr(enum uio_rw rw, struct vnode *vp, void *base, int len, off_t offset, enum uio_seg segflg, int ioflg,