Skip to content

Commit cb995f4

Browse files
author
Matthew Wilcox (Oracle)
committed
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 <[email protected]> Reported-by: Brian Foster <[email protected]> Debugged-by: Brian Foster <[email protected]> Tested-by: Brian Foster <[email protected]> Reviewed-by: Brian Foster <[email protected]> Fixes: cbd59c4 ("mm/filemap: use head pages in generic_file_buffered_read") Cc: [email protected] Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
1 parent 5ccc944 commit cb995f4

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

mm/filemap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,6 +2385,8 @@ static void filemap_get_read_batch(struct address_space *mapping,
23852385
continue;
23862386
if (xas.xa_index > max || xa_is_value(folio))
23872387
break;
2388+
if (xa_is_sibling(folio))
2389+
break;
23882390
if (!folio_try_get_rcu(folio))
23892391
goto retry;
23902392

0 commit comments

Comments
 (0)