• Qu Wenruo's avatar
    btrfs: verify the tranisd of the to-be-written dirty extent buffer · 3777369f
    Qu Wenruo authored
    [BUG]
    There is a bug report that a bitflip in the transid part of an extent
    buffer makes btrfs to reject certain tree blocks:
    
      BTRFS error (device dm-0): parent transid verify failed on 1382301696 wanted 262166 found 22
    
    [CAUSE]
    Note the failed transid check, hex(262166) = 0x40016, while
    hex(22) = 0x16.
    
    It's an obvious bitflip.
    
    Furthermore, the reporter also confirmed the bitflip is from the
    hardware, so it's a real hardware caused bitflip, and such problem can
    not be detected by the existing tree-checker framework.
    
    As tree-checker can only verify the content inside one tree block, while
    generation of a tree block can only be verified against its parent.
    
    So such problem remain undetected.
    
    [FIX]
    Although tree-checker can not verify it at write-time, we still have a
    quick (but not the most accurate) way to catch such obvious corruption.
    
    Function csum_one_extent_buffer() is called before we submit metadata
    write.
    
    Thus it means, all the extent buffer passed in should be dirty tree
    blocks, and should be newer than last committed transaction.
    
    Using that we can catch the above bitflip.
    
    Although it's not a perfect solution, as if the corrupted generation is
    higher than the correct value, we have no way to catch it at all.
    Reported-by: default avatarChristoph Anton Mitterer <calestyo@scientia.org>
    Link: https://lore.kernel.org/linux-btrfs/2dfcbc130c55cc6fd067b93752e90bd2b079baca.camel@scientia.org/
    CC: stable@vger.kernel.org # 5.15+
    Signed-off-by: default avatarQu Wenruo <wqu@sus,ree.com>
    Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    3777369f
disk-io.c 147 KB