Linux CIFS filesystem development
 help / color / mirror / Atom feed
* [PATCH][SMB3] fix temporary data corruption in collapse range
@ 2022-08-20  0:06 Steve French
  2022-08-20 15:23 ` David Howells
  2022-08-22 16:15 ` David Howells
  0 siblings, 2 replies; 4+ messages in thread
From: Steve French @ 2022-08-20  0:06 UTC (permalink / raw)
  To: CIFS; +Cc: David Howells, ronnie sahlberg

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

collapse range doesn't discard the affected cached region
so can risk temporarily corrupting the file data. This
fixes xfstest generic/031

I also decided to merge a minor cleanup to this into the same patch
(avoiding rereading inode size repeatedly unnecessarily) to make it
clearer.

Cc: stable@vger.kernel.org
Fixes: 5476b5dd82c8b ("cifs: add support for FALLOC_FL_COLLAPSE_RANGE")
Reported-by: David Howells <dhowells@redhat.com>
Tested-by: David Howells <dhowells@redhat.com>
Reviewed-by: David Howells <dhowells@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>

See attached:
-- 
Thanks,

Steve

[-- Attachment #2: 0001-smb3-fix-collapse-range-temporary-data-corruption.patch --]
[-- Type: text/x-patch, Size: 2093 bytes --]

From bce7aeed5e9263097209cf7cfb0c7ce1a2afcce1 Mon Sep 17 00:00:00 2001
From: Steve French <stfrench@microsoft.com>
Date: Fri, 19 Aug 2022 18:57:05 -0500
Subject: [PATCH] smb3: fix collapse range temporary data corruption

collapse range doesn't discard the affected cached region
so can risk temporarily corrupting the file data. This
fixes xfstest generic/031

Cc: stable@vger.kernel.org
Fixes: 5476b5dd82c8b ("cifs: add support for FALLOC_FL_COLLAPSE_RANGE")
Reported-by: David Howells <dhowells@redhat.com>
Tested-by: David Howells <dhowells@redhat.com>
Reviewed-by: David Howells <dhowells@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
---
 fs/cifs/smb2ops.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index 96f3b0573606..cd9fa984538a 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -3677,24 +3677,25 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
 	struct cifsFileInfo *cfile = file->private_data;
 	struct cifsInodeInfo *cifsi;
 	__le64 eof;
+	loff_t old_eof;
 
 	xid = get_xid();
 
 	inode = d_inode(cfile->dentry);
 	cifsi = CIFS_I(inode);
-
-	if (off >= i_size_read(inode) ||
-	    off + len >= i_size_read(inode)) {
+	old_eof = i_size_read(inode);
+	if ((off >= old_eof) ||
+	    off + len >= old_eof) {
 		rc = -EINVAL;
 		goto out;
 	}
 
 	rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
-				  i_size_read(inode) - off - len, off);
+				  old_eof - off - len, off);
 	if (rc < 0)
 		goto out;
 
-	eof = cpu_to_le64(i_size_read(inode) - len);
+	eof = cpu_to_le64(old_eof - len);
 	rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
 			  cfile->fid.volatile_fid, cfile->pid, &eof);
 	if (rc < 0)
@@ -3702,6 +3703,7 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
 
 	rc = 0;
 
+	truncate_pagecache_range(inode, off, old_eof);
 	cifsi->server_eof = i_size_read(inode) - len;
 	truncate_setsize(inode, cifsi->server_eof);
 	fscache_resize_cookie(cifs_inode_cookie(inode), cifsi->server_eof);
-- 
2.34.1


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

end of thread, other threads:[~2022-08-22 16:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-20  0:06 [PATCH][SMB3] fix temporary data corruption in collapse range Steve French
2022-08-20 15:23 ` David Howells
2022-08-20 16:08   ` Steve French
2022-08-22 16:15 ` David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox