Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (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 1CCF62BE035 for ; Tue, 26 May 2026 05:30:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779773437; cv=none; b=iPwlPKqc8TbrSrpJm3EiEkFRTpQrXJdihj9Ub3FMFLbf4oJZRZvc+jc819HofCD8M2QyOsqPWxxID8cvKK92CsCarOnnhG1TcqDJFXV2lNCMaII/T0tN2S12K+K9mh3fnhZzyfPt1fYKp4VDu2YOFXw4yMezzVTNDcZpiKVhxSw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779773437; c=relaxed/simple; bh=VBfruXN1pS3FslARFykDxlxebYAs9/KBkSP9Zb4ggko=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c05DpaKcjjl/Hj6M07iWyP5997JVC9XhfsNU2gGj8VZiyP1seI/F9ZhCAQhBZBJUtUbHoBAhxvbi6YStxXvL2XPfMWA5MWVJrgiGEUUp0D6uLIg9EXZuYsZTg9pDJvXRq8xVGCJDwG1AiZFa69ikvukuNmUDp0JiaDEU4l4d8Sw= 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=L+MY+lvY; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=TDOfa+mX; arc=none smtp.client-ip=103.168.172.144 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="L+MY+lvY"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="TDOfa+mX" Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id 46947EC0079; Tue, 26 May 2026 01:30:35 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Tue, 26 May 2026 01:30:35 -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=fm3; t=1779773435; x=1779859835; bh=CMDUrKQR5dCi0IvS93YtWP5/q+nim1hPJc9wu34j6n4=; b= L+MY+lvYA5GOoxW862hI/uThxiZiM5w4n0ZEISsEKLe+uxHNun98xWdVTZ6cTQh3 oA8QeBd0JlB5rb7AWpwINh48PenAam2f8oOg4VQ9L1n0aG9UZmGL+Wh3rBpDwqx9 o/NeDvlfYogmHui0xMw6MKWkLgdnHHolPZqYL9Vw9F44gtNZKnM7mmCDpNSAB89U paGlVg8AMnA9N0NdzNCpWcOqpeqLOfTh9Q3Zg8u6ofg8OVq9+ozoP0ejGkmykUfF x8vPWbYdSp3fS8+Msw49luAU0zYW1rQg7ScEmWmGDnv6RijeQGYXJQGHXSE84q9+ LxUYUFGaGot/BCntv+6dOA== 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=fm3; t=1779773435; x=1779859835; bh=C MDUrKQR5dCi0IvS93YtWP5/q+nim1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w9eKAhsIxovLKPP9vNmR8HrBQ X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 26 May 2026 01:30:33 -0400 (EDT) From: NeilBrown To: Chuck Lever , Jeff Layton Cc: Benjamin Coddington , linux-nfs@vger.kernel.org Subject: [PATCH 1/2] nfsd: fix possible fh_compose of wrong dentry in nfsd4_create_file() Date: Tue, 26 May 2026 15:27:58 +1000 Message-ID: <20260526053004.4014491-2-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20260526053004.4014491-1-neilb@ownmail.net> References: <20260526053004.4014491-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 dentry_create() can hypothetically provide a different dentry than the one passed in. This could happen, for example, if the exported filesystem is NFS, and the server return to OPEN a filehandle which matched a directory that was already in the dcache. Clearly this would not be expected! If this were to happen the dentry (child) that was already stored in resfhp could be freed and later dereferenced. We shouldn't call fh_compose() until we are certain that we have the final dentry, so this patch moved the fh_compose() call to two places: one for the case where the target already exists, and one after dentry_create() where it was created. Fixes: 64a989dbd144 ("VFS/knfsd: Teach dentry_create() to use atomic_open()") Signed-off-by: NeilBrown --- fs/nfsd/nfs4proc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index ab39ec885440..c7adf791b6d1 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -302,10 +302,6 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, goto out; } - status = fh_compose(resfhp, fhp->fh_export, child, fhp); - if (status != nfs_ok) - goto out; - v_mtime = 0; v_atime = 0; if (nfsd4_create_is_exclusive(open->op_createmode)) { @@ -331,6 +327,10 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, if (status != nfs_ok) goto out; + status = fh_compose(resfhp, fhp->fh_export, child, fhp); + if (status != nfs_ok) + goto out; + switch (open->op_createmode) { case NFS4_CREATE_UNCHECKED: if (!d_is_reg(child)) @@ -381,6 +381,10 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp, open->op_created = true; fh_fill_post_attrs(fhp); + status = fh_compose(resfhp, fhp->fh_export, child, fhp); + if (status != nfs_ok) + goto out; + /* A newly created file already has a file size of zero. */ if ((iap->ia_valid & ATTR_SIZE) && (iap->ia_size == 0)) iap->ia_valid &= ~ATTR_SIZE; -- 2.50.0.107.gf914562f5916.dirty