linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [SMB3][PATCH] fix copy_file_range when copying beyond end of source file
@ 2019-06-20  1:44 Steve French
  2019-06-20  2:14 ` ronnie sahlberg
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Steve French @ 2019-06-20  1:44 UTC (permalink / raw)
  To: CIFS, samba-technical, Amir Goldstein, linux-fsdevel, Darrick J. Wong

[-- Attachment #1: Type: text/plain, Size: 540 bytes --]

Patch attached fixes the case where copy_file_range over an SMB3 mount
tries to go beyond the end of file of the source file.  This fixes
xfstests generic/430 and generic/431

Amir's patches had added a similar change in the VFS layer, but
presumably harmless to have the check in cifs.ko as well to ensure
that we don't try to copy beyond end of the source file (otherwise
SMB3 servers will return an error on copychunk rather than doing the
partial copy (up to end of the source file) that copy_file_range
expects).



-- 
Thanks,

Steve

[-- Attachment #2: 0001-SMB3-fix-copy-file-range-when-beyond-size-of-source-.patch --]
[-- Type: text/x-patch, Size: 1568 bytes --]

From a3d9033df7bb5206093f00eb037242336ff7ccfb Mon Sep 17 00:00:00 2001
From: Steve French <stfrench@microsoft.com>
Date: Wed, 19 Jun 2019 15:10:12 -0500
Subject: [PATCH] [SMB3] fix copy file range when beyond size of source file

When requesting a copy which would go beyond the end of the
source file, only copy to the end of the source file instead
of returning an error.  Fixes xfstests generic/430 and
generic/431

Signed-off-by: Steve French <stfrench@microsoft.com>
---
 fs/cifs/smb2ops.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index 376577cc4159..1cdbeec56453 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -1522,6 +1522,7 @@ smb2_copychunk_range(const unsigned int xid,
 	int chunks_copied = 0;
 	bool chunk_sizes_updated = false;
 	ssize_t bytes_written, total_bytes_written = 0;
+	struct inode *inode = d_inode(srcfile->dentry);
 
 	pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
 
@@ -1546,6 +1547,14 @@ smb2_copychunk_range(const unsigned int xid,
 	tcon = tlink_tcon(trgtfile->tlink);
 
 	while (len > 0) {
+		if (src_off >= inode->i_size) {
+			cifs_dbg(FYI, "nothing to do on copychunk\n");
+			goto cchunk_out; /* nothing to do */
+		} else if (src_off + len > inode->i_size) {
+			/* consider adding check to see if src oplocked */
+			len = inode->i_size - src_off;
+			cifs_dbg(FYI, "adjust copychunk len %lld less\n", len);
+		}
 		pcchunk->SourceOffset = cpu_to_le64(src_off);
 		pcchunk->TargetOffset = cpu_to_le64(dest_off);
 		pcchunk->Length =
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-07-15  7:50 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-20  1:44 [SMB3][PATCH] fix copy_file_range when copying beyond end of source file Steve French
2019-06-20  2:14 ` ronnie sahlberg
2019-06-20  3:19   ` Steve French
2019-06-20  3:28     ` ronnie sahlberg
2019-06-20  4:54       ` Amir Goldstein
2019-06-20  4:52     ` Dave Chinner
2019-06-20  5:28 ` Amir Goldstein
2019-06-20  5:46   ` Steve French
2019-07-11 15:16 ` Steve French
2019-07-11 15:19   ` Steve French
2019-07-15  7:50     ` Amir Goldstein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).