From patchwork Mon May 11 18:07:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 6381411 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 4AA939F32B for ; Mon, 11 May 2015 18:25:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5C43920601 for ; Mon, 11 May 2015 18:25:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 643F5201CD for ; Mon, 11 May 2015 18:25:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755454AbbEKSY1 (ORCPT ); Mon, 11 May 2015 14:24:27 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:47347 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754997AbbEKSIY (ORCPT ); Mon, 11 May 2015 14:08:24 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.76 #1 (Red Hat Linux)) id 1Yrs7q-0001TS-PZ; Mon, 11 May 2015 18:08:22 +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 071/110] namei: make should_follow_link() store the link in nd->link Date: Mon, 11 May 2015 19:07:31 +0100 Message-Id: <1431367690-5223-71-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 ... if it decides to follow, that is. Signed-off-by: Al Viro --- fs/namei.c | 62 +++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 1c9af925..1b4bc1b 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1566,15 +1566,31 @@ static void terminate_walk(struct nameidata *nd) put_link(nd); } +static int pick_link(struct nameidata *nd, struct path *link) +{ + if (nd->flags & LOOKUP_RCU) { + if (unlikely(nd->path.mnt != link->mnt || + unlazy_walk(nd, link->dentry))) { + return -ECHILD; + } + } + nd->link = *link; + return 1; +} + /* * Do we need to follow links? We _really_ want to be able * to do this check without having to look at inode->i_op, * so we keep a cache of "no, this doesn't need follow_link" * for the common case. */ -static inline int should_follow_link(struct dentry *dentry, int follow) +static inline int should_follow_link(struct nameidata *nd, struct path *link, int follow) { - return unlikely(d_is_symlink(dentry)) ? follow : 0; + if (likely(!d_is_symlink(link->dentry))) + return 0; + if (!follow) + return 0; + return pick_link(nd, link); } enum {WALK_GET = 1, WALK_PUT = 2}; @@ -1612,17 +1628,9 @@ static int walk_component(struct nameidata *nd, int flags) if (flags & WALK_PUT) put_link(nd); - if (should_follow_link(path.dentry, flags & WALK_GET)) { - if (nd->flags & LOOKUP_RCU) { - if (unlikely(nd->path.mnt != path.mnt || - unlazy_walk(nd, path.dentry))) { - return -ECHILD; - } - } - BUG_ON(inode != path.dentry->d_inode); - nd->link = path; - return 1; - } + err = should_follow_link(nd, &path, flags & WALK_GET); + if (unlikely(err)) + return err; path_to_nameidata(&path, nd); nd->inode = inode; return 0; @@ -2375,9 +2383,11 @@ done: put_link(nd); path->dentry = dentry; path->mnt = nd->path.mnt; - if (should_follow_link(dentry, nd->flags & LOOKUP_FOLLOW)) { - nd->link = *path; - return 1; + error = should_follow_link(nd, path, nd->flags & LOOKUP_FOLLOW); + if (unlikely(error)) { + if (error < 0) + goto out; + return error; } mntget(path->mnt); follow_mount(path); @@ -3095,19 +3105,13 @@ retry_lookup: goto out; } finish_lookup: - if (should_follow_link(path.dentry, nd->flags & LOOKUP_FOLLOW)) { - if (nd->flags & LOOKUP_RCU) { - if (unlikely(nd->path.mnt != path.mnt || - unlazy_walk(nd, path.dentry))) { - error = -ECHILD; - goto out; - } - } - BUG_ON(inode != path.dentry->d_inode); - if (nd->depth) - put_link(nd); - nd->link = path; - return 1; + if (nd->depth) + put_link(nd); + error = should_follow_link(nd, &path, nd->flags & LOOKUP_FOLLOW); + if (unlikely(error)) { + if (error < 0) + goto out; + return error; } if (unlikely(d_is_symlink(path.dentry)) && !(open_flag & O_PATH)) {