From: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
To: "Darrick J. Wong" <djwong@kernel.org>, djwong@kernel.org
Cc: willy@infradead.org, linux-fsdevel@vger.kernel.org,
linux-xfs@vger.kernel.org, willy@infradead.org
Subject: Re: [PATCH 1/2] iomap: don't skip reading in !uptodate folios when unsharing a range
Date: Tue, 19 Sep 2023 10:44:58 +0530 [thread overview]
Message-ID: <87o7hy7nhp.fsf@doe.com> (raw)
In-Reply-To: <169507872536.772278.18183365318216726644.stgit@frogsfrogsfrogs>
"Darrick J. Wong" <djwong@kernel.org> writes:
> From: Darrick J. Wong <djwong@kernel.org>
>
> Prior to commit a01b8f225248e, we would always read in the contents of a
> !uptodate folio prior to writing userspace data into the folio,
> allocated a folio state object, etc. Ritesh introduced an optimization
> that skips all of that if the write would cover the entire folio.
>
> Unfortunately, the optimization misses the unshare case, where we always
> have to read in the folio contents since there isn't a data buffer
> supplied by userspace. This can result in stale kernel memory exposure
> if userspace issues a FALLOC_FL_UNSHARE_RANGE call on part of a shared
> file that isn't already cached.
>
> This was caught by observing fstests regressions in the "unshare around"
> mechanism that is used for unaligned writes to a reflinked realtime
> volume when the realtime extent size is larger than 1FSB,
I was wondering what is testcase that you are referring here to?
Can you please tell the testcase no. and the mkfs / mount config options
which I can use to observe the regression please?
> though I think it applies to any shared file.
>
> Cc: ritesh.list@gmail.com, willy@infradead.org
> Fixes: a01b8f225248e ("iomap: Allocate ifs in ->write_begin() early")
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
> fs/iomap/buffered-io.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
>
> diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
> index ae8673ce08b1..0350830fc989 100644
> --- a/fs/iomap/buffered-io.c
> +++ b/fs/iomap/buffered-io.c
> @@ -640,11 +640,13 @@ static int __iomap_write_begin(const struct iomap_iter *iter, loff_t pos,
> size_t poff, plen;
>
> /*
> - * If the write completely overlaps the current folio, then
> + * If the write or zeroing completely overlaps the current folio, then
> * entire folio will be dirtied so there is no need for
> * per-block state tracking structures to be attached to this folio.
> + * For the unshare case, we must read in the ondisk contents because we
> + * are not changing pagecache contents.
> */
> - if (pos <= folio_pos(folio) &&
> + if (!(iter->flags & IOMAP_UNSHARE) && pos <= folio_pos(folio) &&
> pos + len >= folio_pos(folio) + folio_size(folio))
> return 0;
>
next prev parent reply other threads:[~2023-09-19 5:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-18 23:11 [PATCHSET 0/2] iomap: fix unshare data corruption bug Darrick J. Wong
2023-09-18 23:12 ` [PATCH 1/2] iomap: don't skip reading in !uptodate folios when unsharing a range Darrick J. Wong
2023-09-19 4:42 ` Ritesh Harjani
2023-09-19 9:24 ` Ritesh Harjani
2023-09-19 5:14 ` Ritesh Harjani [this message]
2023-09-19 5:24 ` Darrick J. Wong
2023-09-19 5:32 ` Darrick J. Wong
2023-09-18 23:12 ` [PATCH 2/2] iomap: convert iomap_unshare_iter to use large folios Darrick J. Wong
2023-09-19 8:03 ` Ritesh Harjani
2023-09-18 23:19 ` [PATCH 3/2] fstests: test FALLOC_FL_UNSHARE when pagecache is not loaded Darrick J. Wong
2023-09-19 5:51 ` Ritesh Harjani
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87o7hy7nhp.fsf@doe.com \
--to=ritesh.list@gmail.com \
--cc=djwong@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.