Skip to content

Commit 58c27fa

Browse files
konisgregkh
authored andcommitted
nilfs2: protect access to buffers with no active references
commit 367a9bffabe08c04f6d725032cce3d891b2b9e1a upstream. nilfs_lookup_dirty_data_buffers(), which iterates through the buffers attached to dirty data folios/pages, accesses the attached buffers without locking the folios/pages. For data cache, nilfs_clear_folio_dirty() may be called asynchronously when the file system degenerates to read only, so nilfs_lookup_dirty_data_buffers() still has the potential to cause use after free issues when buffers lose the protection of their dirty state midway due to this asynchronous clearing and are unintentionally freed by try_to_free_buffers(). Eliminate this race issue by adjusting the lock section in this function. [[email protected]: adjusted for page/folio conversion] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ryusuke Konishi <[email protected]> Fixes: 8c26c4e ("nilfs2: fix issue with flush kernel thread after remount in RO mode because of driver's internal error or metadata corruption") Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1929673 commit 58c27fa

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

fs/nilfs2/segment.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,6 @@ static size_t nilfs_lookup_dirty_data_buffers(struct inode *inode,
732732
}
733733
if (!page_has_buffers(page))
734734
create_empty_buffers(page, i_blocksize(inode), 0);
735-
unlock_page(page);
736735

737736
bh = head = page_buffers(page);
738737
do {
@@ -742,11 +741,14 @@ static size_t nilfs_lookup_dirty_data_buffers(struct inode *inode,
742741
list_add_tail(&bh->b_assoc_buffers, listp);
743742
ndirties++;
744743
if (unlikely(ndirties >= nlimit)) {
744+
unlock_page(page);
745745
pagevec_release(&pvec);
746746
cond_resched();
747747
return ndirties;
748748
}
749749
} while (bh = bh->b_this_page, bh != head);
750+
751+
unlock_page(page);
750752
}
751753
pagevec_release(&pvec);
752754
cond_resched();

0 commit comments

Comments
 (0)