linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Cifs: fix kbz 216301: return corrupt/stale file content
@ 2022-09-12  3:04 Ronnie Sahlberg
  2022-09-12  3:04 ` [PATCH] cifs: revalidate mapping when doing direct writes Ronnie Sahlberg
  0 siblings, 1 reply; 4+ messages in thread
From: Ronnie Sahlberg @ 2022-09-12  3:04 UTC (permalink / raw)
  To: linux-cifs; +Cc: Steve French

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.



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

* [PATCH] cifs: revalidate mapping when doing direct writes
  2022-09-12  3:04 Cifs: fix kbz 216301: return corrupt/stale file content Ronnie Sahlberg
@ 2022-09-12  3:04 ` Ronnie Sahlberg
       [not found]   ` <CAH2r5mvh5_XbVxu0idZgt5A=zEr=4k7DF8Omf4VZOdrgCNkOfA@mail.gmail.com>
  2022-09-12 15:57   ` Paulo Alcantara
  0 siblings, 2 replies; 4+ messages in thread
From: Ronnie Sahlberg @ 2022-09-12  3:04 UTC (permalink / raw)
  To: linux-cifs; +Cc: Steve French, 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 <lsahlber@redhat.com>
---
 fs/cifs/file.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index fa738adc031f..6f38b134a346 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -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


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

* Fwd: [PATCH] cifs: revalidate mapping when doing direct writes
       [not found]   ` <CAH2r5mvh5_XbVxu0idZgt5A=zEr=4k7DF8Omf4VZOdrgCNkOfA@mail.gmail.com>
@ 2022-09-12  5:32     ` Steve French
  0 siblings, 0 replies; 4+ messages in thread
From: Steve French @ 2022-09-12  5:32 UTC (permalink / raw)
  To: CIFS

---------- Forwarded message ---------
From: Steve French <smfrench@gmail.com>
Date: Mon, Sep 12, 2022 at 12:30 AM
Subject: Re: [PATCH] cifs: revalidate mapping when doing direct writes
To: Ronnie Sahlberg <lsahlber@redhat.com>
Cc: linux-cifs <linux-cifs@vger.kernel.org>, Ronnie Sahlberg
<lsahlber@redhat.com>


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

On Sun, Sep 11, 2022 at 10:05 PM Ronnie Sahlberg <lsahlber@redhat.com> wrote:
>
> 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 <lsahlber@redhat.com>
> ---
>  fs/cifs/file.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index fa738adc031f..6f38b134a346 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -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
>


-- 
Thanks,

Steve


-- 
Thanks,

Steve

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

* Re: [PATCH] cifs: revalidate mapping when doing direct writes
  2022-09-12  3:04 ` [PATCH] cifs: revalidate mapping when doing direct writes Ronnie Sahlberg
       [not found]   ` <CAH2r5mvh5_XbVxu0idZgt5A=zEr=4k7DF8Omf4VZOdrgCNkOfA@mail.gmail.com>
@ 2022-09-12 15:57   ` Paulo Alcantara
  1 sibling, 0 replies; 4+ messages in thread
From: Paulo Alcantara @ 2022-09-12 15:57 UTC (permalink / raw)
  To: Ronnie Sahlberg, linux-cifs; +Cc: Steve French, Ronnie Sahlberg

Ronnie Sahlberg <lsahlber@redhat.com> 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.
>
> Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> ---
>  fs/cifs/file.c | 3 +++
>  1 file changed, 3 insertions(+)

Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz>

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

end of thread, other threads:[~2022-09-12 15:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-12  3:04 Cifs: fix kbz 216301: return corrupt/stale file content Ronnie Sahlberg
2022-09-12  3:04 ` [PATCH] cifs: revalidate mapping when doing direct writes Ronnie Sahlberg
     [not found]   ` <CAH2r5mvh5_XbVxu0idZgt5A=zEr=4k7DF8Omf4VZOdrgCNkOfA@mail.gmail.com>
2022-09-12  5:32     ` Fwd: " Steve French
2022-09-12 15:57   ` Paulo Alcantara

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).