* [PATCH] NFSD: Reject a COPY whose source and destination are the same file
@ 2026-11-19 17:42 Jeff Layton
2026-11-19 18:48 ` Chuck Lever
2026-11-20 7:55 ` Aurélien Couderc
0 siblings, 2 replies; 4+ messages in thread
From: Jeff Layton @ 2026-11-19 17:42 UTC (permalink / raw)
To: Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
Anna Schumaker
Cc: linux-nfs, linux-kernel, Jeff Layton
RFC 7862 Section 15.2.3 says that COPY MUST fail with NFS4ERR_INVAL
when SAVED_FH and CURRENT_FH refer to the same file, whatever the
ranges. NFSD never checks for this. A same-file COPY with
non-overlapping ranges succeeds, and one with overlapping ranges fails
only because the VFS rejects it.
The overlap-only rule applies to CLONE (Section 15.13.3), so leave
nfsd4_verify_copy() alone. Instead, check in nfsd4_setup_intra_ssc(),
after both stateids are verified. For an inter-server copy, SAVED_FH
names a file on another server, so that path is not affected.
The Linux client never sends a same-file COPY, so this does not change
its behaviour. Found by pynfs COPY11.
Fixes: 29ae7f9dc21a ("NFSD: Implement the COPY call")
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/nfsd/nfs4proc.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index 9fba2b67cce2..27e9cd7ebf59 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -2107,9 +2107,23 @@ nfsd4_setup_intra_ssc(struct svc_rqst *rqstp,
struct nfsd4_compound_state *cstate,
struct nfsd4_copy *copy)
{
- return nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid,
- ©->nf_src, ©->cp_dst_stateid,
- ©->nf_dst);
+ __be32 status;
+
+ status = nfsd4_verify_copy(rqstp, cstate, ©->cp_src_stateid,
+ ©->nf_src, ©->cp_dst_stateid,
+ ©->nf_dst);
+ if (status)
+ return status;
+
+ /*
+ * RFC 7862 Section 15.2.3: COPY MUST fail with NFS4ERR_INVAL when
+ * SAVED_FH and CURRENT_FH refer to the same file, whether or not the
+ * ranges overlap. The caller releases nf_src and nf_dst.
+ */
+ if (file_inode(copy->nf_src->nf_file) ==
+ file_inode(copy->nf_dst->nf_file))
+ return nfserr_inval;
+ return nfs_ok;
}
static void nfsd4_cb_offload_release(struct nfsd4_callback *cb)
---
base-commit: 00270637d0d956cd6343c41bfd9220ba90360fac
change-id: 20261119-nfsd-copy-same-file-2477054222d6
Best regards,
--
Jeff Layton <jlayton@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] NFSD: Reject a COPY whose source and destination are the same file
2026-11-19 17:42 [PATCH] NFSD: Reject a COPY whose source and destination are the same file Jeff Layton
@ 2026-11-19 18:48 ` Chuck Lever
2026-11-20 7:55 ` Aurélien Couderc
1 sibling, 0 replies; 4+ messages in thread
From: Chuck Lever @ 2026-11-19 18:48 UTC (permalink / raw)
To: NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
Anna Schumaker, Jeff Layton
Cc: linux-nfs, linux-kernel
On Thu, 19 Nov 2026 09:42:56 -0800, Jeff Layton wrote:
> RFC 7862 Section 15.2.3 says that COPY MUST fail with NFS4ERR_INVAL
> when SAVED_FH and CURRENT_FH refer to the same file, whatever the
> ranges. NFSD never checks for this. A same-file COPY with
> non-overlapping ranges succeeds, and one with overlapping ranges fails
> only because the VFS rejects it.
>
> The overlap-only rule applies to CLONE (Section 15.13.3), so leave
> nfsd4_verify_copy() alone. Instead, check in nfsd4_setup_intra_ssc(),
> after both stateids are verified. For an inter-server copy, SAVED_FH
> names a file on another server, so that path is not affected.
>
> [...]
Applied to nfsd-testing, thanks!
[1/1] NFSD: Reject a COPY whose source and destination are the same file
commit: c235ae9d5057e37ed83de15b27fd8b8174a032d0
--
Chuck Lever <cel@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] NFSD: Reject a COPY whose source and destination are the same file
2026-11-19 17:42 [PATCH] NFSD: Reject a COPY whose source and destination are the same file Jeff Layton
2026-11-19 18:48 ` Chuck Lever
@ 2026-11-20 7:55 ` Aurélien Couderc
2026-11-20 21:16 ` Jeff Layton
1 sibling, 1 reply; 4+ messages in thread
From: Aurélien Couderc @ 2026-11-20 7:55 UTC (permalink / raw)
To: Jeff Layton, nfsv4
Cc: Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
Anna Schumaker, linux-nfs, linux-kernel
On Thu, Nov 19, 2026 at 6:44 PM Jeff Layton <jlayton@kernel.org> wrote:
>
> RFC 7862 Section 15.2.3 says that COPY MUST fail with NFS4ERR_INVAL
> when SAVED_FH and CURRENT_FH refer to the same file, whatever the
> ranges. NFSD never checks for this. A same-file COPY with
> non-overlapping ranges succeeds, and one with overlapping ranges fails
> only because the VFS rejects it.
>
> The overlap-only rule applies to CLONE (Section 15.13.3), so leave
> nfsd4_verify_copy() alone. Instead, check in nfsd4_setup_intra_ssc(),
> after both stateids are verified. For an inter-server copy, SAVED_FH
> names a file on another server, so that path is not affected.
>
> The Linux client never sends a same-file COPY, so this does not change
> its behaviour. Found by pynfs COPY11.
Why should COPY within the same file be blocked?
For example: Windows FSCTL_OFFLOAD_READ+FSCTL_OFFLOAD_WRITE is used
exactly like that by databases like Oracle. Even advertised as a
"database accelerator" feature...
Better tix the NFSv4.2 COPY spec at RFC level then...
Aurélien
--
Aurélien Couderc <aurelien.couderc2002@gmail.com>
Big Data/Data mining expert, chess enthusiast
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] NFSD: Reject a COPY whose source and destination are the same file
2026-11-20 7:55 ` Aurélien Couderc
@ 2026-11-20 21:16 ` Jeff Layton
0 siblings, 0 replies; 4+ messages in thread
From: Jeff Layton @ 2026-11-20 21:16 UTC (permalink / raw)
To: Aurélien Couderc, nfsv4
Cc: Chuck Lever, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
Anna Schumaker, linux-nfs, linux-kernel
On Fri, 2026-11-20 at 08:55 +0100, Aurélien Couderc wrote:
> On Thu, Nov 19, 2026 at 6:44 PM Jeff Layton <jlayton@kernel.org> wrote:
> >
> > RFC 7862 Section 15.2.3 says that COPY MUST fail with NFS4ERR_INVAL
> > when SAVED_FH and CURRENT_FH refer to the same file, whatever the
> > ranges. NFSD never checks for this. A same-file COPY with
> > non-overlapping ranges succeeds, and one with overlapping ranges fails
> > only because the VFS rejects it.
> >
> > The overlap-only rule applies to CLONE (Section 15.13.3), so leave
> > nfsd4_verify_copy() alone. Instead, check in nfsd4_setup_intra_ssc(),
> > after both stateids are verified. For an inter-server copy, SAVED_FH
> > names a file on another server, so that path is not affected.
> >
> > The Linux client never sends a same-file COPY, so this does not change
> > its behaviour. Found by pynfs COPY11.
>
> Why should COPY within the same file be blocked?
>
> For example: Windows FSCTL_OFFLOAD_READ+FSCTL_OFFLOAD_WRITE is used
> exactly like that by databases like Oracle. Even advertised as a
> "database accelerator" feature...
>
> Better tix the NFSv4.2 COPY spec at RFC level then...
>
It does seem a bit restrictive, but that's way the RFC is written
today. If you want to lead an effort to update the RFC, then be my
guest!
--
Jeff Layton <jlayton@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-20 21:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 17:42 [PATCH] NFSD: Reject a COPY whose source and destination are the same file Jeff Layton
2026-11-19 18:48 ` Chuck Lever
2026-11-20 7:55 ` Aurélien Couderc
2026-11-20 21:16 ` Jeff Layton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®