Cifs: fix kbz 216301: return corrupt/stale file content
Subsystems (2)
Steve, List
Please find a small patch that fixes kernel bugzilla 216301 which can cause writes to an mmaped file to corrupt data when reading it back.
The issue arises when mmaping a file under cache=none. In this case all writes go through the direct_write codepaths directly to the server.
But IF any of the mmapped page are already present then the write will go to the server without updating what we present to the application in the mmapped pages.
PATCH 1/1 cifs: revalidate mapping when doing direct writes
Kernel bugzilla: 216301
When doing direct writes we need to also invalidate the mapping in case we have a cached copy of the affected page(s) in memory or else subsequent reads of the data might return the old/stale content before we wrote an update to the server.
--- fs/cifs/file.c | 3 +++ 1 file changed, 3 insertions(+)
fs/cifs/file.c +3 -0
@@ -3575,6 +3575,9 @@ static ssize_t __cifs_writev(ssize_t cifs_direct_writev (struct kiocb *iocb,struct iov_iter *from) { +struct file *file = iocb->ki_filp; + +cifs_revalidate_mapping (file->f_inode);return __cifs_writev (iocb, from, true); }
Signature · 1 line
2.35.3
A message that is not in the archive (sent off-list or not yet received): CAH2r5mvh5_XbVxu0idZgt5A=zEr=4k7DF8Omf4VZOdrgCNkOfA@mail.gmail.com
PATCH 1/1 cifs: revalidate mapping when doing direct writes
---------- Forwarded message ---------
From: Steve French <[email protected]>
Date: Mon, Sep 12, 2022 at 12:30 AM
Subject: Re: [PATCH] cifs: revalidate mapping when doing direct writes
To: Ronnie Sahlberg <[email protected]>
Cc: linux-cifs <[email protected]>, Ronnie Sahlberg <[email protected]>
added cc:stable and tentatively merged into cifs-2.6.git for-next pending testing
Also let me know if you think this could address any long standing xfstest failures
Quoted 30 lines · Ronnie Sahlberg
Kernel bugzilla: 216301
When doing direct writes we need to also invalidate the mapping in case we have a cached copy of the affected page(s) in memory or else subsequent reads of the data might return the old/stale content before we wrote an update to the server.
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/file.c | 3 +++ 1 file changed, 3 insertions(+)fs/cifs/file.c +3
-1@@ -3575,6 +3575,9 @@ static ssize_t __cifs_writev(ssize_t cifs_direct_writev (struct kiocb *iocb,struct iov_iter *from) { +struct file *file = iocb->ki_filp; + +cifs_revalidate_mapping (file->f_inode);return __cifs_writev (iocb, from, true); } --2.35.3
Signature · 9 lines
Thanks, Steve -- Thanks, Steve
Re: [PATCH] cifs: revalidate mapping when doing direct writes
In reply to Ronnie SahlbergQuoted 11 lines · Ronnie Sahlberg
Kernel bugzilla: 216301
When doing direct writes we need to also invalidate the mapping in case we have a cached copy of the affected page(s) in memory or else subsequent reads of the data might return the old/stale content before we wrote an update to the server.
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/file.c | 3 +++ 1 file changed, 3 insertions(+)