Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2060881pxb; Fri, 25 Mar 2022 10:23:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw10iT/fLCjOPsLPtPG28engYp0g28HYTZDYNi0aQpG5ZJgJc/GatracVEOl488H5ADjHPR X-Received: by 2002:a65:45c8:0:b0:380:352e:825b with SMTP id m8-20020a6545c8000000b00380352e825bmr472917pgr.509.1648229010873; Fri, 25 Mar 2022 10:23:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648229010; cv=none; d=google.com; s=arc-20160816; b=CPwkxf8DqS0EPPe0pnHeOw5L5Y6I5z9FzTRWirmLdKnp8MEz50oiFaLiLVbDZRdcJa UnJbWFQeznuSrAojOjKEOtayr8JVFZfBhMMrU6wly2otG3bKyblvpZzvGaNkp4YHFBFN KC1f4e0n9XRLEINKKzd+wQeqWTTntpya6pxsRHt8v1sq/XnSnzQQxU09k8/uzYsP43t7 v272cfVuF8fDDGaktXG6HiMr4XOZUIgp3/U3D+zNaLcMjtcOlmC2rsaivjM8bDF78Odz quVNx+QqiZio8WdAMSe0LBKnFckWnbjnpl3H/cheyoI+lvjM+7U54dsSkIPnjGpVUv05 F7vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:message-id:date:cc:to:from:subject; bh=KM+H+fLlGat+ZgLqPeTd0wjdhdGt7RCCFVeQHnM6UHI=; b=clgV1rHF+VCiJ0U9B3wPkmP1I9ty6ThO/dekvJEibB5pIHtru9u6QMCY+HhyAMxjti 91NDvSuWAEJXU9b87ciVFkcd5fUVEJsjJlSUdt7fWFP/YKk9K3Y7iDYpZqLyhNgLXDAt sD1TOx9gnDj2shySxjX/3uzOPKhvdzlapQq9gWgqzkDaPfWx4QZPx9q2yOLSOO9r5Wkp 0nBcL9QOhQ9CEvB84HeOggFCDwfhx6BlbER0rdDdjWiywx9Y9V9h4E6kukJrW0InHfmm tljWCzneUjxLSIlmuUCW9BI0YGQjBV2nsk5xD7hIzJ4OgkXQktG7WpVbsnKjPULONJDm VS9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x7-20020a170902ec8700b00153b2d16432si3016180plg.58.2022.03.25.10.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 10:23:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C47ADF2112; Fri, 25 Mar 2022 10:19:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353507AbiCXWJk (ORCPT + 99 others); Thu, 24 Mar 2022 18:09:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355231AbiCXWJj (ORCPT ); Thu, 24 Mar 2022 18:09:39 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAD2910FD for ; Thu, 24 Mar 2022 15:08:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 507D2B8269E for ; Thu, 24 Mar 2022 22:08:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6B50C340EC; Thu, 24 Mar 2022 22:08:02 +0000 (UTC) Subject: [PATCH RFC] NFSD: Instantiate a filecache entry when creating a file From: Chuck Lever To: bfields@fieldses.org Cc: jlayton@kernel.org, linux-nfs@vger.kernel.org Date: Thu, 24 Mar 2022 18:08:01 -0400 Message-ID: <164815968129.1809.12154191330176123202.stgit@manet.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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-nfs@vger.kernel.org There have been reports of races that cause NFSv4 OPEN(CREATE) to return an error even though the requested file was created. NFSv4 does not seem to provide a status code for this case. There are plenty of things that can go wrong between the vfs_create() call in do_nfsd_create() and nfs4_vfs_get_file(), but one of them is another client looking up and modifying the file's mode bits in that window. If that happens, the creator might lose access to the file before it can be opened. Instead of opening the newly created file in nfsd4_process_open2(), open it as soon as the file is created, and leave it sitting in the file cache. This patch is not optimal, of course - we should replace the vfs_create() call in do_nfsd_create() with a call that creates the file and returns a "struct file *" that can be planted immediately in nf->nf_file. But first, I would like to hear opinions about the approach suggested above. BugLink: https://bugzilla.linux-nfs.org/show_bug.cgi?id=382 Signed-off-by: Chuck Lever --- fs/nfsd/vfs.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 02a544645b52..80b568fa12f1 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -1410,6 +1410,7 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp, __be32 err; int host_err; __u32 v_mtime=0, v_atime=0; + struct nfsd_file *nf; /* XXX: Shouldn't this be nfserr_inval? */ err = nfserr_perm; @@ -1535,6 +1536,14 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp, iap->ia_atime.tv_nsec = 0; } + /* Attempt to instantiate a filecache entry while we still hold + * the parent's inode mutex. */ + err = nfsd_file_acquire(rqstp, resfhp, NFSD_MAY_WRITE, &nf); + if (err) + /* This would be bad */ + goto out; + nfsd_file_put(nf); + set_attr: err = nfsd_create_setattr(rqstp, resfhp, iap);