Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp615348imw; Mon, 4 Jul 2022 16:17:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tUSp23iqp9Wlm4YG11L+aYAjw54H+Fh4aiVRJ/Ksy5o9MoxFIx1EduFarwjuksq+uKPapN X-Received: by 2002:a17:90b:1d88:b0:1ec:d5f6:f141 with SMTP id pf8-20020a17090b1d8800b001ecd5f6f141mr41424816pjb.119.1656976654403; Mon, 04 Jul 2022 16:17:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656976654; cv=none; d=google.com; s=arc-20160816; b=d19JQRq+mfgRsHz+9Uptst4AlXDOfV19GqhfVQTo2zXkzwpBwd7OrtrTsM9MdlpH3q eij9ZVMJEaBxD+fdLK6Q7g2rZ0PIq+5DuVV55NfBCXZsG2ZNKW9dJzL0cJnovnUt+3yb D3ABNmui121Wya07KeP5rJ03GEH/ExSyXfSZCFLvZmc31obfbNGLG9ZcSCkFNQyCTEeP IcMApsd7l3wbRAUCKZ1OKxunG5wXClmODGaxB4Rzv9lDUkjeQB9V2F8cKLVrEqB8ghMQ r/sqkaOktwk7MuePG0sWimltYeBjz4+yqZ1UycuDIu+vmHeDOCwfyOmo6zCNJXl00yPS hPSw== 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=phosGs0ReDXhvjah48sBo0KCwl+d1jcc+HCEqeu58tc=; b=MMTT3M+tHdQaxUm/qrtNfnInboK0zNZz2mIXFRJhjzX30uSxFLGjwQGfV55/5xC5bh REt3lemihyKSJj33vznJbm34YH1DkZen/8LbCVxsI+NLsX4nXnpNDO8/OOQUdcaDUi1Y IZ3ZM0lwzZNVu5183KpItU6PIhnv2f77wtUEOupn7nx2byWdMC9tyPPy7g08SGybu0TF VazJlFFZKMXEK8l2WY//KX5chpQGfsY0MVt3Aogot/hGKihP474bY7PO7ZTSI5dALOFg tYDUQihkwPoCTlNQ4K/htDlnIw55tBopLxSxP/sZ93dLGcW2eQxeMJgXOv2vUCnMwWC5 JWwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=OwdNXG7l; 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 j184-20020a638bc1000000b0040c9216ce18si23515454pge.417.2022.07.04.16.17.22; Mon, 04 Jul 2022 16:17:34 -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=OwdNXG7l; 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 S233925AbiGDXQA (ORCPT + 99 others); Mon, 4 Jul 2022 19:16:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229842AbiGDXP5 (ORCPT ); Mon, 4 Jul 2022 19:15:57 -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 D0198EE2E; Mon, 4 Jul 2022 16:15:56 -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=phosGs0ReDXhvjah48sBo0KCwl+d1jcc+HCEqeu58tc=; b=OwdNXG7l7nBZtBBbjR/cEwIL4N J37eUfI1FdldQ2JpF8o2dJ2JHAuu3g5AX9ZcC1ukryfycNUEebrOsH9bjzn5Ms14CE5CNkbnEFGqs MYAVKAe6mUxmINf7gP+SuhmQ5NOKLLqGiIJPJwezFX+CUPngnBDRuMi5xYoptjm99AXdxw+ozX7dd RUdGasO87hSmy74nZJTIKnsrM8O5sp4QAVlELB8ReYdLKpNELFQf2zgYT8cv6WZMmQox9iK66Kq9n TgHphg+f7OxwqwIe3eA3NnlxLV5SbKhPv91SC5i4ZlWxYcAa8/WRiJWOWIk4fkjPr0mRjx2KC0bk9 25vU+zrg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.95 #2 (Red Hat Linux)) id 1o8VHc-008AYW-Qq; Mon, 04 Jul 2022 23:15:12 +0000 Date: Tue, 5 Jul 2022 00:15:12 +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 4/7] step_into(): lose inode argument 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 make handle_mounts() always fetch it. This is just the first step - the callers of step_into() will stop trying to calculate the sucker, etc. The passed value should be equal to dentry->d_inode in all cases; in RCU mode - fetched after we'd sampled ->d_seq. Might as well fetch it here. We do need to validate ->d_seq, which duplicates the check currently done in lookup_fast(); that duplication will go away shortly. After that change handle_mounts() always ignores the initial value of *inode and always sets it on success. Signed-off-by: Al Viro --- fs/namei.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index c7c9e88add85..dddbebf92b48 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1532,6 +1532,11 @@ 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))) return 0; // *path and nd->next_seq might've been clobbered @@ -1842,9 +1847,10 @@ static const char *pick_link(struct nameidata *nd, struct path *link, * NOTE: dentry must be what nd->next_seq had been sampled from. */ static const char *step_into(struct nameidata *nd, int flags, - struct dentry *dentry, struct inode *inode) + struct dentry *dentry) { struct path path; + struct inode *inode; int err = handle_mounts(nd, dentry, &path, &inode); if (err < 0) @@ -1970,7 +1976,7 @@ static const char *handle_dots(struct nameidata *nd, int type) parent = follow_dotdot(nd, &inode); if (IS_ERR(parent)) return ERR_CAST(parent); - error = step_into(nd, WALK_NOFOLLOW, parent, inode); + error = step_into(nd, WALK_NOFOLLOW, parent); if (unlikely(error)) return error; @@ -2015,7 +2021,7 @@ static const char *walk_component(struct nameidata *nd, int flags) } if (!(flags & WALK_MORE) && nd->depth) put_link(nd); - return step_into(nd, flags, dentry, inode); + return step_into(nd, flags, dentry); } /* @@ -2474,8 +2480,7 @@ static int handle_lookup_down(struct nameidata *nd) if (!(nd->flags & LOOKUP_RCU)) dget(nd->path.dentry); nd->next_seq = nd->seq; - return PTR_ERR(step_into(nd, WALK_NOFOLLOW, - nd->path.dentry, nd->inode)); + return PTR_ERR(step_into(nd, WALK_NOFOLLOW, nd->path.dentry)); } /* Returns 0 and nd will be valid on success; Retuns error, otherwise. */ @@ -3464,7 +3469,7 @@ static const char *open_last_lookups(struct nameidata *nd, finish_lookup: if (nd->depth) put_link(nd); - res = step_into(nd, WALK_TRAILING, dentry, inode); + res = step_into(nd, WALK_TRAILING, dentry); if (unlikely(res)) nd->flags &= ~(LOOKUP_OPEN|LOOKUP_CREATE|LOOKUP_EXCL); return res; -- 2.30.2