Omar Sandoval 0c8eccc28e btrfs: fix RAID direct I/O reads with alternate csums
commit e7a04894c766daa4248cb736efee93550f2d5872 upstream.

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: 1e25a2e3ca0d ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-03-12 13:00:20 +01:00
..
2019-09-27 15:10:34 -07:00
2019-09-19 09:42:37 -07:00
2019-07-12 17:37:53 -07:00
2020-02-11 04:35:35 -08:00
2019-09-19 09:42:37 -07:00
2019-09-19 09:42:37 -07:00
2019-07-03 17:52:09 -04:00
2019-10-19 06:32:32 -04:00
2019-09-19 09:42:37 -07:00
2020-03-05 16:43:36 +01:00
2019-11-29 10:10:10 +01:00
2019-08-07 21:51:47 -04:00
2019-12-17 19:55:30 +01:00
2019-09-18 16:59:14 -07:00
2019-10-14 15:04:01 -07:00
2019-09-18 16:59:14 -07:00
2019-08-01 20:51:23 +02:00