Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2364560imm; Tue, 10 Jul 2018 19:23:17 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcxGBq2s2gtnLRtQBFkCgdwlGwiIf9ouUwWvUt0GeWtkVrlQ8GKnWPGkGtFCZ4H5WtesIzv X-Received: by 2002:a63:c252:: with SMTP id l18-v6mr24790136pgg.76.1531275796936; Tue, 10 Jul 2018 19:23:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531275796; cv=none; d=google.com; s=arc-20160816; b=dRwn5xuTnwAC+1DyCfQ3H+aA3GnW0kJEnMCzXs9HeLeHP+/oFc/4hsG9mVQMy+AKI2 k+BcAc+D/UUx9u6cIg3liFyIi+FIKI5rRO9aLZ/DshwrtumsFzxgKceZFTIpIbeF4Jmd 2xjaO6vxxVrTdEmkVb+4dT8bu/FfrQdpFey+Xw8Z6DnW/IaARBtaEiDHrqH1b0x5Swo6 l+6kcZnX1KeJ+YYz7PBJhgVXg0mv5oUH/s4eDPUBAyW5V60oYeTVWPLFFD8Kjf0oxEc2 aeHQLgZmXDTfbDy91bLvMhB1EjgiP4J8teCo75xkPQm58mlZWYqHuT0RXt3gFyMsdYK7 S9xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=E0ZcKZ+yhdm10Mo3mlSZiMu4R+3C1lKr+QKLrati584=; b=xyNAj+pZ4AbHwNl7BvSYJzfsRNqfmDPA24sOZ4LvC6i7OicdjjU1Hpocjz4q1DCb3t W91UYrGHGV9DehJLLkYz3W408XChUbUAAhsb3UTDutTNeluwk26DvQ/Dd0+So2QJXdrc Tkr2tmqIMzQelxsKKULofHSt3/oclvIadG5f8Vn8cy2krIE9hNR6DuMqksjQsqGFKTFI iJaeVAK8EqPVXu0EglqVmPkNwp3NHUKKX0zHH9EcYVIPqB+AfqiIUgNujW6o4ceCfnty +f8rFtPaZa+E54xWLKcXa3+t83UktUuX6RCtntFWs+agVIHJvqdVKjD22bJ0PwVK9Fgp Tl6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 38-v6si17856651pgz.286.2018.07.10.19.23.01; Tue, 10 Jul 2018 19:23:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732693AbeGKCYO (ORCPT + 99 others); Tue, 10 Jul 2018 22:24:14 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:45726 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732600AbeGKCYJ (ORCPT ); Tue, 10 Jul 2018 22:24:09 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1fd4lf-0003Lx-Id; Wed, 11 Jul 2018 02:22:11 +0000 From: Al Viro To: Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Miklos Szeredi Subject: [RFC][PATCH 40/42] make path_init() unconditionally paired with terminate_walk() Date: Wed, 11 Jul 2018 03:22:04 +0100 Message-Id: <20180711022206.12571-40-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180711022206.12571-1-viro@ZenIV.linux.org.uk> References: <20180711021136.GN30522@ZenIV.linux.org.uk> <20180711022206.12571-1-viro@ZenIV.linux.org.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro including the failure exits Signed-off-by: Al Viro --- fs/namei.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index ca3f4dec8cda..a9a2a8ac8b9d 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2125,12 +2125,15 @@ static int link_path_walk(const char *name, struct nameidata *nd) } } +/* must be paired with terminate_walk() */ static const char *path_init(struct nameidata *nd, unsigned flags) { const char *s = nd->name->name; if (!*s) flags &= ~LOOKUP_RCU; + if (flags & LOOKUP_RCU) + rcu_read_lock(); nd->last_type = LAST_ROOT; /* if there are only slashes... */ nd->flags = flags | LOOKUP_JUMPED | LOOKUP_PARENT; @@ -2143,7 +2146,6 @@ static const char *path_init(struct nameidata *nd, unsigned flags) nd->path = nd->root; nd->inode = inode; if (flags & LOOKUP_RCU) { - rcu_read_lock(); nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq); nd->root_seq = nd->seq; nd->m_seq = read_seqbegin(&mount_lock); @@ -2159,21 +2161,15 @@ static const char *path_init(struct nameidata *nd, unsigned flags) nd->m_seq = read_seqbegin(&mount_lock); if (*s == '/') { - if (flags & LOOKUP_RCU) - rcu_read_lock(); set_root(nd); if (likely(!nd_jump_root(nd))) return s; - nd->root.mnt = NULL; - rcu_read_unlock(); return ERR_PTR(-ECHILD); } else if (nd->dfd == AT_FDCWD) { if (flags & LOOKUP_RCU) { struct fs_struct *fs = current->fs; unsigned seq; - rcu_read_lock(); - do { seq = read_seqcount_begin(&fs->seq); nd->path = fs->pwd; @@ -2195,16 +2191,13 @@ static const char *path_init(struct nameidata *nd, unsigned flags) dentry = f.file->f_path.dentry; - if (*s) { - if (!d_can_lookup(dentry)) { - fdput(f); - return ERR_PTR(-ENOTDIR); - } + if (*s && unlikely(!d_can_lookup(dentry))) { + fdput(f); + return ERR_PTR(-ENOTDIR); } nd->path = f.file->f_path; if (flags & LOOKUP_RCU) { - rcu_read_lock(); nd->inode = nd->path.dentry->d_inode; nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq); } else { @@ -2272,8 +2265,10 @@ static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path const char *s = path_init(nd, flags); int err; - if (IS_ERR(s)) + if (IS_ERR(s)) { + terminate_walk(nd); return PTR_ERR(s); + } if (unlikely(flags & LOOKUP_DOWN)) { err = handle_lookup_down(nd); @@ -2337,8 +2332,10 @@ static int path_parentat(struct nameidata *nd, unsigned flags, { const char *s = path_init(nd, flags); int err; - if (IS_ERR(s)) + if (IS_ERR(s)) { + terminate_walk(nd); return PTR_ERR(s); + } err = link_path_walk(s, nd); if (!err) err = complete_walk(nd); @@ -2666,8 +2663,10 @@ path_mountpoint(struct nameidata *nd, unsigned flags, struct path *path) { const char *s = path_init(nd, flags); int err; - if (IS_ERR(s)) + if (IS_ERR(s)) { + terminate_walk(nd); return PTR_ERR(s); + } while (!(err = link_path_walk(s, nd)) && (err = mountpoint_last(nd)) > 0) { s = trailing_symlink(nd); @@ -3514,6 +3513,7 @@ static struct file *path_openat(struct nameidata *nd, s = path_init(nd, flags); if (IS_ERR(s)) { + terminate_walk(nd); fput(file); return ERR_CAST(s); } -- 2.11.0