Skip to content

Commit 367a9bf

Browse files
konisakpm00
authored andcommitted
nilfs2: protect access to buffers with no active references
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. 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]>
1 parent ca76bb2 commit 367a9bf

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
@@ -734,7 +734,6 @@ static size_t nilfs_lookup_dirty_data_buffers(struct inode *inode,
734734
if (!head)
735735
head = create_empty_buffers(folio,
736736
i_blocksize(inode), 0);
737-
folio_unlock(folio);
738737

739738
bh = head;
740739
do {
@@ -744,11 +743,14 @@ static size_t nilfs_lookup_dirty_data_buffers(struct inode *inode,
744743
list_add_tail(&bh->b_assoc_buffers, listp);
745744
ndirties++;
746745
if (unlikely(ndirties >= nlimit)) {
746+
folio_unlock(folio);
747747
folio_batch_release(&fbatch);
748748
cond_resched();
749749
return ndirties;
750750
}
751751
} while (bh = bh->b_this_page, bh != head);
752+
753+
folio_unlock(folio);
752754
}
753755
folio_batch_release(&fbatch);
754756
cond_resched();

0 commit comments

Comments
 (0)