]> git.baikalelectronics.ru Git - kernel.git/commit
filemap: Handle sibling entries in filemap_get_read_batch()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Sat, 18 Jun 2022 00:00:17 +0000 (20:00 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Mon, 20 Jun 2022 20:37:45 +0000 (16:37 -0400)
commitc96ac429555a12df813079176c30d1c8323b5db9
treebb343bdc1f83d5f0675ee98170d868a437543cca
parent993243ed4ede2344b96d5c5e9f6f4100db78f410
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: 8e6a4775bcbe ("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