Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp630539imw; Mon, 4 Jul 2022 16:37:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tu1HEyu4DTTzezxNtulFm3/ehovYkmUkxrX7c4py1IEvYHCri++q6g4smOq9zKEZj4Ex/V X-Received: by 2002:a17:902:988e:b0:16b:7ba7:9262 with SMTP id s14-20020a170902988e00b0016b7ba79262mr37397378plp.3.1656977879168; Mon, 04 Jul 2022 16:37:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656977879; cv=none; d=google.com; s=arc-20160816; b=l3RGjQsLma0e6/MAryQUeNSGHplFMP5hsjJ6sAkrFRFI7+0NpmoUHDz5wnw0g1zDeG Duxd5WrHSRyFM9C+9mkofV9iWaz27rOg06RHVNJaIwEZzkH/xUBPclGJM9jWvPkPDtsF BTs+ur5/R4fnmsUbd4jZZV3ZvMuCNJ0frWmaveGkdgiVowa4l8qgqv4SPo64Groi8wbn ruypQpmsmZ28h7itw7pejJ3eeEkQhDW+Ndo6kS6cNNgazAVvN2sgNjRcEaMrVoSul3e3 +cdAh0h+bXjmw712ieYoh/aht2HhRwD9tbhryuXlxSb+XIC8tplT3CgH/pu4SBxKu4tW gcnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=NqVApc9I2DDH/ifQWSRH221HRDI5UWBJClZrnVtHcvg=; b=mi9Y5QsTTHGJyJWtmRhU5zj2sTZgvKWGv1QD9Gj2nrgUKZXITIBZZs0b1D3wb7xg92 7bVv3JzTV7LbIZ7Xm/2RKd7d1d5Q2Lcn5HFIMkDVLmSG8sMycnE5cWXPvuRmunvJs+uf gMYI3UhfsgcK/2QYKH0ZzEXbBGPuwShJ7KXWtCIt6P/vi0c2zfmywz3PT/sD2VApUwwF Wrkoghfm7zlm0gtqaClIt28XdgxQHy/MCGxOpgwKkiItXksbCxSpq9Nm+amw9zhWL3JB KMecxyvJYmoRjfv4KHLCBs8VvibE3mwwcYiNJQ/q4x1M96Fq22VKdgurnV+yUvYwruQF LgBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=XMq6en3D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h4-20020a170902f54400b00165bb998d85si17341932plf.619.2022.07.04.16.37.46; Mon, 04 Jul 2022 16:37:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=XMq6en3D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229842AbiGDXSI (ORCPT + 99 others); Mon, 4 Jul 2022 19:18:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234081AbiGDXRm (ORCPT ); Mon, 4 Jul 2022 19:17:42 -0400 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DB0B10577; Mon, 4 Jul 2022 16:17:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=NqVApc9I2DDH/ifQWSRH221HRDI5UWBJClZrnVtHcvg=; b=XMq6en3D1K42NPJrNPt3lNiGHU 6m4VZEYHJsKw2KJ8FEER0qK8oNGCVOWcuDgjwh8WQDSnCv3uQR6L+1i3enPxKWoWnbVOH3z6CEie3 nAp9cJJDd2p+yBlssUPpEpXlwKJbc2p27ShaRo5hao7QkcNFe3prUfJ6W5u0gQWZQnbKrS5pR1Tdf egeY54C3ZyVr7W9Zdixd+0O1ckAB19QGVGrBNLoZWZcqmBVvuhjabPDBCUO+bxM+6STEGYDHx9FyS toKCReTROXqjfeOSHKWpf/dSfOftFLkoYOpfUHq4w3tP7uXrpyQGmCSK5nAd/yJzARh/75JRzMNP4 bDBFQeCA==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.95 #2 (Red Hat Linux)) id 1o8VJP-008AcR-HB; Mon, 04 Jul 2022 23:17:03 +0000 Date: Tue, 5 Jul 2022 00:17:03 +0100 From: Al Viro To: Linus Torvalds Cc: Alexander Potapenko , Alexei Starovoitov , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Marco Elver , Mark Rutland , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , kasan-dev , Linux-MM , linux-arch , Linux Kernel Mailing List , Evgenii Stepanov , Nathan Chancellor , Nick Desaulniers , Segher Boessenkool , Vitaly Buka , linux-toolchains Subject: [PATCH 7/7] step_into(): move fetching ->d_inode past handle_mounts() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ... and lose messing with it in __follow_mount_rcu() Signed-off-by: Al Viro --- fs/namei.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index cdb61d09df79..f2c99e75b578 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1470,8 +1470,7 @@ EXPORT_SYMBOL(follow_down); * Try to skip to top of mountpoint pile in rcuwalk mode. Fail if * we meet a managed dentry that would need blocking. */ -static bool __follow_mount_rcu(struct nameidata *nd, struct path *path, - struct inode **inode) +static bool __follow_mount_rcu(struct nameidata *nd, struct path *path) { struct dentry *dentry = path->dentry; unsigned int flags = dentry->d_flags; @@ -1501,13 +1500,6 @@ static bool __follow_mount_rcu(struct nameidata *nd, struct path *path, dentry = path->dentry = mounted->mnt.mnt_root; nd->state |= ND_JUMPED; nd->next_seq = read_seqcount_begin(&dentry->d_seq); - *inode = dentry->d_inode; - /* - * We don't need to re-check ->d_seq after this - * ->d_inode read - there will be an RCU delay - * between mount hash removal and ->mnt_root - * becoming unpinned. - */ flags = dentry->d_flags; // makes sure that non-RCU pathwalk could reach // this state. @@ -1523,7 +1515,7 @@ static bool __follow_mount_rcu(struct nameidata *nd, struct path *path, } static inline int handle_mounts(struct nameidata *nd, struct dentry *dentry, - struct path *path, struct inode **inode) + struct path *path) { bool jumped; int ret; @@ -1532,12 +1524,7 @@ static inline int handle_mounts(struct nameidata *nd, struct dentry *dentry, path->dentry = dentry; if (nd->flags & LOOKUP_RCU) { unsigned int seq = nd->next_seq; - *inode = dentry->d_inode; - if (read_seqcount_retry(&dentry->d_seq, seq)) - return -ECHILD; - if (unlikely(!*inode)) - return -ENOENT; - if (likely(__follow_mount_rcu(nd, path, inode))) + if (likely(__follow_mount_rcu(nd, path))) return 0; // *path and nd->next_seq might've been clobbered path->mnt = nd->path.mnt; @@ -1557,8 +1544,6 @@ static inline int handle_mounts(struct nameidata *nd, struct dentry *dentry, dput(path->dentry); if (path->mnt != nd->path.mnt) mntput(path->mnt); - } else { - *inode = d_backing_inode(path->dentry); } return ret; } @@ -1839,15 +1824,21 @@ static const char *step_into(struct nameidata *nd, int flags, { struct path path; struct inode *inode; - int err = handle_mounts(nd, dentry, &path, &inode); + int err = handle_mounts(nd, dentry, &path); if (err < 0) return ERR_PTR(err); + inode = path.dentry->d_inode; if (likely(!d_is_symlink(path.dentry)) || ((flags & WALK_TRAILING) && !(nd->flags & LOOKUP_FOLLOW)) || (flags & WALK_NOFOLLOW)) { /* not a symlink or should not follow */ - if (!(nd->flags & LOOKUP_RCU)) { + if (nd->flags & LOOKUP_RCU) { + if (read_seqcount_retry(&path.dentry->d_seq, nd->next_seq)) + return ERR_PTR(-ECHILD); + if (unlikely(!inode)) + return ERR_PTR(-ENOENT); + } else { dput(nd->path.dentry); if (nd->path.mnt != path.mnt) mntput(nd->path.mnt); -- 2.30.2