Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757851AbXF0BEj (ORCPT ); Tue, 26 Jun 2007 21:04:39 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754005AbXF0BER (ORCPT ); Tue, 26 Jun 2007 21:04:17 -0400 Received: from ns2.suse.de ([195.135.220.15]:59843 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753962AbXF0BEP (ORCPT ); Tue, 26 Jun 2007 21:04:15 -0400 X-Mailbox-Line: From jjohansen@suse.de Tue Jun 26 17:32:31 2007 Message-Id: <20070627003231.051114488@suse.de> References: <20070626230756.519733902@suse.de> User-Agent: quilt/0.46-14 Date: Tue, 26 Jun 2007 17:32:22 -0700 From: jjohansen@suse.de To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andreas Gruenbacher , John Johansen Subject: [AppArmor 31/44] Add d_namespace_path() to compute namespace relative pathnames Content-Disposition: inline; filename=d_namespace_path.diff Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2991 Lines: 91 In AppArmor, we are interested in pathnames relative to the namespace root. This is the same as d_path() except for the root where the search ends. Add a function for computing the namespace-relative path. Signed-off-by: Andreas Gruenbacher Signed-off-by: John Johansen --- fs/dcache.c | 6 +++--- fs/namespace.c | 27 +++++++++++++++++++++++++++ include/linux/dcache.h | 2 ++ include/linux/mount.h | 2 ++ 4 files changed, 34 insertions(+), 3 deletions(-) --- a/fs/dcache.c +++ b/fs/dcache.c @@ -1779,9 +1779,9 @@ shouldnt_be_hashed: * * Returns the buffer or an error code. */ -static char *__d_path(struct dentry *dentry, struct vfsmount *vfsmnt, - struct dentry *root, struct vfsmount *rootmnt, - char *buffer, int buflen, int fail_deleted) +char *__d_path(struct dentry *dentry, struct vfsmount *vfsmnt, + struct dentry *root, struct vfsmount *rootmnt, + char *buffer, int buflen, int fail_deleted) { int namelen, is_slash, vfsmount_locked = 0; --- a/fs/namespace.c +++ b/fs/namespace.c @@ -1868,3 +1868,30 @@ void __put_mnt_ns(struct mnt_namespace * release_mounts(&umount_list); kfree(ns); } + +char *d_namespace_path(struct dentry *dentry, struct vfsmount *vfsmnt, + char *buf, int buflen) +{ + struct vfsmount *rootmnt, *nsrootmnt = NULL; + struct dentry *root = NULL; + char *res; + + read_lock(¤t->fs->lock); + rootmnt = mntget(current->fs->rootmnt); + read_unlock(¤t->fs->lock); + spin_lock(&vfsmount_lock); + if (rootmnt->mnt_ns) + nsrootmnt = mntget(rootmnt->mnt_ns->root); + spin_unlock(&vfsmount_lock); + mntput(rootmnt); + if (nsrootmnt) + root = dget(nsrootmnt->mnt_root); + res = __d_path(dentry, vfsmnt, root, nsrootmnt, buf, buflen, 1); + dput(root); + mntput(nsrootmnt); + /* Prevent empty path for lazily unmounted filesystems. */ + if (!IS_ERR(res) && *res == '\0') + *--res = '.'; + return res; +} +EXPORT_SYMBOL(d_namespace_path); --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -299,6 +299,8 @@ extern int d_validate(struct dentry *, s */ extern char *dynamic_dname(struct dentry *, char *, int, const char *, ...); +extern char *__d_path(struct dentry *, struct vfsmount *, struct dentry *, + struct vfsmount *, char *, int, int); extern char * d_path(struct dentry *, struct vfsmount *, char *, int); /* Allocation counts.. */ --- a/include/linux/mount.h +++ b/include/linux/mount.h @@ -103,5 +103,7 @@ extern void shrink_submounts(struct vfsm extern spinlock_t vfsmount_lock; extern dev_t name_to_dev_t(char *name); +extern char *d_namespace_path(struct dentry *, struct vfsmount *, char *, int); + #endif #endif /* _LINUX_MOUNT_H */ -- - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/