* [PATCH 2/3] filemap: Handle sibling entries in filemap_get_read_batch()
[not found] <20220619151143.1054746-1-willy@infradead.org>
@ 2022-06-19 15:11 ` Matthew Wilcox (Oracle)
2022-06-20 10:15 ` Brian Foster
0 siblings, 1 reply; 2+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-06-19 15:11 UTC (permalink / raw)
To: linux-mm, linux-fsdevel
Cc: Matthew Wilcox (Oracle), linux-kernel, Dave Chinner, Brian Foster,
stable
If a read races with an invalidation followed by another read, it is
possible for a folio to be replaced with a higher-order folio. If that
happens, we'll see a sibling entry for the new folio in the next iteration
of the loop. This manifests as a NULL pointer dereference while holding
the RCU read lock.
Handle this by simply returning. The next call will find the new folio
and handle it correctly. The other ways of handling this rare race are
more complex and it's just not worth it.
Reported-by: Dave Chinner <david@fromorbit.com>
Reported-by: Brian Foster <bfoster@redhat.com>
Debugged-by: Brian Foster <bfoster@redhat.com>
Tested-by: Brian Foster <bfoster@redhat.com>
Fixes: cbd59c48ae2b ("mm/filemap: use head pages in generic_file_buffered_read")
Cc: stable@vger.kernel.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
mm/filemap.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/mm/filemap.c b/mm/filemap.c
index 577068868449..ffdfbc8b0e3c 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2385,6 +2385,8 @@ static void filemap_get_read_batch(struct address_space *mapping,
continue;
if (xas.xa_index > max || xa_is_value(folio))
break;
+ if (xa_is_sibling(folio))
+ break;
if (!folio_try_get_rcu(folio))
goto retry;
--
2.35.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 2/3] filemap: Handle sibling entries in filemap_get_read_batch()
2022-06-19 15:11 ` [PATCH 2/3] filemap: Handle sibling entries in filemap_get_read_batch() Matthew Wilcox (Oracle)
@ 2022-06-20 10:15 ` Brian Foster
0 siblings, 0 replies; 2+ messages in thread
From: Brian Foster @ 2022-06-20 10:15 UTC (permalink / raw)
To: Matthew Wilcox (Oracle)
Cc: linux-mm, linux-fsdevel, linux-kernel, Dave Chinner, stable
On Sun, Jun 19, 2022 at 04:11:42PM +0100, Matthew Wilcox (Oracle) wrote:
> If a read races with an invalidation followed by another read, it is
> possible for a folio to be replaced with a higher-order folio. If that
> happens, we'll see a sibling entry for the new folio in the next iteration
> of the loop. This manifests as a NULL pointer dereference while holding
> the RCU read lock.
>
> Handle this by simply returning. The next call will find the new folio
> and handle it correctly. The other ways of handling this rare race are
> more complex and it's just not worth it.
>
> Reported-by: Dave Chinner <david@fromorbit.com>
> Reported-by: Brian Foster <bfoster@redhat.com>
> Debugged-by: Brian Foster <bfoster@redhat.com>
> Tested-by: Brian Foster <bfoster@redhat.com>
> Fixes: cbd59c48ae2b ("mm/filemap: use head pages in generic_file_buffered_read")
> Cc: stable@vger.kernel.org
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
This has survived my testing for several days now. I think I grok the
fix and analysis that lead to it, so FWIW:
Reviewed-by: Brian Foster <bfoster@redhat.com>
> mm/filemap.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 577068868449..ffdfbc8b0e3c 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -2385,6 +2385,8 @@ static void filemap_get_read_batch(struct address_space *mapping,
> continue;
> if (xas.xa_index > max || xa_is_value(folio))
> break;
> + if (xa_is_sibling(folio))
> + break;
> if (!folio_try_get_rcu(folio))
> goto retry;
>
> --
> 2.35.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-06-20 10:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20220619151143.1054746-1-willy@infradead.org>
2022-06-19 15:11 ` [PATCH 2/3] filemap: Handle sibling entries in filemap_get_read_batch() Matthew Wilcox (Oracle)
2022-06-20 10:15 ` Brian Foster
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).