]> git.baikalelectronics.ru Git - kernel.git/commit
btrfs: fix inline compressed read err corruption
authorZach Brown <zab@redhat.com>
Fri, 9 May 2014 21:15:10 +0000 (17:15 -0400)
committerChris Mason <clm@fb.com>
Tue, 10 Jun 2014 00:20:23 +0000 (17:20 -0700)
commit36043d86ae735a035ce927b3dd740f96039e9364
tree542143963601383f96aa0d9aa374f54d01205428
parent786f7c4602be1a2259464e55ceb80ce714f9e75c
btrfs: fix inline compressed read err corruption

uncompress_inline() is dropping the error from btrfs_decompress() after
testing it and zeroing the page that was supposed to hold decompressed
data.  This can silently turn compressed inline data in to zeros if
decompression fails due to corrupt compressed data or memory allocation
failure.

I verified this by manually forcing the error from btrfs_decompress()
for a silly named copy of od:

if (!strcmp(current->comm, "failod"))
ret = -ENOMEM;

  # od -x /mnt/btrfs/dir/80 | head -1
  0000000 3031 3038 310a 2d30 6f70 6e69 0a74 3031
  # echo 3 > /proc/sys/vm/drop_caches
  # cp $(which od) /tmp/failod
  # /tmp/failod -x /mnt/btrfs/dir/80 | head -1
  0000000 0000 0000 0000 0000 0000 0000 0000 0000

The fix is to pass the error to its caller.  Which still has a BUG_ON().
So we fix that too.

There seems to be no reason for the zeroing of the page on the error
from btrfs_decompress() but not from the allocation error a few lines
above.  So the page zeroing is removed.

Signed-off-by: Zach Brown <zab@redhat.com>
Reviewed-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
fs/btrfs/inode.c