2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-09-05 16:55:32 +00:00
Files
apparmor/kernel-patches/for-mainline/d_path_namespace_root.diff

75 lines
2.4 KiB
Diff
Raw Normal View History

Index: linux-2.6/fs/dcache.c
===================================================================
--- linux-2.6.orig/fs/dcache.c
+++ linux-2.6/fs/dcache.c
@@ -1741,10 +1741,12 @@ shouldnt_be_hashed:
* @buflen: buffer length
* @flags: flags indicating what should be in the path
*
- * Convert a dentry into an ASCII path name. If the entry has been deleted
- * and the DPATH_DELETED flag is set the string " (deleted)" is appended.
- * Note that this is ambiguous.
- *
+ * Convert a dentry into an ASCII path name.
+ * If the entry has been deleted and the DPATH_DELETED flag is set the
+ * string " (deleted)" is appended. Note that this is ambiguous.
+ * If the DPATH_NSROOT flag is set the path returned will walk past the
+ * chroot.
+ *
* Returns the buffer or an error code if the path was too long.
*
* "buflen" should be positive. Caller holds the dcache_lock.
@@ -1777,7 +1779,8 @@ static char * __d_path( struct dentry *d
for (;;) {
struct dentry * parent;
- if (dentry == root && vfsmnt == rootmnt)
+ if (!(flags & DPATH_NSROOT) &&
+ dentry == root && vfsmnt == rootmnt)
break;
if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
/* Global root? */
@@ -1823,18 +1826,22 @@ char * d_path_flags(struct dentry *dentr
char *buf, int buflen, unsigned int flags)
{
char *res;
- struct vfsmount *rootmnt;
- struct dentry *root;
+ struct vfsmount *rootmnt = NULL;
+ struct dentry *root = NULL;
- read_lock(&current->fs->lock);
- rootmnt = mntget(current->fs->rootmnt);
- root = dget(current->fs->root);
- read_unlock(&current->fs->lock);
+ if (!(flags & DPATH_NSROOT)) {
+ read_lock(&current->fs->lock);
+ rootmnt = mntget(current->fs->rootmnt);
+ root = dget(current->fs->root);
+ read_unlock(&current->fs->lock);
+ }
spin_lock(&dcache_lock);
res = __d_path(dentry, vfsmnt, root, rootmnt, buf, buflen, flags);
spin_unlock(&dcache_lock);
- dput(root);
- mntput(rootmnt);
+ if (!(flags & DPATH_NSROOT)) {
+ dput(root);
+ mntput(rootmnt);
+ }
return res;
}
Index: linux-2.6/include/linux/dcache.h
===================================================================
--- linux-2.6.orig/include/linux/dcache.h
+++ linux-2.6/include/linux/dcache.h
@@ -178,6 +178,7 @@ d_iput: no no no yes
/* d_path flags */
#define DPATH_DELETED 0x0001 /* append " (deleted)" */
+#define DPATH_NSROOT 0x0002 /* continue past fsroot (chroot) */
extern spinlock_t dcache_lock;