Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3289351imm; Sun, 29 Jul 2018 15:08:41 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeBVg9RNJsqWjnD5AHNqbCyhqS4dN9+Wb+gqXLgQAwGY99WuqAFXQd6rEuHB25l68pyS/ol X-Received: by 2002:a17:902:6684:: with SMTP id e4-v6mr14079378plk.35.1532902121221; Sun, 29 Jul 2018 15:08:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532902121; cv=none; d=google.com; s=arc-20160816; b=xSJL0iwb2oQYFdkJq8W/+7WbACadqKGOFa6p0Yv/uDXiOqftC9W3STS+oMvNuNZ1OL QCM8O4TxY7X48PJhAaBhwJlOpj4JpXOcVka3SBtWKLTO/PP9cbjmc4igBvZWLcdZEYnk xNJ9uwH1jN8L/1WYKmLNRL2XdVLEk24x1EyQPpQDwhFvaW0Sfocsbms7ocFJbYopuNFu zQjrF0S1yvCEeVNbWBOGT79RsggMBdP/UBWtx2D30YTjlXU3X3k842ifizt/CcxDu/4l YEHelqZkgPpG6wWsHrL4ab6nVcMdwNUbQj3ng9Eo2D01440mXKE5jJRLtndVpLFaDOgT HEWQ== 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=JKNaaGb8c53UgkRkDTNGHPpJWyymj6NSfkKQQ3mgY0w=; b=vuAU1vUsrFiMY5MBsLdy04Q/8/KZkZJ8qpQngJV0AIZ71u5SJ6uIuEgk/c/5vCQtIF 4Usz67coDkDxutRlqYixTIs2EXAlIqbHHsmuVu4QuyJ1RBZhZ/3DV9keiVVtQULhTIK0 nPMMbDd2JlsDPyUn29zPcBagZyMI2YcD6KcVQNGDZAQSFhU4lTEAkWpH1uDb0lPf7FZR mYTZAhQpa2Iq2GXhVa8MUrQPITYrA1lgqyVC6odg1IiAEe7A9hkId2JI5bkHEON18N1o 1OM9T3xpKaUnRYNtRRtj64ORQreyt0ayNn69Nbb3ZlcGTj35paSRTkyf9spOcbYHrAuB P2CA== 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 a10-v6si9415304pln.349.2018.07.29.15.08.27; Sun, 29 Jul 2018 15:08:41 -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 S1731704AbeG2XiP (ORCPT + 99 others); Sun, 29 Jul 2018 19:38:15 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:51584 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728750AbeG2Xg4 (ORCPT ); Sun, 29 Jul 2018 19:36:56 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1fjto5-0003VE-R0; Sun, 29 Jul 2018 22:04:53 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , linux-kernel@vger.kernel.org, Miklos Szeredi , Trond Myklebust Subject: [PATCH 01/16] nfs_instantiate(): prevent multiple aliases for directory inode Date: Sun, 29 Jul 2018 23:04:38 +0100 Message-Id: <20180729220453.13431-1-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180729220317.GB30522@ZenIV.linux.org.uk> References: <20180729220317.GB30522@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 Since NFS allows open-by-fhandle, we have to cope with the possibility of mkdir vs. open-by-guessed-handle races. A local filesystem could decide what the inumber of the new object will be and insert a locked inode with that inumber into icache _before_ the on-disk data structures begin to look good and unlock it only once it has a dentry alias, so that open-by-handle coming first would quietly fail and mkdir coming first would have open-by-handle grab its dentry. For NFS it's a non-starter - the icache key is server-supplied fhandle and we do not get that until the object has been fully created on server. We really have to deal with the possibility that open-by-handle gets the in-core inode and attaches a dentry to it before mkdir does. Solution: let nfs_mkdir() use d_splice_alias() to catch those. We can * get an error. Just return it to our caller. * get NULL - no preexisting dentry aliases, we'd just done what d_add() would've done. Success. * get a reference to preexisting alias. In that case the alias had been moved in place of nfs_mkdir() argument (and hashed there), while nfs_mkdir() argument is left unhashed negative. Which is just fine for ->mkdir() callers, all we need is to release the reference we'd got from d_splice_alias() and report success. Cc: Trond Myklebust Signed-off-by: Al Viro --- fs/nfs/dir.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 7a9c14426855..df6fd4e5b068 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1641,6 +1641,7 @@ int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fhandle, struct dentry *parent = dget_parent(dentry); struct inode *dir = d_inode(parent); struct inode *inode; + struct dentry *d; int error = -EACCES; d_drop(dentry); @@ -1662,10 +1663,12 @@ int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fhandle, goto out_error; } inode = nfs_fhget(dentry->d_sb, fhandle, fattr, label); - error = PTR_ERR(inode); - if (IS_ERR(inode)) + d = d_splice_alias(inode, dentry); + if (IS_ERR(d)) { + error = PTR_ERR(d); goto out_error; - d_add(dentry, inode); + } + dput(d); out: dput(parent); return 0; -- 2.11.0