All of lore.kernel.org
 help / color / mirror / Atom feed
From: VeroFess <coderzeng@gmail.com>
To: linux-nfs@vger.kernel.org
Cc: cel@kernel.org, jlayton@kernel.org
Subject: [PATCH 3/3] NFSD: Verify COPY and CLONE source and destination filehandles
Date: Tue,  3 Nov 2026 09:32:37 +0800	[thread overview]
Message-ID: <20261103013237.1174538-4-coderzeng@gmail.com> (raw)
In-Reply-To: <20261103013237.1174538-1-coderzeng@gmail.com>

nfsd4_verify_copy() checks the saved source export's flavor and
transport policy, then resolves its stateid. With a cached OPEN
stateid, the file permission check can use credentials left by PUTFH
on the destination export. This can retain root access after the
source export enables root_squash, or reject a source that all_squash
maps to its anonymous UID or GID. The requester must already hold an
OPEN stateid for each file in the reproducer, both source and
destination.

Verify the saved filehandle before resolving the source stateid.
This checks its port requirement and installs the source export's
mapped credentials. Verify the destination filehandle before
resolving its stateid to restore the credentials for the write.
Continue mapping NFS4ERR_WRONGSEC to NFS4ERR_ACCESS for COPY and CLONE.

Fixes: 29ae7f9dc21a ("NFSD: Implement the COPY call")
Signed-off-by: VeroFess <coderzeng@gmail.com>
---
On the combined fix tree, saved-source COPY with root_squash was denied
without changing the destination; permitted COPY and CLONE matched the
source bytes. This patch also built alone with W=1.

 fs/nfsd/nfs4proc.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index 218cedb..774ba9e 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -1514,7 +1514,7 @@ nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 		return nfserr_nofilehandle;
 
 	/* A cached open stateid does not authorize the saved source export. */
-	status = check_nfsd_access(cstate->save_fh.fh_export, rqstp);
+	status = fh_verify(rqstp, &cstate->save_fh, 0, NFSD_MAY_NOP);
 	if (status)
 		return status == nfserr_wrongsec ? nfserr_acces : status;
 
@@ -1523,6 +1523,14 @@ nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	if (status)
 		goto out;
 
+	/* Use the destination export's credentials for the write. */
+	status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
+	if (status) {
+		if (status == nfserr_wrongsec)
+			status = nfserr_acces;
+		goto out_put_src;
+	}
+
 	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
 					    dst_stateid, WR_STATE, dst, NULL);
 	if (status)
-- 
2.43.0


  parent reply	other threads:[~2026-11-03  1:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03  1:32 [PATCH 0/3] NFSD: Apply all export checks when a compound changes exports VeroFess
2026-11-03  1:32 ` [PATCH 1/3] NFSD: Check the secure-port policy when entering an export VeroFess
2026-11-03  1:32 ` [PATCH 2/3] NFSD: Apply the entered export's credentials after LOOKUP and RESTOREFH VeroFess
2026-11-03  1:32 ` VeroFess [this message]
2026-11-03 14:06 ` [PATCH 0/3] NFSD: Apply all export checks when a compound changes exports Chuck Lever

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261103013237.1174538-4-coderzeng@gmail.com \
    --to=coderzeng@gmail.com \
    --cc=cel@kernel.org \
    --cc=jlayton@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.