btrfs-progs: check/lowmem: Add checks for compressed extent without csum

There is one report of compressed extent happens in btrfs, but has no
csum and then leads to possible decompress error screwing up kernel
memory.

Although it's a kernel bug, and won't cause problem until compressed
data get corrupted, let's catch such problem in advance.

This patch will catch any unexpected compressed extent with:

1) missing csum

2) nodatasum flag set in the inode item

This is for lowmem mode.

Reported-by: James Harvey <jamespharvey20@gmail.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
master
Qu Wenruo 2018-05-14 13:49:29 +08:00 committed by David Sterba
parent 50b9312f3a
commit cc7a35f642
1 changed files with 19 additions and 0 deletions

View File

@ -2082,6 +2082,25 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_path *path,
}
}
/*
* Extra check for compressed extents:
* Btrfs doesn't allow NODATASUM and compressed extent co-exist, thus
* all compressed extents should have a checksum.
*/
if (compressed && csum_found < search_len) {
error(
"root %llu EXTENT_DATA[%llu %llu] compressed extent must have csum, but only %llu bytes have, expect %llu",
root->objectid, fkey.objectid, fkey.offset, csum_found,
search_len);
err |= CSUM_ITEM_MISSING;
}
if (compressed && nodatasum) {
error(
"root %llu EXTENT_DATA[%llu %llu] is compressed, but inode flag doesn't allow it",
root->objectid, fkey.objectid, fkey.offset);
err |= FILE_EXTENT_ERROR;
}
/* Check EXTENT_DATA hole */
if (!no_holes && *end != fkey.offset) {
if (repair)