Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4B772C08BB for ; Thu, 2 Jul 2026 01:40:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782956460; cv=none; b=l3n//S42poyBf9cHDRqsGt9NzIgYwsZeyVTv+GgKN4UXPboav0StKaN6XcXCJWPJm3/OIGPTYAsOyWR8r3gUPjecyeywGeVj7q6OPcBKIELTq7jwZ0sLGP3xHn82gGLQyR56eB94mNMtjfw/dFYzMmlSE0F+wjRWDMqgVDY/BWQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782956460; c=relaxed/simple; bh=BDruZbnqLN83CA4Cag/hRE9pANOTDt+yvVhCc89COdo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=syBt0NKwl6LzN7BZb3zH7wKGlqDA5BgrnYL/cBRivwm3VGOW1nfEWo4+OHRARRocZyFK1+tsg4SGJLSDzkGMrsfHnewPfOi498i9os22WZr6QIUGM+WlEoiZQvO11H8vHP+I63lVEf1vOqMYH19aYKo/F5J31FG99ZCyjS+Ic60= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ownmail.net; spf=pass smtp.mailfrom=ownmail.net; dkim=pass (2048-bit key) header.d=ownmail.net header.i=@ownmail.net header.b=SHjXbTyz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PdpBOCgE; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ownmail.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ownmail.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ownmail.net header.i=@ownmail.net header.b="SHjXbTyz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PdpBOCgE" Received: from phl-compute-08.internal (phl-compute-08.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id 3D442140014D; Wed, 1 Jul 2026 21:40:58 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Wed, 01 Jul 2026 21:40:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ownmail.net; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:subject:subject:to:to; s=fm1; t=1782956458; x=1783042858; bh=jRK3PihBUTPjhctBVRomM9UR3mfAbrAApyv4dbPrNfs=; b= SHjXbTyzPf0ZV8m3flM/hnehNSfywM3IMGQQoVAh1FvX5Q80HopzmE8xnJDkyuEK 8mxTdbljITRsmLl9SzMkKU+nTtrDTAwGUvDzf+QILReuMS0rdj4FzSdxJL77M7TG ae/gyi7GTOAzhMoxPiY57pXXOwmkci8lD3zpXVbtpvqlpFejwRB9B6F3gNvJSFaI QOG45WPxoI1pT1vSu8t2db2UQ/Dh9UztEnS7nQIBGB641lFQqdnnGE4/1ZNdtQyt 58EeVkK/5k+FOf370V7Z6UrKkMQ5VTxksdxJHl9LO42guLHSZ5zqJviYEdSQVTJZ I6I+5WXq27bB7icnDYd7/g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1782956458; x=1783042858; bh=j RK3PihBUTPjhctBVRomM9UR3mfAbrAApyv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1m+gy7+JCA/A2Rg X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 1 Jul 2026 21:40:56 -0400 (EDT) From: NeilBrown To: Chuck Lever , Jeff Layton Cc: Olga Kornievskaia , Dai Ngo , Tom Talpey , linux-nfs@vger.kernel.org Subject: [PATCH 10/10] nfsd: reduce want-write range in nfsd4_create_file( Date: Thu, 2 Jul 2026 11:34:29 +1000 Message-ID: <20260702014000.3397240-11-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20260702014000.3397240-1-neilb@ownmail.net> References: <20260702014000.3397240-1-neilb@ownmail.net> Reply-To: NeilBrown Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: NeilBrown nfsd4_create_file() needs write access to the mount for two purposes: 1/ to create/open the file. 2/ to set attributes on the newly created file. Normally a file being created would be open for write, and once we have an active open we have the write access needed for a setattr. However if a file were created but opened read-only then the setattr wouldn't necessarily have write access to the mount. Currently this is all handled by holding the write access across the open and the setattr. A subsequent patch will necessarily change how write access is gained for the open. So we reduce the range for the first want_write, and add another one only if setattr is needed on a read-only open. Signed-off-by: NeilBrown --- fs/nfsd/nfs4proc.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 961e0c26e9a2..08e1213de743 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -308,7 +308,7 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, &QSTR_LEN(open->op_fname, open->op_fnamelen)); if (IS_ERR(child)) { status = nfserrno(PTR_ERR(child)); - goto out; + goto out_write; } path.dentry = child; @@ -321,16 +321,17 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, end_creating(child); status = nfserrno(PTR_ERR(open->op_filp)); open->op_filp = NULL; - goto out; + goto out_write; } open->op_created = open->op_filp->f_mode & FMODE_CREATED; } end_creating(child); + fh_drop_write(fhp); status = fh_compose(resfhp, fhp->fh_export, child, fhp); if (status != nfs_ok) - goto out; + goto out_free; if (!open->op_created && nfsd4_create_is_exclusive(open->op_createmode) && @@ -357,7 +358,7 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, !iap->ia_size); } else status = nfserr_exist; - goto out; + goto out_free; } /* file was created */ fh_fill_post_attrs(fhp); @@ -367,7 +368,24 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, iap->ia_valid &= ~ATTR_SIZE; if (is_create_with_attrs(open)) { - status = nfsd_create_setattr(rqstp, fhp, resfhp, &attrs); + if (((oflags & O_ACCMODE) == O_RDONLY)) { + /* + * We will need write access to set the attrs, + * but a successful open won't have provided + * that. + */ + int host_err = fh_want_write(fhp); + if (host_err) { + status = nfserrno(host_err); + } else { + status = nfsd_create_setattr(rqstp, fhp, + resfhp, &attrs); + fh_drop_write(fhp); + } + } else { + status = nfsd_create_setattr(rqstp, fhp, + resfhp, &attrs); + } if (attrs.na_labelerr) open->op_bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL; @@ -378,11 +396,13 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, if (attrs.na_paclerr) open->op_bmval[2] &= ~FATTR4_WORD2_POSIX_ACCESS_ACL; } -out: - fh_drop_write(fhp); out_free: nfsd_attrs_free(&attrs); return status; + +out_write: + fh_drop_write(fhp); + goto out_free; } /** -- 2.50.0.107.gf914562f5916.dirty