Skip to content

Commit f83913f

Browse files
konisakpm00
authored andcommitted
nilfs2: fix general protection fault in nilfs_lookup_dirty_data_buffers()
A syzbot stress test reported that create_empty_buffers() called from nilfs_lookup_dirty_data_buffers() can cause a general protection fault. Analysis using its reproducer revealed that the back reference "mapping" from a page/folio has been changed to NULL after dirty page/folio gang lookup in nilfs_lookup_dirty_data_buffers(). Fix this issue by excluding pages/folios from being collected if, after acquiring a lock on each page/folio, its back reference "mapping" differs from the pointer to the address space struct that held the page/folio. Link: https://lkml.kernel.org/r/20230805132038.6435-1-konishi.ryusuke@gmail.com Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com> Reported-by: syzbot+0ad741797f4565e7e2d2@syzkaller.appspotmail.com Closes: https://lkml.kernel.org/r/0000000000002930a705fc32b231@google.com Tested-by: Ryusuke Konishi <konishi.ryusuke@gmail.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 5805192 commit f83913f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

fs/nilfs2/segment.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,11 @@ static size_t nilfs_lookup_dirty_data_buffers(struct inode *inode,
725725
struct folio *folio = fbatch.folios[i];
726726

727727
folio_lock(folio);
728+
if (unlikely(folio->mapping != mapping)) {
729+
/* Exclude folios removed from the address space */
730+
folio_unlock(folio);
731+
continue;
732+
}
728733
head = folio_buffers(folio);
729734
if (!head) {
730735
create_empty_buffers(&folio->page, i_blocksize(inode), 0);

0 commit comments

Comments
 (0)