Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp696793ybl; Wed, 28 Aug 2019 04:06:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZKdmCblg0u8GOYi/26uM2cT5NTK9KYj5S1rfviIEd3vr3NKxj3UubJSsazNUWM4oqj81i X-Received: by 2002:a63:d04e:: with SMTP id s14mr2800587pgi.189.1566990387075; Wed, 28 Aug 2019 04:06:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566990387; cv=none; d=google.com; s=arc-20160816; b=gFkJfTkKNphDHAODuzmMHgP4VbmsHx3XnTOQFzFdkc3YKLblORSsm/iDfsqy9SB/zs 9Ju7fLmOnlWgL+3WsinWLCmQtHYd6OVO+XACZT3MZaPb3jnxtry64ciNYcFipN/EbBVs k/eu3NKasI6737bH7lz7keD1WdY0pshgMONojpSzQq0dd7kF/Qfr4f3h8FQFpIhWdRTP Zoz233WBoyHzS4ZKSc3l6mBIFjRAmN9Rur1Ujbz/7deOedY713mB6aVDJ8uGKVXmnAY3 NanlTNknyHYf1sd5ElUXAV5nk6i7iGtiB8Sxtr5jO5a9tkOobeEt1sSs4gnRnfOc0B8S +xcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=6BhCxjbjXMkdWE1B1M6IkZ4bXhe/Fn2wHYwI4MbZRWo=; b=vd+D1GfkDo5ZfCIS6ZYGVouMOMp+AsEjIrIPlHisSIn3xa+q5RsrABbipxQ6YBXzY4 62kEpLosDbgo/jAABmyzkCrCjGn/btMGKlvpyy9d4XDkRar7UVPD3d5bXr9m2rNF8HEy Gp88Mnbb36JGrgere8TIdx4kZvopaGhh/x1q9sshcNa/OimupHgNH/q3FufgP6M5pk/v odeK3hhe/josi4V8WUR02D+pPatOYRuK5LwcZf6op+NLApysQCvbsRXPCFMUjXfKTc7P o7eMNIXnTeLemPaJsBxjUZhdDILP/DGGYTExGNQscsgYnRfcg0Ug2LkSWEds0cNHKhiR dQkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bb7si1753169plb.303.2019.08.28.04.06.03; Wed, 28 Aug 2019 04:06:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-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-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726253AbfH1LGB (ORCPT + 99 others); Wed, 28 Aug 2019 07:06:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59178 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726232AbfH1LGB (ORCPT ); Wed, 28 Aug 2019 07:06:01 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D53278980E2; Wed, 28 Aug 2019 11:06:00 +0000 (UTC) Received: from [172.16.176.1] (ovpn-112-84.rdu2.redhat.com [10.10.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA3525C221; Wed, 28 Aug 2019 11:05:59 +0000 (UTC) From: "Benjamin Coddington" To: "Trond Myklebust" Cc: linux-nfs@vger.kernel.org, Anna.Schumaker@netapp.com, viro@zeniv.linux.org.uk Subject: Re: [PATCH] NFSv3: nfs_instantiate() might succeed leaving dentry negative unhashed Date: Wed, 28 Aug 2019 07:05:57 -0400 Message-ID: <19F3F549-6C84-4DD6-A8E9-2562DAE70CF0@redhat.com> In-Reply-To: <720c018fc83192cdea73f8f26ca737e5ac393902.camel@hammerspace.com> References: <720c018fc83192cdea73f8f26ca737e5ac393902.camel@hammerspace.com> MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.67]); Wed, 28 Aug 2019 11:06:01 +0000 (UTC) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On 27 Aug 2019, at 7:46, Trond Myklebust wrote: > On Tue, 2019-08-27 at 06:33 -0400, Benjamin Coddington wrote: >> On 26 Aug 2019, at 16:39, Trond Myklebust wrote: >>> If this is a consequence of a race in nfs_instantiate, then why are >>> we >>> not fix it there? Won't we otherwise end up having to duplicate the >>> above code in all the other callers? >>> >>> IOW: why not simply modify nfs_instantiate() to return the dentry >>> from >>> d_splice_alias(), much like we already do for nfs_lookup()? >> >> None of the other callers care about the dentry and it seemed more >> invasive. >> It is also an accepted pattern for VFS - that's why Al justified it >> in >> b0c6108ecf64. > > It is racy, though. Nothing guarantees that a dentry for that file is > still hashed under the same name when you look it up again, so it is > better to pass it back directly from the d_splice_alias() call. > >> If you'd rather change all the callers, let me know and I can send >> that. > > If you'd prefer not to have to change all the callers, then perhaps > split the function into two parts: > - The inner part that returns the dentry from d_splice_alias() on > success, and which can be called directly from nfs3_do_create(). > - Then a wrapper that works like nfs_instantiate() by dput()ing the > valid dentry (and returning 0) or otherwise converting the ERR_PTR() > and returning that. Ok, sounds fine. One thing that strikes me as odd is the d_drop() at the top of nfs_instantiate(). That seems wrong if the next check for positive bypasses the work of hashing it again. Can you give me a hint as to why the paths are that way? Otherwise, I think it should change as: diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 8d501093660f..7720a19b38d3 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1682,11 +1682,12 @@ int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fhandle, struct dentry *d; int error = -EACCES; - d_drop(dentry); - /* We may have been initialized further down */ if (d_really_is_positive(dentry)) goto out; + + d_drop(dentry); if (fhandle->size == 0) { error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, fhandle, fattr, NULL); if (error) Ben