From cc7a35f6425f55aa48654da1ee69b6014b8ebb0c Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Mon, 14 May 2018 13:49:29 +0800 Subject: [PATCH] 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 Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- check/mode-lowmem.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c index 6d7ae2bc..157a0b70 100644 --- a/check/mode-lowmem.c +++ b/check/mode-lowmem.c @@ -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)