All of lore.kernel.org
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] filemap: Handle sibling entries in filemap_get_read_batch()" failed to apply to 5.15-stable tree
@ 2022-06-25 14:44 gregkh
  2022-07-04 18:56 ` Matthew Wilcox
  0 siblings, 1 reply; 2+ messages in thread
From: gregkh @ 2022-06-25 14:44 UTC (permalink / raw)
  To: willy, bfoster, david; +Cc: stable


The patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From cb995f4eeba9d268fd4b56c2423ad6c1d1ea1b82 Mon Sep 17 00:00:00 2001
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Date: Fri, 17 Jun 2022 20:00:17 -0400
Subject: [PATCH] filemap: Handle sibling entries in filemap_get_read_batch()

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>
Reviewed-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>

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;
 


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

* Re: FAILED: patch "[PATCH] filemap: Handle sibling entries in filemap_get_read_batch()" failed to apply to 5.15-stable tree
  2022-06-25 14:44 FAILED: patch "[PATCH] filemap: Handle sibling entries in filemap_get_read_batch()" failed to apply to 5.15-stable tree gregkh
@ 2022-07-04 18:56 ` Matthew Wilcox
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Wilcox @ 2022-07-04 18:56 UTC (permalink / raw)
  To: gregkh; +Cc: bfoster, david, stable

On Sat, Jun 25, 2022 at 04:44:59PM +0200, gregkh@linuxfoundation.org wrote:
> 
> The patch below does not apply to the 5.15-stable tree.
> If someone wants it applied there, or to any other stable or longterm
> tree, then please email the backport, including the original git commit
> id to <stable@vger.kernel.org>.

Compile-tested only, but it's fairly straightforward (if you understand
how the code mutated over time)

diff --git a/mm/filemap.c b/mm/filemap.c
index 00e391e75880..9cef95427575 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2341,6 +2341,8 @@ static void filemap_get_read_batch(struct address_space *mapping,
 			continue;
 		if (xas.xa_index > max || xa_is_value(head))
 			break;
+		if (xa_is_sibling(head))
+			break;
 		if (!page_cache_get_speculative(head))
 			goto retry;
 

> thanks,
> 
> greg k-h
> 
> ------------------ original commit in Linus's tree ------------------
> 
> >From cb995f4eeba9d268fd4b56c2423ad6c1d1ea1b82 Mon Sep 17 00:00:00 2001
> From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
> Date: Fri, 17 Jun 2022 20:00:17 -0400
> Subject: [PATCH] filemap: Handle sibling entries in filemap_get_read_batch()
> 
> 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>
> Reviewed-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>
> 
> 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;
>  
> 

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

end of thread, other threads:[~2022-07-04 18:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-25 14:44 FAILED: patch "[PATCH] filemap: Handle sibling entries in filemap_get_read_batch()" failed to apply to 5.15-stable tree gregkh
2022-07-04 18:56 ` Matthew Wilcox

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.