Skip to content

Commit 782e53d

Browse files
konisakpm00
authored andcommitted
nilfs2: prevent general protection fault in nilfs_clear_dirty_page()
In a syzbot stress test that deliberately causes file system errors on nilfs2 with a corrupted disk image, it has been reported that nilfs_clear_dirty_page() called from nilfs_clear_dirty_pages() can cause a general protection fault. In nilfs_clear_dirty_pages(), when looking up dirty pages from the page cache and calling nilfs_clear_dirty_page() for each dirty page/folio retrieved, the back reference from the argument page to "mapping" may have been changed to NULL (and possibly others). It is necessary to check this after locking the page/folio. So, fix this issue by not calling nilfs_clear_dirty_page() on a page/folio after locking it in nilfs_clear_dirty_pages() if the back reference "mapping" from the page/folio is different from the "mapping" that held the page/folio just before. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ryusuke Konishi <[email protected]> Reported-by: [email protected] Closes: https://lkml.kernel.org/r/[email protected] Tested-by: Ryusuke Konishi <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 71c3ad6 commit 782e53d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

fs/nilfs2/page.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,15 @@ void nilfs_clear_dirty_pages(struct address_space *mapping, bool silent)
370370
struct folio *folio = fbatch.folios[i];
371371

372372
folio_lock(folio);
373-
nilfs_clear_dirty_page(&folio->page, silent);
373+
374+
/*
375+
* This folio may have been removed from the address
376+
* space by truncation or invalidation when the lock
377+
* was acquired. Skip processing in that case.
378+
*/
379+
if (likely(folio->mapping == mapping))
380+
nilfs_clear_dirty_page(&folio->page, silent);
381+
374382
folio_unlock(folio);
375383
}
376384
folio_batch_release(&fbatch);

0 commit comments

Comments
 (0)