Skip to content

Commit a395726

Browse files
author
Steve French
committed
cifs: fix data corruption in read after invalidate
When invalidating a file as part of breaking a lease, the folios holding the file data are disposed of, and truncate calls ->invalidate_folio() to get rid of them rather than calling ->release_folio(). This means that the netfs_inode::zero_point value didn't get updated in current upstream code to reflect the point after which we can assume that the server will only return zeroes, and future reads will then return blocks of zeroes if the file got extended for any region beyond the old zero point. Fix this by updating zero_point before invalidating the inode in cifs_revalidate_mapping(). Suggested-by: David Howells <dhowells@redhat.com> Fixes: 3ee1a1f ("cifs: Cut over to using netfslib") Reviewed-by: David Howells <dhowell@redhat.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 1ab1bd2 commit a395726

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

fs/smb/client/inode.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2465,7 +2465,8 @@ int
24652465
cifs_revalidate_mapping(struct inode *inode)
24662466
{
24672467
int rc;
2468-
unsigned long *flags = &CIFS_I(inode)->flags;
2468+
struct cifsInodeInfo *cifs_inode = CIFS_I(inode);
2469+
unsigned long *flags = &cifs_inode->flags;
24692470
struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
24702471

24712472
/* swapfiles are not supposed to be shared */
@@ -2482,6 +2483,7 @@ cifs_revalidate_mapping(struct inode *inode)
24822483
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RW_CACHE)
24832484
goto skip_invalidate;
24842485

2486+
cifs_inode->netfs.zero_point = cifs_inode->netfs.remote_i_size;
24852487
rc = filemap_invalidate_inode(inode, true, 0, LLONG_MAX);
24862488
if (rc) {
24872489
cifs_dbg(VFS, "%s: invalidate inode %p failed with rc %d\n",

0 commit comments

Comments
 (0)