From patchwork Mon Mar 23 02:37:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 6068741 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1DAC09F2A9 for ; Mon, 23 Mar 2015 02:39:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 87ABE201FE for ; Mon, 23 Mar 2015 02:39:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6FE2C2021B for ; Mon, 23 Mar 2015 02:39:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752493AbbCWCjZ (ORCPT ); Sun, 22 Mar 2015 22:39:25 -0400 Received: from cantor2.suse.de ([195.135.220.15]:34515 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752066AbbCWCjW (ORCPT ); Sun, 22 Mar 2015 22:39:22 -0400 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 B44EBACF9; Mon, 23 Mar 2015 02:39:20 +0000 (UTC) From: NeilBrown To: Al Viro Date: Mon, 23 Mar 2015 13:37:40 +1100 Subject: [PATCH 14/20] VFS/namei: add 'inode' arg to put_link(). Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <20150323023740.8161.51849.stgit@notabene.brown> In-Reply-To: <20150323023258.8161.32467.stgit@notabene.brown> References: <20150323023258.8161.32467.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 When symlinks are followed in RCU-walk, dentry->d_inode may have changed between the call to ->follow_link and the call to ->put_link. So we need to preserve the inode used in the first instance, and use it to find the correct put_link. Note that this means that when RCU-walk is permitted in ->follow_link, dentry->d_inode cannot be used in ->put_link. Signed-off-by: NeilBrown --- Documentation/filesystems/porting | 4 ++++ fs/namei.c | 20 ++++++++++++-------- 2 files changed, 16 insertions(+), 8 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/Documentation/filesystems/porting b/Documentation/filesystems/porting index eba8dd0a13e3..09454610515c 100644 --- a/Documentation/filesystems/porting +++ b/Documentation/filesystems/porting @@ -490,3 +490,7 @@ in your dentry operations instead. The passed inode must be used rather than dentry->d_inode, particularly if LOOKUP_RCU is set. If s_fs_info is used, it must be freed using RCU. +-- +[mandatory] + If ->follow_link permits RCU-walk, then ->put_link must + not access dentry->d_inode as that may have changed. diff --git a/fs/namei.c b/fs/namei.c index 224b1495edae..72f5a4f91855 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -763,9 +763,9 @@ static void terminate_walk(struct nameidata *nd) } } -static inline void put_link(struct nameidata *nd, struct path *link, void *cookie) +static inline void put_link(struct nameidata *nd, struct path *link, + struct inode *inode, void *cookie) { - struct inode *inode = link->dentry->d_inode; if (inode->i_op->put_link) inode->i_op->put_link(link->dentry, nd_get_link(nd), cookie); if (!(nd->flags & LOOKUP_LINK_RCU)) @@ -934,7 +934,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p) if (s) { if (unlikely(IS_ERR(s))) { terminate_walk(nd); - put_link(nd, link, *p); + put_link(nd, link, inode, *p); return PTR_ERR(s); } if (*s == '/') { @@ -948,7 +948,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p) nd->inode = nd->path.dentry->d_inode; error = link_path_walk(s, nd); if (unlikely(error)) - put_link(nd, link, *p); + put_link(nd, link, inode, *p); } return error; @@ -1669,13 +1669,14 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd) do { struct path link = *path; + struct inode *inode = link.dentry->d_inode; void *cookie; res = follow_link(&link, nd, &cookie); if (res) break; res = walk_component(nd, path, LOOKUP_FOLLOW); - put_link(nd, &link, cookie); + put_link(nd, &link, inode, cookie); } while (res > 0); nd->link_count--; @@ -2036,6 +2037,7 @@ static int path_lookupat(int dfd, const char *name, while (err > 0) { void *cookie; struct path link = path; + struct inode *inode = link.dentry->d_inode; err = may_follow_link(&link, nd); if (unlikely(err)) break; @@ -2044,7 +2046,7 @@ static int path_lookupat(int dfd, const char *name, if (err) break; err = lookup_last(nd, &path); - put_link(nd, &link, cookie); + put_link(nd, &link, inode, cookie); } } @@ -2396,6 +2398,7 @@ path_mountpoint(int dfd, const char *name, struct path *path, unsigned int flags while (err > 0) { void *cookie; struct path link = *path; + struct inode *inode = link.dentry->d_inode; err = may_follow_link(&link, &nd); if (unlikely(err)) break; @@ -2404,7 +2407,7 @@ path_mountpoint(int dfd, const char *name, struct path *path, unsigned int flags if (err) break; err = mountpoint_last(&nd, path); - put_link(&nd, &link, cookie); + put_link(&nd, &link, inode, cookie); } out: path_cleanup(&nd); @@ -3281,6 +3284,7 @@ static struct file *path_openat(int dfd, struct filename *pathname, error = do_last(nd, &path, file, op, &opened, pathname); while (unlikely(error > 0)) { /* trailing symlink */ struct path link = path; + struct inode *inode = link.dentry->d_inode; void *cookie; if (!(nd->flags & LOOKUP_FOLLOW)) { path_to_nameidata(&path, nd); @@ -3297,7 +3301,7 @@ static struct file *path_openat(int dfd, struct filename *pathname, if (unlikely(error)) break; error = do_last(nd, &path, file, op, &opened, pathname); - put_link(nd, &link, cookie); + put_link(nd, &link, inode, cookie); } out: path_cleanup(nd);