[PATCH 1/2][Xenial SRU] vfs: add lookup_hash() helper

Seth Forshee seth.forshee at canonical.com
Thu Jan 26 13:33:42 UTC 2017


From: Miklos Szeredi <mszeredi at redhat.com>

BugLink: http://bugs.launchpad.net/bugs/1659417

Overlayfs needs lookup without inode_permission() and already has the name
hash (in form of dentry->d_name on overlayfs dentry).  It also doesn't
support filesystems with d_op->d_hash() so basically it only needs
the actual hashed lookup from lookup_one_len_unlocked()

So add a new helper that does unlocked lookup of a hashed name.

Signed-off-by: Miklos Szeredi <mszeredi at redhat.com>
(backported from commit 3c9fe8cdff1b889a059a30d22f130372f2b3885f)
Signed-off-by: Seth Forshee <seth.forshee at canonical.com>
---
 fs/namei.c            | 21 +++++++++++++++++++++
 include/linux/namei.h |  2 ++
 2 files changed, 23 insertions(+)

diff --git a/fs/namei.c b/fs/namei.c
index f251a018e79f..0587407fa003 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1537,6 +1537,27 @@ static struct dentry *__lookup_hash(struct qstr *name,
 	return lookup_real(base->d_inode, dentry, flags);
 }
 
+/**
+ * lookup_hash - lookup single pathname component on already hashed name
+ * @name:	name and hash to lookup
+ * @base:	base directory to lookup from
+ *
+ * The name must have been verified and hashed (see lookup_one_len()).  Using
+ * this after just full_name_hash() is unsafe.
+ *
+ * This function also doesn't check for search permission on base directory.
+ *
+ * Use lookup_one_len_unlocked() instead, unless you really know what you are
+ * doing.
+ *
+ * Do not hold i_mutex; this helper takes i_mutex if necessary.
+ */
+struct dentry *lookup_hash(struct qstr *name, struct dentry *base)
+{
+	return __lookup_hash(name, base, 0);
+}
+EXPORT_SYMBOL(lookup_hash);
+
 /*
  *  It's more convoluted than I'd like it to be, but... it's still fairly
  *  small and for now I'd prefer to have fast path as straight as possible.
diff --git a/include/linux/namei.h b/include/linux/namei.h
index d8c6334cd150..0a6a1ab47b38 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -77,6 +77,8 @@ extern struct dentry *kern_path_locked(const char *, struct path *);
 extern int kern_path_mountpoint(int, const char *, struct path *, unsigned int);
 
 extern struct dentry *lookup_one_len(const char *, struct dentry *, int);
+struct qstr;
+extern struct dentry *lookup_hash(struct qstr *, struct dentry *);
 
 extern int follow_down_one(struct path *);
 extern int follow_down(struct path *);
-- 
2.7.4





More information about the kernel-team mailing list