From patchwork Mon Jan 30 22:06:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 721739 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3vC3QG6y6Rz9sQw; Tue, 31 Jan 2017 09:06:46 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical-com.20150623.gappssmtp.com header.i=@canonical-com.20150623.gappssmtp.com header.b="rhf3+bX0"; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1cYK60-0004pk-Cd; Mon, 30 Jan 2017 22:06:44 +0000 Received: from mail-it0-f50.google.com ([209.85.214.50]) by huckleberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1cYK5n-0004nD-SK for kernel-team@lists.ubuntu.com; Mon, 30 Jan 2017 22:06:31 +0000 Received: by mail-it0-f50.google.com with SMTP id k200so24620582itb.1 for ; Mon, 30 Jan 2017 14:06:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=VBnP0UDw1bsonwEkyTgoaa3tbn/2c4NvNNt5BfxjVqA=; b=rhf3+bX0cEq1w4xw2hYdnTjjcsJG2741wG+Bv+pM4RadHSNyyH+xyTOuOQ+pM3fDim KF92yNhncA0CcFHB+uepI8RMnGpDQ8sAm9A7AcdkMRt0EYJPig8Vz63E8GCKXyn5bPfg 5MhJfLaBz5WweQTD4h3ze3RVzB1lIkDc+aCLumrNbIUdYz1Z+7nQuBVuo4n9FbTuHuBP PYQoqrOHM3aha2KoNUYE9gP7LpELfElXdIi1GjxvcO+FX1wLwRx5z4ltqwrzOK/8V9HP fJxiZTjYA5Wp96Ph1F8HyrFUAYVzFz1B6xKxH22i5bCENE0MqyECWv1Ybl+h3NLJTYRZ XbuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=VBnP0UDw1bsonwEkyTgoaa3tbn/2c4NvNNt5BfxjVqA=; b=k27MrMNhXAgL5BVMdR4yFTs+0mTv/+nxB0/JvC2m8XoU+cq2K7+8DQniUpSjsgvfdU U96RPwinKANBmG7Fkk7ueyDJLS4bGVHKd2CgQNA1frBAxdoNmkusx6Jz7QCH8AzoTUHA 7aJ78OjWUTr5zWNo5eb33Wif4CIxoHz6f2iS562aJuwcSjrV9ZYu8hdh/6ajcu6GbXz/ 8GR9pBICd6sO3IQBfRczdsHv+NQ9ihR6NgOWbUpN6FDEtVbvZGdZiBM7mZvM1psZxPe6 mb2eFPKTXTTfbQs2aqiL+x7Gl1zXjvvbIbmtR2wUgdJ+ajb+rcNEzJcNpuqg5gJUDY9F eE4g== X-Gm-Message-State: AIkVDXIZWBsVrcs4VblVQQAJzwpci+5r9D6GFb7HRivKIcKOvmpFEonHpoJK/x6VVQdZpTK2 X-Received: by 10.36.163.1 with SMTP id p1mr17061964ite.79.1485813990359; Mon, 30 Jan 2017 14:06:30 -0800 (PST) Received: from localhost ([2605:a601:aa7:8220:d525:2d8c:d0b4:d509]) by smtp.gmail.com with ESMTPSA id h69sm7091137ith.16.2017.01.30.14.06.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jan 2017 14:06:29 -0800 (PST) From: Seth Forshee To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 1/2][Xenial SRU] vfs: add lookup_hash() helper Date: Mon, 30 Jan 2017 16:06:25 -0600 Message-Id: <1485813986-58913-2-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1485813986-58913-1-git-send-email-seth.forshee@canonical.com> References: <1485813986-58913-1-git-send-email-seth.forshee@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com From: Miklos Szeredi 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 (backported from commit 3c9fe8cdff1b889a059a30d22f130372f2b3885f) Signed-off-by: Seth Forshee --- fs/namei.c | 26 ++++++++++++++++++++++++++ include/linux/namei.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/fs/namei.c b/fs/namei.c index f251a018e79f..773df05712d5 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1537,6 +1537,32 @@ 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) +{ + struct dentry *dentry; + + mutex_lock(&base->d_inode->i_mutex); + dentry = __lookup_hash(name, base, 0); + mutex_unlock(&base->d_inode->i_mutex); + return dentry; +} +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 *);