From patchwork Mon May 11 18:07:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 6381801 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 A74819F374 for ; Mon, 11 May 2015 18:32:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B6E1320A8F for ; Mon, 11 May 2015 18:32:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BA38220A81 for ; Mon, 11 May 2015 18:32:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932352AbbEKSaW (ORCPT ); Mon, 11 May 2015 14:30:22 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:47192 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754967AbbEKSIV (ORCPT ); Mon, 11 May 2015 14:08:21 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.76 #1 (Red Hat Linux)) id 1Yrs7m-0001RH-S4; Mon, 11 May 2015 18:08:18 +0000 From: Al Viro To: Linus Torvalds Cc: Neil Brown , Christoph Hellwig , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 050/110] namei: trim the arguments of get_link() Date: Mon, 11 May 2015 19:07:10 +0100 Message-Id: <1431367690-5223-50-git-send-email-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <20150511180650.GA4147@ZenIV.linux.org.uk> References: <20150511180650.GA4147@ZenIV.linux.org.uk> 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 From: Al Viro same story as the previous commit Signed-off-by: Al Viro --- fs/namei.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 1ac3217..e5715a5 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -843,27 +843,33 @@ static int may_linkat(struct path *link) return -EPERM; } -static __always_inline const char * -get_link(struct path *link, struct nameidata *nd, void **p) +static __always_inline +const char *get_link(struct nameidata *nd) { - struct dentry *dentry = link->dentry; + struct saved *last = nd->stack + nd->depth; + struct dentry *dentry = nd->link.dentry; struct inode *inode = dentry->d_inode; int error; const char *res; BUG_ON(nd->flags & LOOKUP_RCU); - if (link->mnt == nd->path.mnt) - mntget(link->mnt); + if (nd->link.mnt == nd->path.mnt) + mntget(nd->link.mnt); - res = ERR_PTR(-ELOOP); - if (unlikely(current->total_link_count >= 40)) - goto out; + if (unlikely(current->total_link_count >= 40)) { + path_put(&nd->path); + path_put(&nd->link); + return ERR_PTR(-ELOOP); + } + + last->link = nd->link; + last->cookie = NULL; cond_resched(); current->total_link_count++; - touch_atime(link); + touch_atime(&last->link); error = security_inode_follow_link(dentry); res = ERR_PTR(error); @@ -871,14 +877,13 @@ get_link(struct path *link, struct nameidata *nd, void **p) goto out; nd->last_type = LAST_BIND; - *p = NULL; res = inode->i_link; if (!res) { - res = inode->i_op->follow_link(dentry, p, nd); + res = inode->i_op->follow_link(dentry, &last->cookie, nd); if (IS_ERR(res)) { out: path_put(&nd->path); - path_put(link); + path_put(&last->link); } } return res; @@ -1717,7 +1722,6 @@ static inline u64 hash_name(const char *name) */ static int link_path_walk(const char *name, struct nameidata *nd) { - struct saved *last = nd->stack; int err; while (*name=='/') @@ -1795,16 +1799,13 @@ Walked: nd->depth++; current->link_count++; - last++; - last->link = nd->link; - s = get_link(&last->link, nd, &last->cookie); + s = get_link(nd); if (unlikely(IS_ERR(s))) { err = PTR_ERR(s); current->link_count--; nd->depth--; - last--; goto Err; } err = 0; @@ -1813,7 +1814,6 @@ Walked: put_link(nd); current->link_count--; nd->depth--; - last--; } else { if (*s == '/') { if (!nd->root.mnt) @@ -1826,7 +1826,7 @@ Walked: ; } nd->inode = nd->path.dentry->d_inode; - last->name = name; + nd->stack[nd->depth].name = name; if (!*s) goto OK; name = s; @@ -1844,17 +1844,15 @@ Err: put_link(nd); current->link_count--; nd->depth--; - last--; } return err; OK: if (unlikely(nd->depth)) { - name = last->name; + name = nd->stack[nd->depth].name; err = walk_component(nd, LOOKUP_FOLLOW); put_link(nd); current->link_count--; nd->depth--; - last--; goto Walked; } return 0; @@ -1979,8 +1977,7 @@ static int trailing_symlink(struct nameidata *nd) if (unlikely(error)) return error; nd->flags |= LOOKUP_PARENT; - nd->stack[0].link = nd->link; - s = get_link(&nd->stack[0].link, nd, &nd->stack[0].cookie); + s = get_link(nd); if (unlikely(IS_ERR(s))) return PTR_ERR(s); if (unlikely(!s))