• Ryusuke Konishi's avatar
    nilfs2: make block erasure safe in nilfs_finish_roll_forward() · db3e24a0
    Ryusuke Konishi authored
    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/20240511002942.9608-1-konishi.ryusuke@gmail.comSigned-off-by: default avatarRyusuke Konishi <konishi.ryusuke@gmail.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    db3e24a0
recovery.c 23.7 KB