Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10786363imu; Thu, 6 Dec 2018 06:48:54 -0800 (PST) X-Google-Smtp-Source: AFSGD/X3zOeU8cc7zLhZ7oD9XuNvAlovF2M878glpFBxvhjw6vLT3E4vFjXrZDmZyNNU4b2XQcdo X-Received: by 2002:aa7:868f:: with SMTP id d15mr28324925pfo.225.1544107734212; Thu, 06 Dec 2018 06:48:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544107734; cv=none; d=google.com; s=arc-20160816; b=emfzfQkR3GxkQk8BwNPS438XNSbTgksx54j18of2t7eQgBmhK2kiNgj3vFF8/ow0OL lbaatxOEbZiUTP/jxSzN2Vhqb6h0xWEFaX47rU59fsw8TLcMSJesG1LWNKkQQw5wRGm2 mm/vTTY8JhQo4tbYcJ+0AREJawSQsJGn42IQNbrhbpMruXDPWaR4b4SF4DsWLbTfQq/A /yVDOOWZliAcY4VCC8ubejHiH2iddInRMGRGtFgn89MblRGD0sp58Aj7vAfEB8/pqfux /BOPg3JnYhNAq3YAik/q21AKlZBtfe/zs1ihh8Z8YpmcDGm5ryyWrrgABgKIcrA/KQvr b3Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6Ayjyc07FVCA0JV/tCrNRwZa93yTrxkzBUjYB2Kava0=; b=obqbLt5tZ+yZ+77CvsHHv1F7VlE9eODDSMjWXWFhaIXl6xJ7uVrMacrGIlZDbtoY/V a4qYpXbRFIdFpkilEAv7kFPxrqH8ojUyjKyVZORjZlLuBd61mVNAnVG7R80EX29bVosL mtq7ZHAM98NOULU/n+bmlh3sCVtgfrJLcAIGokqCNDXftxnZR5RCGIQBq2KuMleu8N3d FKkfFvO/gxjHpX91QN8sxqQvmvl65gnkYVI7scfkpX65OOF3H23Q4xBjysxAQ8/bxRHZ vPpKg5mQO2rl0wA1neQvweGOiIVFciC7u4YpC6Huy/SRRVyqMCPSyIShrlb3uqymcTa3 HJRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=r0kvvSVR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s4si408263pfb.190.2018.12.06.06.48.38; Thu, 06 Dec 2018 06:48:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=r0kvvSVR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731335AbeLFOqy (ORCPT + 99 others); Thu, 6 Dec 2018 09:46:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:51620 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730672AbeLFOqv (ORCPT ); Thu, 6 Dec 2018 09:46:51 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ECC0B21508; Thu, 6 Dec 2018 14:46:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544107610; bh=Zg64WzEHlteQVFQRVOE43LMu6mlC0q+0upBeAMoNQ/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r0kvvSVRWAv/eiQOFJ4NLW6du+QfLCFJ+fZPV/C3z4qYwZLRjvpEluDBIolo5AKfJ FK3N4fCteaA8cR/zd6udP3Xes1kDHJf8Ho6zxNQBU2ENDvdVhQtV+pisKtyTfJ4quX iByyu02bwdpRNvNi+fbaeVDAYxevSRzI0JU6G9o8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , Nikolay Borisov , David Sterba , Ben Hutchings Subject: [PATCH 4.9 070/101] btrfs: Add checker for EXTENT_CSUM Date: Thu, 6 Dec 2018 15:39:09 +0100 Message-Id: <20181206143015.990058544@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181206143011.174892052@linuxfoundation.org> References: <20181206143011.174892052@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Qu Wenruo commit 4b865cab96fe2a30ed512cf667b354bd291b3b0a upstream. EXTENT_CSUM checker is a relatively easy one, only needs to check: 1) Objectid Fixed to BTRFS_EXTENT_CSUM_OBJECTID 2) Key offset alignment Must be aligned to sectorsize 3) Item size alignedment Must be aligned to csum size Signed-off-by: Qu Wenruo Reviewed-by: Nikolay Borisov Reviewed-by: David Sterba Signed-off-by: David Sterba [bwh: Backported to 4.9: Use root->sectorsize instead of root->fs_info->sectorsize] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/disk-io.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -621,6 +621,27 @@ static int check_extent_data_item(struct return 0; } +static int check_csum_item(struct btrfs_root *root, struct extent_buffer *leaf, + struct btrfs_key *key, int slot) +{ + u32 sectorsize = root->sectorsize; + u32 csumsize = btrfs_super_csum_size(root->fs_info->super_copy); + + if (key->objectid != BTRFS_EXTENT_CSUM_OBJECTID) { + CORRUPT("invalid objectid for csum item", leaf, root, slot); + return -EUCLEAN; + } + if (!IS_ALIGNED(key->offset, sectorsize)) { + CORRUPT("unaligned key offset for csum item", leaf, root, slot); + return -EUCLEAN; + } + if (!IS_ALIGNED(btrfs_item_size_nr(leaf, slot), csumsize)) { + CORRUPT("unaligned csum item size", leaf, root, slot); + return -EUCLEAN; + } + return 0; +} + /* * Common point to switch the item-specific validation. */ @@ -634,6 +655,9 @@ static int check_leaf_item(struct btrfs_ case BTRFS_EXTENT_DATA_KEY: ret = check_extent_data_item(root, leaf, key, slot); break; + case BTRFS_EXTENT_CSUM_KEY: + ret = check_csum_item(root, leaf, key, slot); + break; } return ret; }