From patchwork Thu Mar 5 05:21:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 5943571 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2C2D7BF440 for ; Thu, 5 Mar 2015 05:24:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4C15A202BE for ; Thu, 5 Mar 2015 05:24:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4C25C202B8 for ; Thu, 5 Mar 2015 05:24:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753132AbbCEFWm (ORCPT ); Thu, 5 Mar 2015 00:22:42 -0500 Received: from cantor2.suse.de ([195.135.220.15]:42147 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753123AbbCEFWl (ORCPT ); Thu, 5 Mar 2015 00:22:41 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B08B2AC82; Thu, 5 Mar 2015 05:22:39 +0000 (UTC) From: NeilBrown To: Alexander Viro Date: Thu, 05 Mar 2015 16:21:21 +1100 Subject: [PATCH 2/9] VFS/namei: use terminate_walk when symlink lookup fails. Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <20150305052121.23906.81777.stgit@notabene.brown> In-Reply-To: <20150305051530.23906.65097.stgit@notabene.brown> References: <20150305051530.23906.65097.stgit@notabene.brown> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently following a symlink never uses rcu-walk, so terminate_walk isn't needed. That will change in a future patch. In preparation, change some path_put_condtional() path_put() sequences to path_to_nameidata() terminate_walk() These sequence are identical when in ref-walk, and correct when in rcu-walk. Also change two path_put() calls to equivalent terminate_walk(). Signed-off-by: NeilBrown --- fs/namei.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/namei.c b/fs/namei.c index de508a3cec42..515adc4594be 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -726,6 +726,18 @@ char *nd_get_link(struct nameidata *nd) } EXPORT_SYMBOL(nd_get_link); +static void terminate_walk(struct nameidata *nd) +{ + if (!(nd->flags & LOOKUP_RCU)) { + path_put(&nd->path); + } else { + nd->flags &= ~LOOKUP_RCU; + if (!(nd->flags & LOOKUP_ROOT)) + nd->root.mnt = NULL; + rcu_read_unlock(); + } +} + static inline void put_link(struct nameidata *nd, struct path *link, void *cookie) { struct inode *inode = link->dentry->d_inode; @@ -776,8 +788,8 @@ static inline int may_follow_link(struct path *link, struct nameidata *nd) return 0; audit_log_link_denied("follow_link", link); - path_put_conditional(link, nd); - path_put(&nd->path); + path_to_nameidata(link, nd); + terminate_walk(nd); return -EACCES; } @@ -886,7 +898,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p) s = nd_get_link(nd); if (s) { if (unlikely(IS_ERR(s))) { - path_put(&nd->path); + terminate_walk(nd); put_link(nd, link, *p); return PTR_ERR(s); } @@ -908,7 +920,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p) out_put_nd_path: *p = NULL; - path_put(&nd->path); + terminate_walk(nd); path_put(link); return error; } @@ -1539,18 +1551,6 @@ static inline int handle_dots(struct nameidata *nd, int type) return 0; } -static void terminate_walk(struct nameidata *nd) -{ - if (!(nd->flags & LOOKUP_RCU)) { - path_put(&nd->path); - } else { - nd->flags &= ~LOOKUP_RCU; - if (!(nd->flags & LOOKUP_ROOT)) - nd->root.mnt = NULL; - rcu_read_unlock(); - } -} - /* * Do we need to follow links? We _really_ want to be able * to do this check without having to look at inode->i_op, @@ -1622,8 +1622,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd) int res; if (unlikely(current->link_count >= MAX_NESTED_LINKS)) { - path_put_conditional(path, nd); - path_put(&nd->path); + path_to_nameidata(path, nd); + terminate_walk(nd); return -ELOOP; } BUG_ON(nd->depth >= MAX_NESTED_LINKS); @@ -3238,8 +3238,8 @@ static struct file *path_openat(int dfd, struct filename *pathname, struct path link = path; void *cookie; if (!(nd->flags & LOOKUP_FOLLOW)) { - path_put_conditional(&path, nd); - path_put(&nd->path); + path_to_nameidata(&path, nd); + terminate_walk(nd); error = -ELOOP; break; }