Skip to content

Commit db3e24a

Browse files
konisakpm00
authored andcommitted
nilfs2: make block erasure safe in nilfs_finish_roll_forward()
The implementation of writing a zero-fill block in nilfs_finish_roll_forward() is not safe. The buffer is being cleared without acquiring a lock or setting the uptodate flag, so theoretically, between the time the buffer's data is cleared and the time it is written back to the block device using sync_dirty_buffer(), that zero data can be undone by concurrent block device reads. Since this buffer points to a location that has been read from disk once, the uptodate flag will most likely remain, but since it was obtained with __getblk(), that is not guaranteed. In other words, this is exceptional, and this function itself is not normally called (only once when mounting after a specific pattern of unclean shutdown), so it is highly unlikely that this will actually cause a problem. Anyway, eliminate this potential race issue by protecting the clearing of buffer data with a buffer lock and setting the buffer's uptodate flag within the protected section. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ryusuke Konishi <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 28d2188 commit db3e24a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

fs/nilfs2/recovery.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,12 @@ static void nilfs_finish_roll_forward(struct the_nilfs *nilfs,
702702
if (WARN_ON(!bh))
703703
return; /* should never happen */
704704

705+
lock_buffer(bh);
705706
memset(bh->b_data, 0, bh->b_size);
707+
set_buffer_uptodate(bh);
706708
set_buffer_dirty(bh);
709+
unlock_buffer(bh);
710+
707711
err = sync_dirty_buffer(bh);
708712
if (unlikely(err))
709713
nilfs_warn(nilfs->ns_sb,

0 commit comments

Comments
 (0)