From patchwork Mon May 14 07:03:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10397071 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CF26560216 for ; Mon, 14 May 2018 07:03:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE4AC287D3 for ; Mon, 14 May 2018 07:03:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2EED28C0F; Mon, 14 May 2018 07:03:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 503A8287D3 for ; Mon, 14 May 2018 07:03:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932171AbeENHDQ (ORCPT ); Mon, 14 May 2018 03:03:16 -0400 Received: from mx2.suse.de ([195.135.220.15]:46845 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932167AbeENHDO (ORCPT ); Mon, 14 May 2018 03:03:14 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 5ACF0AE6C for ; Mon, 14 May 2018 07:03:13 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/3] btrfs-progs: check/lowmem: Add checks for compressed extent without csum Date: Mon, 14 May 2018 15:03:08 +0800 Message-Id: <20180514070310.27197-2-wqu@suse.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180514070310.27197-1-wqu@suse.com> References: <20180514070310.27197-1-wqu@suse.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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) 0 or less than expected csum 2) nodatasum flag set in the inode item This is for lowmem mode. Reported-by: James Harvey Issue: #134 Signed-off-by: Qu Wenruo Reviewed-by: Su Yue --- check/mode-lowmem.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c index dac3201b7d99..8e6d5e8de12a 100644 --- a/check/mode-lowmem.c +++ b/check/mode-lowmem.c @@ -1543,6 +1543,24 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_key *fkey, csum_found); } } + /* + * Extra check for compressed extents. + * Btrfs doesn't allow NODATASUM and compressed extent co-exist, thus + * all compressed extent should have csum. + */ + if (compressed && csum_found < search_len) { + error( +"root %llu EXTENT_DATA[%llu %llu] compressed extent must have csum, but only %llu bytes has csum, 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) {