1 From: Andreas Gruenbacher <agruen@suse.de>
2 Subject: Add d_namespace_path() to compute namespace relative pathnames
4 In AppArmor, we are interested in pathnames relative to the namespace root.
5 This is the same as d_path() except for the root where the search ends. Add
6 a function for computing the namespace-relative path.
8 Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
9 Signed-off-by: John Johansen <jjohansen@suse.de>
12 fs/namespace.c | 30 ++++++++++++++++++++++++++++++
13 include/linux/mount.h | 2 ++
14 2 files changed, 32 insertions(+)
18 @@ -2357,3 +2357,33 @@ void put_mnt_ns(struct mnt_namespace *ns
21 EXPORT_SYMBOL(put_mnt_ns);
23 +char *d_namespace_path(struct dentry *dentry, struct vfsmount *vfsmnt,
24 + char *buf, int buflen)
26 + struct path root, tmp, ns_root = { };
27 + struct path path = { .mnt = vfsmnt, .dentry = dentry };
30 + read_lock(¤t->fs->lock);
31 + root = current->fs->root;
32 + path_get(¤t->fs->root);
33 + read_unlock(¤t->fs->lock);
34 + spin_lock(&vfsmount_lock);
36 + ns_root.mnt = mntget(root.mnt->mnt_ns->root);
38 + ns_root.dentry = dget(ns_root.mnt->mnt_root);
39 + spin_unlock(&vfsmount_lock);
41 + res = __d_path(&path, &tmp, buf, buflen,
42 + D_PATH_FAIL_DELETED | D_PATH_DISCONNECT);
46 + /* Prevent empty path for lazily unmounted filesystems. */
47 + if (!IS_ERR(res) && *res == '\0')
51 +EXPORT_SYMBOL(d_namespace_path);
52 --- a/include/linux/mount.h
53 +++ b/include/linux/mount.h
54 @@ -137,4 +137,6 @@ extern void mark_mounts_for_expiry(struc
55 extern spinlock_t vfsmount_lock;
56 extern dev_t name_to_dev_t(char *name);
58 +extern char *d_namespace_path(struct dentry *, struct vfsmount *, char *, int);
60 #endif /* _LINUX_MOUNT_H */