Skip to content

Commit 5bc09b3

Browse files
konisakpm00
authored andcommitted
nilfs2: fix potential bug in end_buffer_async_write
According to a syzbot report, end_buffer_async_write(), which handles the completion of block device writes, may detect abnormal condition of the buffer async_write flag and cause a BUG_ON failure when using nilfs2. Nilfs2 itself does not use end_buffer_async_write(). But, the async_write flag is now used as a marker by commit 7f42ec3 ("nilfs2: fix issue with race condition of competition between segments for dirty blocks") as a means of resolving double list insertion of dirty blocks in nilfs_lookup_dirty_data_buffers() and nilfs_lookup_node_buffers() and the resulting crash. This modification is safe as long as it is used for file data and b-tree node blocks where the page caches are independent. However, it was irrelevant and redundant to also introduce async_write for segment summary and super root blocks that share buffers with the backing device. This led to the possibility that the BUG_ON check in end_buffer_async_write would fail as described above, if independent writebacks of the backing device occurred in parallel. The use of async_write for segment summary buffers has already been removed in a previous change. Fix this issue by removing the manipulation of the async_write flag for the remaining super root block buffer. Link: https://lkml.kernel.org/r/20240203161645.4992-1-konishi.ryusuke@gmail.com Fixes: 7f42ec3 ("nilfs2: fix issue with race condition of competition between segments for dirty blocks") Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com> Reported-by: syzbot+5c04210f7c7f897c1e7f@syzkaller.appspotmail.com Closes: https://lkml.kernel.org/r/00000000000019a97c05fd42f8c8@google.com Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent b9e4bc1 commit 5bc09b3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

fs/nilfs2/segment.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,6 @@ static void nilfs_segctor_prepare_write(struct nilfs_sc_info *sci)
17031703

17041704
list_for_each_entry(bh, &segbuf->sb_payload_buffers,
17051705
b_assoc_buffers) {
1706-
set_buffer_async_write(bh);
17071706
if (bh == segbuf->sb_super_root) {
17081707
if (bh->b_folio != bd_folio) {
17091708
folio_lock(bd_folio);
@@ -1714,6 +1713,7 @@ static void nilfs_segctor_prepare_write(struct nilfs_sc_info *sci)
17141713
}
17151714
break;
17161715
}
1716+
set_buffer_async_write(bh);
17171717
if (bh->b_folio != fs_folio) {
17181718
nilfs_begin_folio_io(fs_folio);
17191719
fs_folio = bh->b_folio;
@@ -1800,7 +1800,6 @@ static void nilfs_abort_logs(struct list_head *logs, int err)
18001800

18011801
list_for_each_entry(bh, &segbuf->sb_payload_buffers,
18021802
b_assoc_buffers) {
1803-
clear_buffer_async_write(bh);
18041803
if (bh == segbuf->sb_super_root) {
18051804
clear_buffer_uptodate(bh);
18061805
if (bh->b_folio != bd_folio) {
@@ -1809,6 +1808,7 @@ static void nilfs_abort_logs(struct list_head *logs, int err)
18091808
}
18101809
break;
18111810
}
1811+
clear_buffer_async_write(bh);
18121812
if (bh->b_folio != fs_folio) {
18131813
nilfs_end_folio_io(fs_folio, err);
18141814
fs_folio = bh->b_folio;
@@ -1896,15 +1896,17 @@ static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci)
18961896
BIT(BH_Delay) | BIT(BH_NILFS_Volatile) |
18971897
BIT(BH_NILFS_Redirected));
18981898

1899-
set_mask_bits(&bh->b_state, clear_bits, set_bits);
19001899
if (bh == segbuf->sb_super_root) {
1900+
set_buffer_uptodate(bh);
1901+
clear_buffer_dirty(bh);
19011902
if (bh->b_folio != bd_folio) {
19021903
folio_end_writeback(bd_folio);
19031904
bd_folio = bh->b_folio;
19041905
}
19051906
update_sr = true;
19061907
break;
19071908
}
1909+
set_mask_bits(&bh->b_state, clear_bits, set_bits);
19081910
if (bh->b_folio != fs_folio) {
19091911
nilfs_end_folio_io(fs_folio, 0);
19101912
fs_folio = bh->b_folio;

0 commit comments

Comments
 (0)