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/dcache.c | 6 +++---
13
fs/namespace.c | 27 +++++++++++++++++++++++++++
14
include/linux/dcache.h | 2 ++
15
include/linux/mount.h | 2 ++
16
4 files changed, 34 insertions(+), 3 deletions(-)
20
@@ -1782,9 +1782,9 @@ shouldnt_be_hashed:
22
* Returns the buffer or an error code.
24
-static char *__d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
25
- struct dentry *root, struct vfsmount *rootmnt,
26
- char *buffer, int buflen, int fail_deleted)
27
+char *__d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
28
+ struct dentry *root, struct vfsmount *rootmnt,
29
+ char *buffer, int buflen, int fail_deleted)
31
int namelen, is_slash, vfsmount_locked = 0;
35
@@ -1883,3 +1883,30 @@ void __put_mnt_ns(struct mnt_namespace *
36
release_mounts(&umount_list);
40
+char *d_namespace_path(struct dentry *dentry, struct vfsmount *vfsmnt,
41
+ char *buf, int buflen)
43
+ struct vfsmount *rootmnt, *nsrootmnt = NULL;
44
+ struct dentry *root = NULL;
47
+ read_lock(¤t->fs->lock);
48
+ rootmnt = mntget(current->fs->rootmnt);
49
+ read_unlock(¤t->fs->lock);
50
+ spin_lock(&vfsmount_lock);
51
+ if (rootmnt->mnt_ns)
52
+ nsrootmnt = mntget(rootmnt->mnt_ns->root);
53
+ spin_unlock(&vfsmount_lock);
56
+ root = dget(nsrootmnt->mnt_root);
57
+ res = __d_path(dentry, vfsmnt, root, nsrootmnt, buf, buflen, 1);
60
+ /* Prevent empty path for lazily unmounted filesystems. */
61
+ if (!IS_ERR(res) && *res == '\0')
65
+EXPORT_SYMBOL(d_namespace_path);
66
--- a/include/linux/dcache.h
67
+++ b/include/linux/dcache.h
68
@@ -300,6 +300,8 @@ extern int d_validate(struct dentry *, s
70
extern char *dynamic_dname(struct dentry *, char *, int, const char *, ...);
72
+extern char *__d_path(struct dentry *, struct vfsmount *, struct dentry *,
73
+ struct vfsmount *, char *, int, int);
74
extern char * d_path(struct dentry *, struct vfsmount *, char *, int);
76
/* Allocation counts.. */
77
--- a/include/linux/mount.h
78
+++ b/include/linux/mount.h
79
@@ -103,5 +103,7 @@ extern void shrink_submounts(struct vfsm
80
extern spinlock_t vfsmount_lock;
81
extern dev_t name_to_dev_t(char *name);
83
+extern char *d_namespace_path(struct dentry *, struct vfsmount *, char *, int);
86
#endif /* _LINUX_MOUNT_H */