]> git.baikalelectronics.ru Git - kernel.git/commit
btrfs: fix RAID direct I/O reads with alternate csums
authorOmar Sandoval <osandov@fb.com>
Mon, 2 Mar 2020 22:02:49 +0000 (14:02 -0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 3 Mar 2020 14:26:08 +0000 (15:26 +0100)
commitaaa97a02beb37199f815222273b04a93ea4567b9
tree500ed1c5e3a81c03d1c70c7c3f3e44e476a154e5
parent7aaa5366ea262059200fb4d171ae305483aae31a
btrfs: fix RAID direct I/O reads with alternate csums

btrfs_lookup_and_bind_dio_csum() does pointer arithmetic which assumes
32-bit checksums. If using a larger checksum, this leads to spurious
failures when a direct I/O read crosses a stripe. This is easy
to reproduce:

  # mkfs.btrfs -f --checksum blake2 -d raid0 /dev/vdc /dev/vdd
  ...
  # mount /dev/vdc /mnt
  # cd /mnt
  # dd if=/dev/urandom of=foo bs=1M count=1 status=none
  # dd if=foo of=/dev/null bs=1M iflag=direct status=none
  dd: error reading 'foo': Input/output error
  # dmesg | tail -1
  [  135.821568] BTRFS warning (device vdc): csum failed root 5 ino 257 off 421888 ...

Fix it by using the actual checksum size.

Fixes: 11dc962b586e ("btrfs: don't assume ordered sums to be 4 bytes")
CC: stable@vger.kernel.org # 5.4+
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Omar Sandoval <osandov@fb.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c